Skip to content

Commit

Permalink
azurerm_automation_powershell72_module: support tag property (#26106
Browse files Browse the repository at this point in the history
)

* add tag support for ps72 module

* udpate tags as map[string]interface{}
  • Loading branch information
wuxu92 authored May 27, 2024
1 parent a583c78 commit ecce5f2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"time"

"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 @@ -29,9 +31,10 @@ type ModuleHash struct {
}

type AutomationPowerShell72ModuleModel struct {
AutomationAccountID string `tfschema:"automation_account_id"`
Name string `tfschema:"name"`
ModuleLink []ModuleLinkModel `tfschema:"module_link"`
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 @@ -83,6 +86,7 @@ func (r PowerShell72ModuleResource) Arguments() map[string]*pluginsdk.Schema {
},
},
},
"tags": commonschema.Tags(),
}
}

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

if _, err := client.PowerShell72ModuleCreateOrUpdate(ctx, id, parameters); err != nil {
Expand Down Expand Up @@ -228,6 +233,10 @@ func (r PowerShell72ModuleResource) Update() sdk.ResourceFunc {
},
}

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

if _, err := client.PowerShell72ModuleCreateOrUpdate(ctx, *id, parameters); err != nil {
return fmt.Errorf("updating %s: %+v", id, err)
}
Expand Down Expand Up @@ -320,6 +329,9 @@ func (r PowerShell72ModuleResource) Read() sdk.ResourceFunc {

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

return metadata.Encode(&output)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ resource "azurerm_automation_powershell72_module" "test" {
value = "5277774C7D6FC0E60986519D2D16C7100B9948B2D0B62091ED7B489A252F0F6D"
}
}
tags = {
Env = "ACC"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}
2 changes: 2 additions & 0 deletions website/docs/r/automation_powershell72_module.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ The following arguments are supported:

* `module_link` - (Required) A `module_link` block as defined below.

* `tags` - (Optional) A mapping of tags to assign to the resource.

---

The `module_link` block supports the following:
Expand Down

0 comments on commit ecce5f2

Please sign in to comment.