-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Conversation
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.
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 |
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.
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?
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.
Done.
@@ -265,12 +259,33 @@ func flattenContainerGroupContainers(containers *[]containerinstance.Container) | |||
} | |||
// protocol isn't returned in container config | |||
|
|||
if len(*container.EnvironmentVariables) > 0 { |
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.
this'll crash if container.EnvironmentVariables
is nil - could we add an if statement around this?
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.
It's never nil, but a check is warranted to be safe. Done.
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.
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"), |
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'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?
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.
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" |
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.
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"
?
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 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": { |
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.
is it worth making this environment_variables
?
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.
Done. Also matches with the CLI.
Type: schema.TypeList, | ||
"env_vars": { | ||
Type: schema.TypeMap, | ||
Optional: true, |
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.
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
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.
👍
d17f014
to
59d9025
Compare
@abhijeetgaiha sorry, messed up git again (I think it's pushing to a remote |
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! |
More progress on #287