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

ACI: Add support for Volume mounts #366

Merged
merged 23 commits into from
Oct 5, 2017

Conversation

abhijeetgaiha
Copy link

Added support for Volume mounts in Azure container groups.

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 and have left a few comments but this mostly LGTM :)

Thanks!

@@ -206,7 +253,7 @@ func resourceArmContainerGroupRead(d *schema.ResourceData, meta interface{}) err
d.Set("ip_address", address.IP)
}

containerConfigs := flattenContainerGroupContainers(resp.Containers)
containerConfigs := flattenContainerGroupContainers(d, resp.Containers, resp.ContainerGroupProperties.IPAddress.Ports, resp.ContainerGroupProperties.Volumes)
Copy link
Contributor

Choose a reason for hiding this comment

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

if resp.ContainerGroupProperties is nil (e.g. Swagger/API spec changes), there's a possibility for a crash here - could we instead wrap this via:

if props := resp.ContainerGroupProperties; props != nil {
  containerConfigs := flattenContainerGroupContainers(d, resp.Containers, props.IPAddress.Ports, props.Volumes)
  # ...

}

Copy link
Author

Choose a reason for hiding this comment

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

Done.

containerConfig["port"] = containerPort
// protocol isn't returned in container config, have to search in container group ports
protocol := ""
for _, cgPort := range *containerGroupPorts {
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need a check to ensure this isn't nil?

Copy link
Author

Choose a reason for hiding this comment

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

Done.

},
}

*containerGroupVolumes = append(*containerGroupVolumes, cv)
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 argue this would be clearer if we instead returned multiple objects from this method, rather than appending to the input argument i.e.

func foo(bar string) (*[]containerinstance.Volume, *[]containerinstance.VolumeMount) {
  return volumes, volumeMounts
}

Copy link
Author

Choose a reason for hiding this comment

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

It has to be this way since the containerGroupVolumes is a collection of all volumes across all containers.

Copy link
Contributor

Choose a reason for hiding this comment

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

Reading the code above, it takes understanding of the inner working of the method to know that both a value passed in will be modified, and a return value will come out - in general methods tend to do one or the other (and I'd argue the latter is easier to understand). We should be able to achieve the same thing by returning the value and then setting it - for instance:

func foo() {
  containerGroupVolumes := make([]containerinstance.Volume, 0)
  
  for i := 0; i < 9; i++ {
    mounts, containerGroupVolumes := expandContainerVolumes(interface{}, &containerGroupVolumes)
    // mounts is local
    // containerGroupVolumes is appended too
  }
}

func expandContainerVolumes(input interface{}, containerGroupVolumes *[]containerinstance.Volume) (*[]containerinstance.VolumeMount, containerGroupVolumes *[]containerinstance.Volume) {
  mounts := make([]containerinstance.VolumeMount, 0)
  volumes := *containerGroupVolumes
  volumes = append(volumes, ...)
  return &mounts, &volumes
}

Copy link
Author

Choose a reason for hiding this comment

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

Done.

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.

really minor could we normalise the formatting this?

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@@ -86,6 +111,22 @@ The `container` block supports:

* `command` - (Optional) A command line to be run on the container. Changing this forces a new resource to be created.

* `volume` - (Optional) The definition of a volume mount for this container. Changing this forces a new resource to be created.
Copy link
Contributor

Choose a reason for hiding this comment

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

The definition of a volume mount for this container

could we suffix this with "as documented in the volume block below"?

Copy link
Author

Choose a reason for hiding this comment

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

Done.

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.

Hi @abhijeetgaiha

Thanks for the continued effort on this - I've taken another look through and this LGTM.

Tests pass:

$ acctests azurerm TestAccAzureRMContainerGroup
=== RUN   TestAccAzureRMContainerGroup_linuxBasic
--- PASS: TestAccAzureRMContainerGroup_linuxBasic (62.53s)
=== RUN   TestAccAzureRMContainerGroup_linuxBasicUpdate
--- PASS: TestAccAzureRMContainerGroup_linuxBasicUpdate (71.28s)
=== RUN   TestAccAzureRMContainerGroup_linuxComplete
--- PASS: TestAccAzureRMContainerGroup_linuxComplete (88.78s)
=== RUN   TestAccAzureRMContainerGroup_windowsBasic
--- PASS: TestAccAzureRMContainerGroup_windowsBasic (60.53s)
=== RUN   TestAccAzureRMContainerGroup_windowsComplete
--- PASS: TestAccAzureRMContainerGroup_windowsComplete (58.66s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	341.800s

Thanks!

@tombuildsstuff tombuildsstuff merged commit 29f7276 into hashicorp:master Oct 5, 2017
tombuildsstuff added a commit that referenced this pull request Oct 5, 2017
@abhijeetgaiha abhijeetgaiha deleted the master branch October 5, 2017 08:36
@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 👉 [email protected]. 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