From 6f133de864b3594c499743bdb246a1575c17c357 Mon Sep 17 00:00:00 2001 From: lawrencegripper Date: Tue, 10 Jul 2018 12:48:14 +0100 Subject: [PATCH 1/6] Added imageRegistryCredentials to container group --- azurerm/resource_arm_container_group.go | 85 ++++++++++++++++++- .../aci-image-registry-credentials/main.tf | 37 ++++++++ 2 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 examples/aci-image-registry-credentials/main.tf diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index 1203b1aba2c3..99e20b835090 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -53,6 +53,30 @@ func resourceArmContainerGroup() *schema.Resource { }, true), }, + "image_registry_credential": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "server": { + Type: schema.TypeString, + Required: true, + }, + + "username": { + Type: schema.TypeString, + Required: true, + }, + + "password": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, + "tags": tagsForceNewSchema(), "restart_policy": { @@ -198,6 +222,7 @@ func resourceArmContainerGroupCreate(d *schema.ResourceData, meta interface{}) e IPAddressType := d.Get("ip_address_type").(string) tags := d.Get("tags").(map[string]interface{}) restartPolicy := d.Get("restart_policy").(string) + imageCredentials := expandContainerImageRegistryCredentials(d) containers, containerGroupPorts, containerGroupVolumes := expandContainerGroupContainers(d) containerGroup := containerinstance.ContainerGroup{ @@ -211,8 +236,9 @@ func resourceArmContainerGroupCreate(d *schema.ResourceData, meta interface{}) e Type: &IPAddressType, Ports: containerGroupPorts, }, - OsType: containerinstance.OperatingSystemTypes(OSType), - Volumes: containerGroupVolumes, + OsType: containerinstance.OperatingSystemTypes(OSType), + Volumes: containerGroupVolumes, + ImageRegistryCredentials: imageCredentials, }, } @@ -264,6 +290,11 @@ func resourceArmContainerGroupRead(d *schema.ResourceData, meta interface{}) err d.Set("location", azureRMNormalizeLocation(*resp.Location)) flattenAndSetTags(d, resp.Tags) + imageRegistryCredentials := flattenContainerImageRegistryCredentials(resp.ImageRegistryCredentials) + if imageRegistryCredentials != nil { + d.Set("image_registry_credential", imageRegistryCredentials) + } + d.Set("os_type", string(resp.OsType)) if address := resp.IPAddress; address != nil { d.Set("ip_address_type", address.Type) @@ -516,6 +547,56 @@ func expandContainerEnvironmentVariables(input interface{}) *[]containerinstance return &output } +func expandContainerImageRegistryCredentials(d *schema.ResourceData) *[]containerinstance.ImageRegistryCredential { + credsRaw := d.Get("image_registry_credential").([]interface{}) + + output := make([]containerinstance.ImageRegistryCredential, 0, len(credsRaw)) + + if len(credsRaw) == 0 { + return nil + } + + 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, + }) + } + + return &output +} + +func flattenContainerImageRegistryCredentials(credsPtr *[]containerinstance.ImageRegistryCredential) []interface{} { + if credsPtr == nil { + return nil + } + + creds := *credsPtr + output := make([]interface{}, len(creds)) + for _, cred := range creds { + credConfig := make(map[string]interface{}) + if cred.Server != nil { + credConfig["server"] = *cred.Server + } + if cred.Password != nil { + credConfig["password"] = *cred.Password + } + if cred.Username != nil { + credConfig["username"] = *cred.Username + } + + output = append(output, credConfig) + } + return output +} + func expandContainerVolumes(input interface{}) (*[]containerinstance.VolumeMount, *[]containerinstance.Volume) { volumesRaw := input.([]interface{}) diff --git a/examples/aci-image-registry-credentials/main.tf b/examples/aci-image-registry-credentials/main.tf new file mode 100644 index 000000000000..e9fecdeb88fc --- /dev/null +++ b/examples/aci-image-registry-credentials/main.tf @@ -0,0 +1,37 @@ +resource "azurerm_resource_group" "aci-rg" { + name = "aci-test-creds" + location = "west us" +} + +resource "azurerm_container_group" "aci-test" { + name = "my-aci-hw" + location = "${azurerm_resource_group.aci-rg.location}" + resource_group_name = "${azurerm_resource_group.aci-rg.name}" + ip_address_type = "public" + os_type = "linux" + + image_registry_credential { + server = "hub.docker.com" + username = "yourusername1" + password = "yourpassword" + } + + container { + name = "hw" + image = "microsoft/aci-helloworld:latest" + cpu = "0.5" + memory = "1.5" + port = "80" + } + + container { + name = "sidecar" + image = "microsoft/aci-tutorial-sidecar" + cpu = "0.5" + memory = "1.5" + } + + tags { + environment = "testing" + } +} From 6434cf6296ac95df0b1c63eec4e1b30071a7e3ff Mon Sep 17 00:00:00 2001 From: lawrencegripper Date: Tue, 10 Jul 2018 13:34:27 +0100 Subject: [PATCH 2/6] Update docs to add image_registry_credentials --- website/docs/r/container_group.html.markdown | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/website/docs/r/container_group.html.markdown b/website/docs/r/container_group.html.markdown index accd835f7158..1eba571ff93a 100644 --- a/website/docs/r/container_group.html.markdown +++ b/website/docs/r/container_group.html.markdown @@ -94,6 +94,8 @@ The following arguments are supported: * `restart_policy` - (Optional) Restart policy for the container group. Allowed values are `Always`, `Never`, `OnFailure`. Defaults to `Always`. +* `image_registry_credential` - (Optional) Set image registry credentials for the group as documented in the `image_registry_credential` block below + * `container` - (Required) The definition of a container that is part of the group as documented in the `container` block below. Changing this forces a new resource to be created. ~> **Note:** if `os_type` is set to `Windows` currently only a single `container` block is supported. @@ -130,6 +132,14 @@ The `volume` block supports: * `share_name` - (Required) The Azure storage share that is to be mounted as a volume. This must be created on the storage account specified as above. Changing this forces a new resource to be created. +The `image_registry_credential` block supports: + +* `username` - (Required) The username with which to connect to the registry. + +* `password` - (Required) The password with which to connect to the registry. + +* `server` - (Required) The address to use to connect to the registry without protocol ("https"/"http"). For example: "myacr.acr.io" + ## Attributes Reference The following attributes are exported: From af8f84bffeee10fdb14116110db3bd73e83ddcb5 Mon Sep 17 00:00:00 2001 From: lawrencegripper Date: Tue, 10 Jul 2018 14:05:07 +0100 Subject: [PATCH 3/6] Added test and fixes from pr #1509 --- azurerm/resource_arm_container_group.go | 48 +++++++----- azurerm/resource_arm_container_group_test.go | 78 +++++++++++++++++++- 2 files changed, 107 insertions(+), 19 deletions(-) diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index eeb974cdd4bc..0ca6e8bd265d 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -56,18 +56,25 @@ func resourceArmContainerGroup() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "server": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.NoZeroValues, + ForceNew: true, }, "username": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.NoZeroValues, + ForceNew: true, }, "password": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + Sensitive: true, + ValidateFunc: validation.NoZeroValues, + ForceNew: true, }, }, }, @@ -229,7 +236,6 @@ func resourceArmContainerGroupCreate(d *schema.ResourceData, meta interface{}) e IPAddressType := d.Get("ip_address_type").(string) tags := d.Get("tags").(map[string]interface{}) restartPolicy := d.Get("restart_policy").(string) - imageCredentials := expandContainerImageRegistryCredentials(d) containers, containerGroupPorts, containerGroupVolumes := expandContainerGroupContainers(d) containerGroup := containerinstance.ContainerGroup{ @@ -245,7 +251,7 @@ func resourceArmContainerGroupCreate(d *schema.ResourceData, meta interface{}) e }, OsType: containerinstance.OperatingSystemTypes(OSType), Volumes: containerGroupVolumes, - ImageRegistryCredentials: imageCredentials, + ImageRegistryCredentials: expandContainerImageRegistryCredentials(d), }, } @@ -303,9 +309,8 @@ func resourceArmContainerGroupRead(d *schema.ResourceData, meta interface{}) err } flattenAndSetTags(d, resp.Tags) - imageRegistryCredentials := flattenContainerImageRegistryCredentials(resp.ImageRegistryCredentials) - if imageRegistryCredentials != nil { - d.Set("image_registry_credential", imageRegistryCredentials) + if imageRegCreds := flattenContainerImageRegistryCredentials(d, resp.ImageRegistryCredentials); imageRegCreds != nil { + d.Set("image_registry_credential", imageRegCreds) } d.Set("os_type", string(resp.OsType)) @@ -564,13 +569,12 @@ func expandContainerEnvironmentVariables(input interface{}) *[]containerinstance func expandContainerImageRegistryCredentials(d *schema.ResourceData) *[]containerinstance.ImageRegistryCredential { credsRaw := d.Get("image_registry_credential").([]interface{}) - - output := make([]containerinstance.ImageRegistryCredential, 0, len(credsRaw)) - if len(credsRaw) == 0 { return nil } + output := make([]containerinstance.ImageRegistryCredential, 0, len(credsRaw)) + for _, c := range credsRaw { credConfig := c.(map[string]interface{}) @@ -588,10 +592,11 @@ func expandContainerImageRegistryCredentials(d *schema.ResourceData) *[]containe return &output } -func flattenContainerImageRegistryCredentials(credsPtr *[]containerinstance.ImageRegistryCredential) []interface{} { +func flattenContainerImageRegistryCredentials(d *schema.ResourceData, credsPtr *[]containerinstance.ImageRegistryCredential) []interface{} { if credsPtr == nil { return nil } + configsOld := d.Get("image_registry_credential").([]interface{}) creds := *credsPtr output := make([]interface{}, len(creds)) @@ -600,13 +605,20 @@ func flattenContainerImageRegistryCredentials(credsPtr *[]containerinstance.Imag if cred.Server != nil { credConfig["server"] = *cred.Server } - if cred.Password != nil { - credConfig["password"] = *cred.Password - } if cred.Username != nil { credConfig["username"] = *cred.Username } + for i, configsOld := range configsOld { + data := configsOld.(map[string]interface{}) + oldServer := data["server"].(string) + if cred.Server != nil && *cred.Server == oldServer { + if v, ok := d.GetOk(fmt.Sprintf("image_registry_credential.%d.password", i)); ok { + credConfig["password"] = v.(string) + } + } + } + output = append(output, credConfig) } return output diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index 5b9e655e6e98..f210a73a9acf 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -11,12 +11,40 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestAccAzureRMContainerGroup_linuxBasic(t *testing.T) { +func TestAccAzureRMContainerGroup_imageRegistryCredentials(t *testing.T) { resourceName := "azurerm_container_group.test" ri := acctest.RandInt() config := testAccAzureRMContainerGroup_linuxBasic(ri, testLocation()) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMContainerGroupDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMContainerGroupExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.#:", "2"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.server", "hub.docker.com"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.username", "yourusername"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.password:", "yourpassword"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.server", "mine.acr.io"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.username", "acrusername"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.password:", "acrpassword"), + ), + }, + }, + }) +} + +func TestAccAzureRMContainerGroup_linuxBasic(t *testing.T) { + resourceName := "azurerm_container_group.test" + ri := acctest.RandInt() + + config := testAccAzureRMContainerGroup_imageRegistryCredentials(ri, testLocation()) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -176,6 +204,54 @@ resource "azurerm_container_group" "test" { `, ri, location, ri) } +func testAccAzureRMContainerGroup_imageRegistryCredentials(ri int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_container_group" "test" { + name = "acctestcontainergroup-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + ip_address_type = "public" + os_type = "linux" + + container { + name = "hw" + image = "microsoft/aci-helloworld:latest" + cpu = "0.5" + memory = "0.5" + port = "80" + } + + image_registry_credential { + server = "hub.docker.com" + username = "yourusername" + password = "yourpassword" + } + + image_registry_credential { + server = "mine.acr.io" + username = "acrusername" + password = "acrpassword" + } + + container { + name = "sidecar" + image = "microsoft/aci-tutorial-sidecar" + cpu = "0.5" + memory = "0.5" + } + + tags { + environment = "Testing" + } +} +`, ri, location, ri) +} + func testAccAzureRMContainerGroup_linuxBasicUpdated(ri int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { From 06aa6047ca85b31dd539ac4ab7eb13484186219a Mon Sep 17 00:00:00 2001 From: lawrencegripper Date: Wed, 11 Jul 2018 11:46:29 +0100 Subject: [PATCH 4/6] Fix up review feedback --- azurerm/resource_arm_container_group.go | 19 +++++++++---------- azurerm/resource_arm_container_group_test.go | 2 +- .../aci-image-registry-credentials/main.tf | 6 ++++++ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index 0ca6e8bd265d..60a6f1819850 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -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)) @@ -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)), }) } @@ -599,7 +595,7 @@ 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 { credConfig := make(map[string]interface{}) if cred.Server != nil { @@ -610,6 +606,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 { diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index f210a73a9acf..652144881a65 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -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 { diff --git a/examples/aci-image-registry-credentials/main.tf b/examples/aci-image-registry-credentials/main.tf index e9fecdeb88fc..97f2f868e7f4 100644 --- a/examples/aci-image-registry-credentials/main.tf +++ b/examples/aci-image-registry-credentials/main.tf @@ -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" From 1114183a668b3cd719591089a8d636ee60bb3d63 Mon Sep 17 00:00:00 2001 From: lawrencegripper Date: Fri, 13 Jul 2018 16:59:18 +0100 Subject: [PATCH 5/6] Further tests and tweaks --- azurerm/resource_arm_container_group.go | 17 ++-- azurerm/resource_arm_container_group_test.go | 89 +++++++++++++++++++- 2 files changed, 91 insertions(+), 15 deletions(-) diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index 60a6f1819850..0bf7b99a0f72 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -596,7 +596,7 @@ func flattenContainerImageRegistryCredentials(d *schema.ResourceData, credsPtr * creds := *credsPtr output := make([]interface{}, 0, len(creds)) - for _, cred := range creds { + for i, cred := range creds { credConfig := make(map[string]interface{}) if cred.Server != nil { credConfig["server"] = *cred.Server @@ -605,16 +605,11 @@ func flattenContainerImageRegistryCredentials(d *schema.ResourceData, credsPtr * credConfig["username"] = *cred.Username } - 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 { - if v, ok := d.GetOk(fmt.Sprintf("image_registry_credential.%d.password", i)); ok { - credConfig["password"] = v.(string) - } + data := configsOld[i].(map[string]interface{}) + oldServer := data["server"].(string) + if cred.Server != nil && *cred.Server == oldServer { + if v, ok := d.GetOk(fmt.Sprintf("image_registry_credential.%d.password", i)); ok { + credConfig["password"] = v.(string) } } diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index 652144881a65..e14238af7cbc 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -15,7 +15,36 @@ func TestAccAzureRMContainerGroup_imageRegistryCredentials(t *testing.T) { resourceName := "azurerm_container_group.test" ri := acctest.RandInt() - config := testAccAzureRMContainerGroup_linuxBasic(ri, testLocation()) + config := testAccAzureRMContainerGroup_imageRegistryCredentials(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMContainerGroupDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMContainerGroupExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.#", "2"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.server", "hub.docker.com"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.username", "yourusername"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.password", "yourpassword"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.server", "mine.acr.io"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.username", "acrusername"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.password", "acrpassword"), + ), + }, + }, + }) +} + +func TestAccAzureRMContainerGroup_imageRegistryCredentialsUpdate(t *testing.T) { + resourceName := "azurerm_container_group.test" + ri := acctest.RandInt() + + config := testAccAzureRMContainerGroup_imageRegistryCredentials(ri, testLocation()) + updated := testAccAzureRMContainerGroup_imageRegistryCredentialsUpdated(ri, testLocation()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -26,13 +55,23 @@ func TestAccAzureRMContainerGroup_imageRegistryCredentials(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( testCheckAzureRMContainerGroupExists(resourceName), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.#:", "2"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.#", "2"), resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.server", "hub.docker.com"), resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.username", "yourusername"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.password:", "yourpassword"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.password", "yourpassword"), resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.server", "mine.acr.io"), resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.username", "acrusername"), - resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.password:", "acrpassword"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.1.password", "acrpassword"), + ), + }, + { + Config: updated, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMContainerGroupExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.#", "1"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.server", "hub.docker.com"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.username", "updatedusername"), + resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.password", "updatedpassword"), ), }, }, @@ -252,6 +291,48 @@ resource "azurerm_container_group" "test" { `, ri, location, ri) } +func testAccAzureRMContainerGroup_imageRegistryCredentialsUpdated(ri int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_container_group" "test" { + name = "acctestcontainergroup-%d" + location = "${azurerm_resource_group.test.location}" + resource_group_name = "${azurerm_resource_group.test.name}" + ip_address_type = "public" + os_type = "linux" + + container { + name = "hw" + image = "microsoft/aci-helloworld:latest" + cpu = "0.5" + memory = "0.5" + port = "80" + } + + image_registry_credential { + server = "hub.docker.com" + username = "updatedusername" + password = "updatedpassword" + } + + container { + name = "sidecar" + image = "microsoft/aci-tutorial-sidecar" + cpu = "0.5" + memory = "0.5" + } + + tags { + environment = "Testing" + } +} +`, ri, location, ri) +} + func testAccAzureRMContainerGroup_linuxBasicUpdated(ri int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { From b706c8b15eea4b93a19d8e9773a9e1731cd91d50 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 16 Jul 2018 12:45:31 +0200 Subject: [PATCH 6/6] Reverting the LinuxBasic test Tests pass: ``` $ acctests azurerm TestAccAzureRMContainerGroup_linuxBasic === RUN TestAccAzureRMContainerGroup_linuxBasic --- PASS: TestAccAzureRMContainerGroup_linuxBasic (86.67s) === RUN TestAccAzureRMContainerGroup_linuxBasicUpdate --- PASS: TestAccAzureRMContainerGroup_linuxBasicUpdate (107.92s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 194.641s ``` --- azurerm/resource_arm_container_group_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index e14238af7cbc..742151705837 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -82,7 +82,7 @@ func TestAccAzureRMContainerGroup_linuxBasic(t *testing.T) { resourceName := "azurerm_container_group.test" ri := acctest.RandInt() - config := testAccAzureRMContainerGroup_imageRegistryCredentials(ri, testLocation()) + config := testAccAzureRMContainerGroup_linuxBasic(ri, testLocation()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) },