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

Added dns_name_label and FQDN properties to container group resource. #877

Merged
merged 1 commit into from
Feb 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions azurerm/resource_arm_container_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down
17 changes: 11 additions & 6 deletions azurerm/resource_arm_container_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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"

Expand All @@ -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}"
}
Expand All @@ -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 {
Expand Down
44 changes: 26 additions & 18 deletions examples/aci-linux-multi/main.tf
Original file line number Diff line number Diff line change
@@ -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"
}
}

9 changes: 9 additions & 0 deletions examples/aci-linux-multi/outputs.tf
Original file line number Diff line number Diff line change
@@ -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}"
}
11 changes: 11 additions & 0 deletions examples/aci-linux-multi/variables.tf
Original file line number Diff line number Diff line change
@@ -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"
}
57 changes: 33 additions & 24 deletions examples/aci-linux-volume-mount/main.tf
Original file line number Diff line number Diff line change
@@ -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" {
Expand All @@ -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"
}
Expand Down
9 changes: 9 additions & 0 deletions examples/aci-linux-volume-mount/outputs.tf
Original file line number Diff line number Diff line change
@@ -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}"
}
11 changes: 11 additions & 0 deletions examples/aci-linux-volume-mount/variables.tf
Original file line number Diff line number Diff line change
@@ -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"
}
25 changes: 16 additions & 9 deletions website/docs/r/container_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -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}"
}
}

Expand Down Expand Up @@ -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`.
Expand Down Expand Up @@ -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`.