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

Container groups: Add support for env vars and command line #336

Closed
wants to merge 0 commits into from

Conversation

abhijeetgaiha
Copy link

More progress on #287

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.

Hey @abhijeetgaiha

Thanks for this PR :)

I've taken a look through and left some comments in-line, but this generally looks good.

Thanks!

@@ -197,6 +188,9 @@ func resourceArmContainerGroupRead(d *schema.ResourceData, meta interface{}) err
resp, err := containterGroupsClient.Get(resGroup, name)

if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

given the Read method is used for several things (both checking that a resource exists at Plan time, and for parsing data from the API) - can we add d.SetId("") before the return nil here to ensure that deleted resources are detected?

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@@ -265,12 +259,33 @@ func flattenContainerGroupContainers(containers *[]containerinstance.Container)
}
// protocol isn't returned in container config

if len(*container.EnvironmentVariables) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

this'll crash if container.EnvironmentVariables is nil - could we add an if statement around this?

Copy link
Author

Choose a reason for hiding this comment

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

It's never nil, but a check is warranted to be safe. Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

To add some context to why this check is needed: if the Swagger is incorrect (which historically has happened a lot) this would be mapped incorrectly and crash

resource.TestCheckResourceAttr(resourceName, "ip_address_type", "Public"),
resource.TestCheckResourceAttr(resourceName, "os_type", "Linux"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.environment", "testing"),
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest that checking all of these is probably overkill, since the Import tests will do this for us (by deploying the input configuration, and then comparing the remote state against it - without specifying each fields values)

Instead - we could probably just check the OS Type / Environment Variables here?

Copy link
Author

Choose a reason for hiding this comment

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

In addition, I'll leave command in there too, remove the others.

@@ -32,6 +32,10 @@ resource "azurerm_container_group" "aci-helloworld" {
cpu ="0.5"
memory = "1.5"
port = "80"
env_vars {
"env"="staging"
Copy link
Contributor

Choose a reason for hiding this comment

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

it might sound odd, but in this current example the Environment Variable looks very similar to Tags (which we normally use "Environment" = "Staging" as an example) - as such would it make more sense to make this "NODE_ENV" = "Staging"?

Copy link
Author

Choose a reason for hiding this comment

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

I made them the same intentionally, but this change is fine.

@@ -108,25 +108,16 @@ func resourceArmContainerGroup() *schema.Resource {
}, true),
},

"env_var": {
Type: schema.TypeList,
"env_vars": {
Copy link
Contributor

Choose a reason for hiding this comment

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

is it worth making this environment_variables?

Copy link
Author

Choose a reason for hiding this comment

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

Done. Also matches with the CLI.

Type: schema.TypeList,
"env_vars": {
Type: schema.TypeMap,
Optional: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

be aware, if we'd done a release of this, we'd have to include a State Migration to handle converting between the two fields going from a TypeList -> TypeMap - but I think we can probably overlook that this time since this hasn't been released yet

Copy link
Author

Choose a reason for hiding this comment

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

👍

@tombuildsstuff
Copy link
Contributor

@abhijeetgaiha sorry, messed up git again (I think it's pushing to a remote master branch which is breaking things) - I've opened #338 which includes this.

@ghost
Copy link

ghost commented Apr 1, 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 Apr 1, 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.

2 participants