diff --git a/internal/services/automation/automation_powershell72_module_resource.go b/internal/services/automation/automation_powershell72_module_resource.go index 6c07cb8479d2..5d35ec457c5a 100644 --- a/internal/services/automation/automation_powershell72_module_resource.go +++ b/internal/services/automation/automation_powershell72_module_resource.go @@ -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" @@ -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{} @@ -83,6 +86,7 @@ func (r PowerShell72ModuleResource) Arguments() map[string]*pluginsdk.Schema { }, }, }, + "tags": commonschema.Tags(), } } @@ -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 { @@ -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) } @@ -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) }, diff --git a/internal/services/automation/automation_powershell72_module_resource_test.go b/internal/services/automation/automation_powershell72_module_resource_test.go index 9d03f7e0e6e6..4ace597bf8eb 100644 --- a/internal/services/automation/automation_powershell72_module_resource_test.go +++ b/internal/services/automation/automation_powershell72_module_resource_test.go @@ -206,6 +206,10 @@ resource "azurerm_automation_powershell72_module" "test" { value = "5277774C7D6FC0E60986519D2D16C7100B9948B2D0B62091ED7B489A252F0F6D" } } + + tags = { + Env = "ACC" + } } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } diff --git a/website/docs/r/automation_powershell72_module.html.markdown b/website/docs/r/automation_powershell72_module.html.markdown index af1b5abf17b5..c33141ce327b 100644 --- a/website/docs/r/automation_powershell72_module.html.markdown +++ b/website/docs/r/automation_powershell72_module.html.markdown @@ -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: