Skip to content

Commit

Permalink
udpate tags as map[string]interface{}
Browse files Browse the repository at this point in the history
  • Loading branch information
wuxu92 committed May 27, 2024
1 parent fc129a0 commit 563dfd5
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/automation/2023-11-01/module"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
Expand All @@ -31,10 +31,10 @@ type ModuleHash struct {
}

type AutomationPowerShell72ModuleModel struct {
AutomationAccountID string `tfschema:"automation_account_id"`
Name string `tfschema:"name"`
ModuleLink []ModuleLinkModel `tfschema:"module_link"`
Tags map[string]string `tfschema:"tags"`
AutomationAccountID string `tfschema:"automation_account_id"`
Name string `tfschema:"name"`
ModuleLink []ModuleLinkModel `tfschema:"module_link"`
Tags map[string]interface{} `tfschema:"tags"`
}

type PowerShell72ModuleResource struct{}
Expand Down Expand Up @@ -142,7 +142,7 @@ func (r PowerShell72ModuleResource) Create() sdk.ResourceFunc {
Properties: module.ModuleCreateOrUpdateProperties{
ContentLink: expandPowerShell72ModuleLink(model.ModuleLink),
},
Tags: pointer.To(model.Tags),
Tags: tags.Expand(model.Tags),
}

if _, err := client.PowerShell72ModuleCreateOrUpdate(ctx, id, parameters); err != nil {
Expand Down Expand Up @@ -231,7 +231,10 @@ func (r PowerShell72ModuleResource) Update() sdk.ResourceFunc {
Properties: module.ModuleCreateOrUpdateProperties{
ContentLink: expandPowerShell72ModuleLink(model.ModuleLink),
},
Tags: pointer.To(model.Tags),
}

if metadata.ResourceData.HasChange("tags") {
parameters.Tags = tags.Expand(model.Tags)
}

if _, err := client.PowerShell72ModuleCreateOrUpdate(ctx, *id, parameters); err != nil {
Expand Down Expand Up @@ -326,7 +329,9 @@ func (r PowerShell72ModuleResource) Read() sdk.ResourceFunc {

output.Name = id.PowerShell72ModuleName
output.AutomationAccountID = module.NewAutomationAccountID(id.SubscriptionId, id.ResourceGroupName, id.AutomationAccountName).ID()
output.Tags = pointer.From(resp.Model.Tags)
if resp.Model != nil {
output.Tags = tags.Flatten(resp.Model.Tags)
}

return metadata.Encode(&output)
},
Expand Down

0 comments on commit 563dfd5

Please sign in to comment.