diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index 1203b1aba2c3..b916174f589a 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -73,6 +73,17 @@ func resourceArmContainerGroup() *schema.Resource { Computed: true, }, + "fqdn": { + Type: schema.TypeString, + Computed: true, + }, + + "dns_name_label": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "container": { Type: schema.TypeList, Required: true, @@ -216,6 +227,10 @@ func resourceArmContainerGroupCreate(d *schema.ResourceData, meta interface{}) e }, } + if dnsNameLabel := d.Get("dns_name_label").(string); dnsNameLabel != "" { + containerGroup.ContainerGroupProperties.IPAddress.DNSNameLabel = &dnsNameLabel + } + _, err := containerGroupsClient.CreateOrUpdate(ctx, resGroup, name, containerGroup) if err != nil { return err @@ -268,6 +283,8 @@ func resourceArmContainerGroupRead(d *schema.ResourceData, meta interface{}) err if address := resp.IPAddress; address != nil { d.Set("ip_address_type", address.Type) d.Set("ip_address", address.IP) + d.Set("dns_name_label", address.DNSNameLabel) + d.Set("fqdn", address.Fqdn) } d.Set("restart_policy", string(resp.RestartPolicy)) diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index b2007809f282..5b9e655e6e98 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -253,6 +253,7 @@ resource "azurerm_container_group" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" ip_address_type = "public" + dns_name_label = "acctestcontainergroup-%d" os_type = "windows" restart_policy = "Never" @@ -262,8 +263,9 @@ resource "azurerm_container_group" "test" { cpu = "2.0" memory = "3.5" port = "80" + environment_variables { - "foo" = "bar" + "foo" = "bar" "foo1" = "bar1" } command = "cmd.exe echo hi" @@ -273,7 +275,7 @@ resource "azurerm_container_group" "test" { environment = "Testing" } } -`, ri, location, ri) +`, ri, location, ri, ri) } func testAccAzureRMContainerGroup_linuxComplete(ri int, location string) string { @@ -305,6 +307,7 @@ resource "azurerm_container_group" "test" { location = "${azurerm_resource_group.test.location}" resource_group_name = "${azurerm_resource_group.test.name}" ip_address_type = "public" + dns_name_label = "acctestcontainergroup-%d" os_type = "linux" restart_policy = "OnFailure" @@ -313,14 +316,16 @@ resource "azurerm_container_group" "test" { image = "seanmckenna/aci-hellofiles" cpu = "1" memory = "1.5" - port = "80" + + port = "80" protocol = "TCP" volume { - name = "logs" + name = "logs" mount_path = "/aci/logs" - read_only = false + read_only = false share_name = "${azurerm_storage_share.test.name}" + storage_account_name = "${azurerm_storage_account.test.name}" storage_account_key = "${azurerm_storage_account.test.primary_access_key}" } @@ -337,7 +342,7 @@ resource "azurerm_container_group" "test" { environment = "Testing" } } -`, ri, location, ri, ri, ri) +`, ri, location, ri, ri, ri, ri) } func testCheckAzureRMContainerGroupExists(name string) resource.TestCheckFunc { diff --git a/examples/aci-linux-multi/main.tf b/examples/aci-linux-multi/main.tf index fb1903209c3e..ae735c2bb023 100644 --- a/examples/aci-linux-multi/main.tf +++ b/examples/aci-linux-multi/main.tf @@ -1,30 +1,38 @@ resource "azurerm_resource_group" "aci-rg" { - name="aci-test" - location="west us" + name = "${var.resource_group_name}" + location = "${var.resource_group_location}" } -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" +#an attempt to keep the aci container group name (an dns label) somewhat omunique +resource "random_integer" "random_int" { + min = 100 + max = 999 +} + +resource "azurerm_container_group" "aci-example" { + name = "my-aci-cg-${random_integer.random_int.result}" + location = "${azurerm_resource_group.aci-rg.location}" + resource_group_name = "${azurerm_resource_group.aci-rg.name}" + ip_address_type = "public" + dns_name_label = "my-aci-cg-${random_integer.random_int.result}" + os_type = "linux" container { - name = "hw" - image = "microsoft/aci-helloworld:latest" - cpu ="0.5" - memory = "1.5" - port = "80" + 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" + name = "sidecar" + image = "microsoft/aci-tutorial-sidecar" + cpu = "0.5" + memory = "1.5" } + tags { environment = "testing" } } - diff --git a/examples/aci-linux-multi/outputs.tf b/examples/aci-linux-multi/outputs.tf new file mode 100644 index 000000000000..45ff1b4614ed --- /dev/null +++ b/examples/aci-linux-multi/outputs.tf @@ -0,0 +1,9 @@ + +output "ip_address" { + value = "${azurerm_container_group.aci-example.ip_address}" +} + +#the dns fqdn of the container group if dns_name_label is set +output "fqdn" { + value = "${azurerm_container_group.aci-example.fqdn}" +} \ No newline at end of file diff --git a/examples/aci-linux-multi/variables.tf b/examples/aci-linux-multi/variables.tf new file mode 100644 index 000000000000..a4e4a7df9a9e --- /dev/null +++ b/examples/aci-linux-multi/variables.tf @@ -0,0 +1,11 @@ +variable "resource_group_name" { + type = "string" + description = "Name of the azure resource group." + default = "aci-test" +} + +variable "resource_group_location" { + type = "string" + description = "Location of the azure resource group." + default = "westus" +} diff --git a/examples/aci-linux-volume-mount/main.tf b/examples/aci-linux-volume-mount/main.tf index 3c3af380eab5..738a0c85ae0c 100644 --- a/examples/aci-linux-volume-mount/main.tf +++ b/examples/aci-linux-volume-mount/main.tf @@ -1,14 +1,20 @@ resource "azurerm_resource_group" "aci-rg" { - name = "aci-test" - location = "west us" + name = "${var.resource_group_name}" + location = "${var.resource_group_location}" +} + +#storage account name needs to be globally unique so lets generate a random id +resource "random_integer" "random_int" { + min = 100 + max = 999 } resource "azurerm_storage_account" "aci-sa" { - name = "acistorageacct" - resource_group_name = "${azurerm_resource_group.aci-rg.name}" - location = "${azurerm_resource_group.aci-rg.location}" - account_tier = "Standard" - account_replication_type = "LRS" + name = "acistorageacct${random_integer.random_int.result}" + resource_group_name = "${azurerm_resource_group.aci-rg.name}" + location = "${azurerm_resource_group.aci-rg.location}" + account_tier = "Standard" + account_replication_type = "LRS" } resource "azurerm_storage_share" "aci-share" { @@ -20,31 +26,34 @@ resource "azurerm_storage_share" "aci-share" { quota = 50 } -resource "azurerm_container_group" "myhw" { +resource "azurerm_container_group" "aci-example" { - name = "mycontainergroup" - location = "${azurerm_resource_group.aci-rg.location}" + name = "mycontainergroup-${random_integer.random_int.result}" + location = "${azurerm_resource_group.aci-rg.location}" resource_group_name = "${azurerm_resource_group.aci-rg.name}" - ip_address_type="public" - os_type = "linux" + ip_address_type = "public" + dns_name_label = "mycontainergroup-${random_integer.random_int.result}" + os_type = "linux" container { - name = "webserver" - image = "seanmckenna/aci-hellofiles" - cpu ="1" - memory = "1.5" - port = "80" - protocol = "tcp" + name = "webserver" + image = "seanmckenna/aci-hellofiles" + cpu = "1" + memory = "1.5" + port = "80" + protocol = "tcp" volume { - name = "logs" - mount_path = "/aci/logs" - read_only = false - share_name = "${azurerm_storage_share.aci-share.name}" - storage_account_name = "${azurerm_storage_account.aci-sa.name}" - storage_account_key = "${azurerm_storage_account.aci-sa.primary_access_key}" + name = "logs" + mount_path = "/aci/logs" + read_only = false + share_name = "${azurerm_storage_share.aci-share.name}" + + storage_account_name = "${azurerm_storage_account.aci-sa.name}" + storage_account_key = "${azurerm_storage_account.aci-sa.primary_access_key}" } } + tags { environment = "testing" } diff --git a/examples/aci-linux-volume-mount/outputs.tf b/examples/aci-linux-volume-mount/outputs.tf new file mode 100644 index 000000000000..45ff1b4614ed --- /dev/null +++ b/examples/aci-linux-volume-mount/outputs.tf @@ -0,0 +1,9 @@ + +output "ip_address" { + value = "${azurerm_container_group.aci-example.ip_address}" +} + +#the dns fqdn of the container group if dns_name_label is set +output "fqdn" { + value = "${azurerm_container_group.aci-example.fqdn}" +} \ No newline at end of file diff --git a/examples/aci-linux-volume-mount/variables.tf b/examples/aci-linux-volume-mount/variables.tf new file mode 100644 index 000000000000..a4e4a7df9a9e --- /dev/null +++ b/examples/aci-linux-volume-mount/variables.tf @@ -0,0 +1,11 @@ +variable "resource_group_name" { + type = "string" + description = "Name of the azure resource group." + default = "aci-test" +} + +variable "resource_group_location" { + type = "string" + description = "Location of the azure resource group." + default = "westus" +} diff --git a/website/docs/r/container_group.html.markdown b/website/docs/r/container_group.html.markdown index accd835f7158..77760911e9e2 100644 --- a/website/docs/r/container_group.html.markdown +++ b/website/docs/r/container_group.html.markdown @@ -23,6 +23,7 @@ resource "azurerm_storage_account" "aci-sa" { resource_group_name = "${azurerm_resource_group.aci-rg.name}" location = "${azurerm_resource_group.aci-rg.location}" account_tier = "Standard" + account_replication_type = "LRS" } @@ -40,28 +41,30 @@ resource "azurerm_container_group" "aci-helloworld" { location = "${azurerm_resource_group.aci-rg.location}" resource_group_name = "${azurerm_resource_group.aci-rg.name}" ip_address_type = "public" + dns_label_name = "aci-label" os_type = "linux" container { - name = "hw" - image = "seanmckenna/aci-hellofiles" - cpu ="0.5" + name = "hw" + image = "seanmckenna/aci-hellofiles" + cpu ="0.5" memory = "1.5" - port = "80" + port = "80" environment_variables { - "NODE_ENV"="testing" + "NODE_ENV" = "testing" } command = "/bin/bash -c '/path to/myscript.sh'" volume { - name = "logs" + name = "logs" mount_path = "/aci/logs" - read_only = false + read_only = false share_name = "${azurerm_storage_share.aci-share.name}" - storage_account_name = "${azurerm_storage_account.aci-sa.name}" - storage_account_key = "${azurerm_storage_account.aci-sa.primary_access_key}" + + storage_account_name = "${azurerm_storage_account.aci-sa.name}" + storage_account_key = "${azurerm_storage_account.aci-sa.primary_access_key}" } } @@ -90,6 +93,8 @@ The following arguments are supported: * `ip_address_type` - (Optional) Specifies the ip address type of the container. `Public` is the only acceptable value at this time. Changing this forces a new resource to be created. +* `dns_label_name` - (Optional) The DNS label/name for the container groups IP. + * `os_type` - (Required) The OS for the container group. Allowed values are `Linux` and `Windows`. Changing this forces a new resource to be created. * `restart_policy` - (Optional) Restart policy for the container group. Allowed values are `Always`, `Never`, `OnFailure`. Defaults to `Always`. @@ -137,3 +142,5 @@ The following attributes are exported: * `id` - The container group ID. * `ip_address` - The IP address allocated to the container group. + +* `fqdn` - The FQDN of the container group derived from `dns_name_label`.