简体   繁体   中英

How to reuse data from a resource in Terraform?

I want to reuse the string from addresses in dns_aaaa_record_set in dns_ptr_record, how?

resource "dns_aaaa_record_set" "app-stage-dns" {
  count     = length(var.datacenter)
  zone      = format("%s.", var.dns_zone)
  name      = "app-stage-${var.datacenter[count.index]}.mydomain"
  addresses = [replace(openstack_compute_instance_v2.app-stage[count.index].access_ip_v6, "/\\[|\\]/", "")]
  ttl       = 300
}

resource "dns_ptr_record" "app-stage-dns-ptr" {
  count = length(var.datacenter)
  zone  = format("%s.", var.dns_ptr_zone)
  ptr   = "app-stage-${var.datacenter[count.index]}.mydomain"
  name  = <dns_aaaa_record_set[addresses]>
  ttl   = 300
}

Generally you could do the following:

resource "dns_ptr_record" "app-stage-dns-ptr" {
  count = length(var.datacenter)
  zone  = format("%s.", var.dns_ptr_zone)
  ptr   = "app-stage-${var.datacenter[count.index]}.mydomain"
  name  = dns_aaaa_record_set.app-stage-dns[count.index].addresses[0]
  ttl   = 300
}

You have to be careful about name . addresses in your dns_aaaa_record_set is a list, and name must be only a string, not list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM