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

azurerm_container_group - Support of dns_config #7912

Merged
merged 16 commits into from
Sep 27, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
75 changes: 75 additions & 0 deletions azurerm/internal/services/containers/container_group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,37 @@ func resourceArmContainerGroup() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"dns_config": {
Optional: true,
MaxItems: 1,
ForceNew: true,
Type: schema.TypeList,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"nameservers": {
Type: schema.TypeList,
Required: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"search_domains": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"options": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -468,6 +499,7 @@ func resourceArmContainerGroupCreate(d *schema.ResourceData, meta interface{}) e
OsType: containerinstance.OperatingSystemTypes(OSType),
Volumes: containerGroupVolumes,
ImageRegistryCredentials: expandContainerImageRegistryCredentials(d),
DNSConfig: expandContainerGroupDnsConfig(d),
},
}

Expand Down Expand Up @@ -562,6 +594,7 @@ func resourceArmContainerGroupRead(d *schema.ResourceData, meta interface{}) err

d.Set("restart_policy", string(props.RestartPolicy))
d.Set("os_type", string(props.OsType))
d.Set("dns_config", flattenContainerGroupDnsConfig(resp.DNSConfig))

if err := d.Set("diagnostics", flattenContainerGroupDiagnostics(d, props.Diagnostics)); err != nil {
return fmt.Errorf("Error setting `diagnostics`: %+v", err)
Expand Down Expand Up @@ -1375,3 +1408,45 @@ func resourceArmContainerGroupPortsHash(v interface{}) int {

return hashcode.String(buf.String())
}

func flattenContainerGroupDnsConfig(input *containerinstance.DNSConfiguration) []interface{} {
if input == nil {
return nil
}
outputArr := make([]interface{}, 1)
output := make(map[string]interface{})

if v := input.SearchDomains; v != nil {
output["search_domains"] = *v
}
if v := input.Options; v != nil {
output["options"] = *v
}
if v := input.NameServers; v != nil {
output["nameservers"] = *v
}

outputArr = append(outputArr, output)
return outputArr
}

func expandContainerGroupDnsConfig(d *schema.ResourceData) *containerinstance.DNSConfiguration {
configRaw := d.Get("dns_config").([]interface{})
if len(configRaw) == 0 {
return nil
}
config := configRaw[0].(map[string]interface{})

ns := []string{}
for _, v := range config["nameservers"].([]interface{}) {
ns = append(ns, v.(string))
}

dnsConfig := &containerinstance.DNSConfiguration{
Options: utils.String(config["options"].(string)),
SearchDomains: utils.String(config["search_domains"].(string)),
NameServers: &ns,
}

return dnsConfig
}
9 changes: 9 additions & 0 deletions website/docs/r/container_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ The following arguments are supported:
~> **Note:** if `os_type` is set to `Windows` currently only a single `container` block is supported. Windows containers are not supported in virtual networks.

---
* `dns_config` - (Optional) A `dns_config` block as documented below.

* `diagnostics` - (Optional) A `diagnostics` block as documented below.

Expand Down Expand Up @@ -239,6 +240,14 @@ The `http_get` block supports:

* `scheme` - (Optional) Scheme to use for connecting to the host. Possible values are `Http` and `Https`. Changing this forces a new resource to be created.

---

The `dns_config` block supports:

* `nameservers` (Required) A list of nameservers (IPv4 format) for the container to search out to resolve requests
* `search_domains` (Required) A string that represents the search domains that DNS requests will search along
* `options` (Required) `ex: ndots:2` A string representing the number of domains to search above the current `search_domains` field

## Attributes Reference

The following attributes are exported:
Expand Down