Skip to content

Commit

Permalink
azurerm_container_group - set storage_account_key in the update o…
Browse files Browse the repository at this point in the history
…peration (#26640)

* azurerm_container_group - set storage_account_key in the update operation

* update tc name

* change to mcr

* update TestAccDataSourceContainerGroup_complete

* change to mcr

* move api call to identity block

* update image

* update tc port
  • Loading branch information
neil-yechenwei committed Aug 8, 2024
1 parent ac920eb commit 81742d5
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 48 deletions.
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

0 comments on commit 81742d5

Please sign in to comment.