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
35 changes: 31 additions & 4 deletions internal/services/containers/container_group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -855,14 +855,41 @@ func resourceContainerGroupUpdate(d *pluginsdk.ResourceData, meta interface{}) e
return fmt.Errorf("expanding `identity`: %+v", err)
}
model.Identity = expandedIdentity

// 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)
}
}

if d.HasChange("tags") {
model.Tags = tags.Expand(d.Get("tags").(map[string]interface{}))
}
updateParameters := containerinstance.Resource{
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

if err := client.ContainerGroupsCreateOrUpdateThenPoll(ctx, *id, model); err != nil {
return fmt.Errorf("updating %s: %+v", *id, err)
// 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