-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
resource/container_group: add registry credential #1529
Merged
tombuildsstuff
merged 7 commits into
hashicorp:master
from
lawrencegripper:lg/addcredstoaci
Jul 16, 2018
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6f133de
Added imageRegistryCredentials to container group
lawrencegripper 6434cf6
Update docs to add image_registry_credentials
lawrencegripper 73b236a
Merge remote-tracking branch 'upstream/master' into lg/addcredstoaci
lawrencegripper af8f84b
Added test and fixes from pr #1509
lawrencegripper 06aa604
Fix up review feedback
lawrencegripper 1114183
Further tests and tweaks
lawrencegripper b706c8b
Reverting the LinuxBasic test
tombuildsstuff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the tests are failing since this has been updated but the counts are incorrect; going to push a test to revert this to |
||
|
||
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" { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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" | ||
} | ||
|
||
image_registry_credential { | ||
server = "2hub.docker.com" | ||
username = "2yourusername1" | ||
password = "2yourpassword" | ||
} | ||
|
||
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, but i presume the ordering is consistent so you could get the old values this way:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little uncertain on this one so was being careful. Does the ordering of elements relate to the ordering of the elements in HCL? So for example if the user update the
password
element in their template but also moved the credential block ahead of another existing block would that affect this approach (making sure the server name matches)? Feels like an edge case either way round.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the order of the list directly relates to the order of the elements in HCL. So if the user does as you describe, the Apply would be sending a new list anyways, and the subsequent read would be post Update. unless azure returns things in a different order I think it should be fine. You could always write a test to confirm 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, makes sense to me. Will also check with the test just to be on the safe side.