Skip to content

Commit

Permalink
Fix up review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrencegripper committed Jul 11, 2018
1 parent af8f84b commit 087eaff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
24 changes: 14 additions & 10 deletions azurerm/resource_arm_container_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ func resourceArmContainerGroupRead(d *schema.ResourceData, meta interface{}) err
}
flattenAndSetTags(d, resp.Tags)

if imageRegCreds := flattenContainerImageRegistryCredentials(d, resp.ImageRegistryCredentials); imageRegCreds != nil {
d.Set("image_registry_credential", imageRegCreds)
if err := d.Set("image_registry_credential", flattenContainerImageRegistryCredentials(d, resp.ImageRegistryCredentials)); err != nil {
return fmt.Errorf("Error setting `capabilities`: %+v", err)
}

d.Set("os_type", string(resp.OsType))
Expand Down Expand Up @@ -578,14 +578,10 @@ func expandContainerImageRegistryCredentials(d *schema.ResourceData) *[]containe
for _, c := range credsRaw {
credConfig := c.(map[string]interface{})

server := credConfig["server"].(string)
username := credConfig["username"].(string)
password := credConfig["password"].(string)

output = append(output, containerinstance.ImageRegistryCredential{
Server: &server,
Password: &password,
Username: &username,
Server: utils.String(credConfig["server"].(string)),
Password: utils.String(credConfig["password"].(string)),
Username: utils.String(credConfig["username"].(string)),
})
}

Expand All @@ -599,8 +595,13 @@ func flattenContainerImageRegistryCredentials(d *schema.ResourceData, credsPtr *
configsOld := d.Get("image_registry_credential").([]interface{})

creds := *credsPtr
output := make([]interface{}, len(creds))
output := make([]interface{}, 0, len(creds))
for _, cred := range creds {
// Seems some responses include empty items. Ignore these.
if cred.Server == nil {
continue
}

credConfig := make(map[string]interface{})
if cred.Server != nil {
credConfig["server"] = *cred.Server
Expand All @@ -610,6 +611,9 @@ func flattenContainerImageRegistryCredentials(d *schema.ResourceData, credsPtr *
}

for i, configsOld := range configsOld {
if configsOld == nil {
continue
}
data := configsOld.(map[string]interface{})
oldServer := data["server"].(string)
if cred.Server != nil && *cred.Server == oldServer {
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_container_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ resource "azurerm_container_group" "test" {
image = "microsoft/aci-helloworld:latest"
cpu = "0.5"
memory = "0.5"
port = "80"
port = "80"
}
image_registry_credential {
Expand Down
6 changes: 6 additions & 0 deletions examples/aci-image-registry-credentials/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ resource "azurerm_container_group" "aci-test" {
password = "yourpassword"
}

image_registry_credential {
server = "2hub.docker.com"
username = "2yourusername1"
password = "2yourpassword"
}

container {
name = "hw"
image = "microsoft/aci-helloworld:latest"
Expand Down

0 comments on commit 087eaff

Please sign in to comment.