Skip to content

Commit

Permalink
Refactor: Update large_icon field type in WinGetAppResourceModel
Browse files Browse the repository at this point in the history
  • Loading branch information
ShocOne committed Oct 2, 2024
1 parent a3fab50 commit 98af486
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type WinGetAppResourceModel struct {
DisplayName types.String `tfsdk:"display_name"`
Description types.String `tfsdk:"description"`
Publisher types.String `tfsdk:"publisher"`
LargeIcon *MimeContentModel `tfsdk:"large_icon"`
LargeIcon types.Object `tfsdk:"large_icon"`
CreatedDateTime types.String `tfsdk:"created_date_time"`
LastModifiedDateTime types.String `tfsdk:"last_modified_date_time"`
IsFeatured types.Bool `tfsdk:"is_featured"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ func (r *WinGetAppResource) Schema(ctx context.Context, req resource.SchemaReque
" run_as_account = \"user\"\n" +
" }\n" +
"}\n" +
"```\n\n" +
"Can be set using the `PACKAGE_IDENTIFIER` environment variable.",
"```\n\n",
Validators: []validator.String{
stringvalidator.RegexMatches(regexp.MustCompile(`^[a-zA-Z0-9]{12}$`), "package_identifier must be a 12-character alphanumeric string (upper or lowercase)."),
stringvalidator.RegexMatches(
regexp.MustCompile(`^[A-Z0-9]{12}$`),
"package_identifier must be a 12-character string containing only uppercase letters and numbers.",
),
},
},
"is_featured": schema.BoolAttribute{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/deploymenttheory/terraform-provider-microsoft365/internal/resources/common/state"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/microsoftgraph/msgraph-beta-sdk-go/models"
Expand Down Expand Up @@ -41,13 +42,28 @@ func MapRemoteStateToTerraform(ctx context.Context, data *WinGetAppResourceModel
data.SupersededAppCount = state.Int32PtrToTypeInt64(remoteResource.GetSupersededAppCount())

// Handle LargeIcon
largeIconObj := types.ObjectNull(
map[string]attr.Type{
"type": types.StringType,
"value": types.StringType,
},
)

if largeIcon := remoteResource.GetLargeIcon(); largeIcon != nil {
data.LargeIcon = &MimeContentModel{
Type: types.StringValue(state.StringPtrToString(largeIcon.GetTypeEscaped())),
Value: types.StringValue(string(largeIcon.GetValue())),
}
largeIconObj, _ = types.ObjectValue(
map[string]attr.Type{
"type": types.StringType,
"value": types.StringType,
},
map[string]attr.Value{
"type": types.StringValue(state.StringPtrToString(largeIcon.GetTypeEscaped())),
"value": types.StringValue(state.ByteToString(largeIcon.GetValue())),
},
)
}

data.LargeIcon = largeIconObj

// Handle InstallExperience
if installExperience := remoteResource.GetInstallExperience(); installExperience != nil {
data.InstallExperience = &WinGetAppInstallExperienceModel{
Expand Down

0 comments on commit 98af486

Please sign in to comment.