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_container_group - set storage_account_key in the update operation #26640

Merged
merged 9 commits into from
Aug 8, 2024
Merged
31 changes: 29 additions & 2 deletions internal/services/containers/container_group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,14 +857,41 @@ func resourceContainerGroupUpdate(d *pluginsdk.ResourceData, meta interface{}) e
model.Identity = expandedIdentity
}

if d.HasChange("tags") {
model.Tags = tags.Expand(d.Get("tags").(map[string]interface{}))
// As API doesn't return the value of StorageAccountKey, so it has to get the value from tf config and set it to request payload. Otherwise, the Update API call would fail
addedEmptyDirs := map[string]bool{}
_, initContainerVolumes, err := expandContainerGroupInitContainers(d, addedEmptyDirs)
if err != nil {
return err
}
_, _, containerVolumes, err := expandContainerGroupContainers(d, addedEmptyDirs)
if err != nil {
return err
}
var containerGroupVolumes []containerinstance.Volume
if initContainerVolumes != nil {
containerGroupVolumes = initContainerVolumes
}
if containerGroupVolumes != nil {
containerGroupVolumes = append(containerGroupVolumes, containerVolumes...)
}
model.Properties.Volumes = pointer.To(containerGroupVolumes)

// As Update API doesn't support to update identity, so it has to use CreateOrUpdate API to update identity
if err := client.ContainerGroupsCreateOrUpdateThenPoll(ctx, *id, model); err != nil {
return fmt.Errorf("updating %s: %+v", *id, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

If only the tags are updated then we would be making an unnecessary update call. I think this whole block should be moved into

if d.HasChange("identity") {
...
}

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 d.HasChange("tags") {
updateParameters := containerinstance.Resource{
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

// As CreateOrUpdate API doesn't support to update tags, so it has to use Update API to update tags
if _, err := client.ContainerGroupsUpdate(ctx, *id, updateParameters); err != nil {
return fmt.Errorf("updating tags %s: %+v", *id, err)
}
}

return resourceContainerGroupRead(d, meta)
}

Expand Down
Loading
Loading