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

resource/container_group: add registry credential #1529

Merged
merged 7 commits into from
Jul 16, 2018

Conversation

lawrencegripper
Copy link
Contributor

When I noticed this feature was missing I checked the issues and didn't see anything so set about working on it. When I came to raise the PR I noticed that #1509 was already in progress.

As I'd already included docs, test and an example (not in the current PR work) I thought it's still worth raising this PR as these can be merged into the existing PR and don't go to waste.

cc/ @tharvik and @katbyte

Ps. will check open PR's next time :(

@katbyte
Copy link
Collaborator

katbyte commented Jul 10, 2018

Hi @lawrencegripper,

Regardless thank you for your contribution! As #1509 was just pulling some old commits out of the repo and lacks documentation/tests I am going to close it in favour of yours.

I will review it shortly.

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lawrencegripper,

I've left a few inline comments but otherwise this mostly LGTM! Look forward to getting this merged once they are addressed.

@@ -277,6 +309,10 @@ 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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we check for an error here? like:

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

d.Set() sill handle a nil value correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, make sense I'll fix this up

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

output = append(output, containerinstance.ImageRegistryCredential{
Server: &server,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor but these could be assigned inline via utils.String()

Server: utils.String(credConfig["username"].(string)),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah much nicer, I thought about bringing in the to package from Autorest as has lots of these funcs too didn't realize you already had one.

credConfig["username"] = *cred.Username
}

for i, configsOld := range configsOld {
Copy link
Collaborator

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:

for i, oldIrcConfig := range ircConfigsOld {
...

    if v, ok := d.GetOk(fmt.Sprintf("image_registry_credential.%d.password", i)); ok {
        block["password"] = v.(string)
    }
}

Copy link
Contributor Author

@lawrencegripper lawrencegripper Jul 11, 2018

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.

Copy link
Collaborator

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 🙂

Copy link
Contributor Author

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.

image = "microsoft/aci-helloworld:latest"
cpu = "0.5"
memory = "0.5"
port = "80"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we fix the alignment here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woop will do

@katbyte katbyte changed the title resource/container_group: add registry credential v2 (oops) resource/container_group: add registry credential Jul 11, 2018
@lawrencegripper
Copy link
Contributor Author

lawrencegripper commented Jul 13, 2018

Tests look good and hopefully all feedback is sorted.

2018/07/13 16:56:10 debugger.go:518: continuing
=== RUN   TestAccAzureRMContainerGroup_imageRegistryCredentials
--- PASS: TestAccAzureRMContainerGroup_imageRegistryCredentials (62.86s)
=== RUN   TestAccAzureRMContainerGroup_imageRegistryCredentialsUpdate
--- PASS: TestAccAzureRMContainerGroup_imageRegistryCredentialsUpdate (75.83s)
PASS

func TestAccAzureRMContainerGroup_linuxBasic(t *testing.T) {
resourceName := "azurerm_container_group.test"
ri := acctest.RandInt()

config := testAccAzureRMContainerGroup_linuxBasic(ri, testLocation())
config := testAccAzureRMContainerGroup_imageRegistryCredentials(ri, testLocation())
Copy link
Contributor

Choose a reason for hiding this comment

The 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 TestAccAzureRMContainerGroup_linuxBasic

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
```
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for this 👍

@tombuildsstuff tombuildsstuff dismissed katbyte’s stale review July 16, 2018 10:50

changes have been pushed

@tombuildsstuff
Copy link
Contributor

Tests pass with the test fix:

screenshot 2018-07-16 at 13 04 01

@tombuildsstuff tombuildsstuff merged commit fe9975d into hashicorp:master Jul 16, 2018
tombuildsstuff added a commit that referenced this pull request Jul 16, 2018
@lawrencegripper
Copy link
Contributor Author

Thanks @tombuildsstuff, sorry for messing up the linuxBasic tests was only running the new tests I'd added so I missed it - will remember to run all tests in future.

@tombuildsstuff
Copy link
Contributor

@lawrencegripper no worries - easily done, thanks again for this PR :)

@ghost
Copy link

ghost commented Mar 30, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants