Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_automation_powershell72_module: support tag property #26106

Merged
merged 2 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +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-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 @@ -32,6 +34,7 @@ type AutomationPowerShell72ModuleModel struct {
AutomationAccountID string `tfschema:"automation_account_id"`
Name string `tfschema:"name"`
ModuleLink []ModuleLinkModel `tfschema:"module_link"`
Tags map[string]string `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: pointer.To(model.Tags),
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use d.HasChanges("tags") here before adding it to parameters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated,

}

if _, err := client.PowerShell72ModuleCreateOrUpdate(ctx, *id, parameters); err != nil {
Expand Down Expand Up @@ -320,6 +326,7 @@ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like we do elsewhere for Tags in the read, can we nil check the Model and use the tags.Flatten function.

Suggested change
output.Tags = pointer.From(resp.Model.Tags)
if model := resp.Model; model != nil {
output.Tags = tags.Flatten(model.Tags)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated,


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
Loading