hashicorp/terraform

azurerm_dns_srv_record should support dynamic count or list of targets

Closed this issue · 2 comments

hh commented

Terraform Version

0.9.2 / current stable

Affected Resource(s)

  • azurerm_dns_srv_record

Terraform Configuration Files

Creating A records via azurerm_dns_a_record with count of 3 results in multiple records:

resource "azurerm_dns_a_record" "A-point-to-three-ips" {
  name = "mynodes"
  zone_name = "myzone"
  resource_group_name = "mygroup"
  ttl = "300"
  # records = [ "${ var.mynode-ips }" ]
  # aka:
  records = [
    "10.10.10.1",
    "10.10.10.2",
    "10.10.10.3"
  ]
}

When we query the A record the DNS server for the zone responds with the IP list:

mynodes.myzone => [ 10.10.10.1, 10.10.10.2, 10.10.10.3]

In order to have a single SRV record with a multiple entries we should somehow programatically provide azurerm_dns_srv_record with a list.

We tried count with SRV records, but this results in a single record due to the SRV name not changing, and only a single record/entry is created. (the last one in the loop)

resource "azurerm_dns_srv_record" "SRV-point-to-three-records" {
  name = "_mysrv._tcp"
  zone_name = "myzone"
  resource_group_name = "mygroup}"
  ttl = "300"
  count = "3"

  record {
    priority = 0
    weight = 0
    port = 2379
    target = "srv${count.index}.myzone"
  }
}

Using dig at this point for _mysrv._tcp.myzone results in only one record.

_mysrv._tcp.myzone => [ srv3.myzone ]

We should support a list for record targets or support count within the record definition:

resource "azurerm_dns_srv_record" "SRV-count-to-three" {
  name = "_mysrv._tcp"
  zone_name = "myzone"
  resource_group_name = "mygroup}"
  ttl = "300"

  records {
    priority = 0
    weight = 0
    port = 2379

    ### we could support count here
    count = 3
    ### and use count in target
    target = "srv${count.index}.mytld"


    #### or we support a list via targets
    targets = [
       "srv1.mytld",
       "srv2.mytld",
       "srv3.mytld"
    ]
  }
}

Expected Behavior

To provision SRV records for high service availability we need to add multiple records per azurerm_dns_srv_record pointing to dynamic VMs using count or supplying a list of targets.

_mysrv._tcp.myzone => [ srv1.myzone, srv2.myzone, srv3.myzone ]

Actual Behavior

When using count, only one SRV record survives pointing to the last one looped through.

_mysrv._tcp.myzone => [ srv3.myzone ]

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Use the SRV-point-to-three-records hcl tf config
  2. terraform apply
  3. dig @azure-dns-server-for-zone-ip _mysrv._tcp.myzone will return a single entry
hh commented

This is needed for dynamic etcd master SRV entries for the cncf/demo#126

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.