Can't get Terraform instance IP address after create

484 Views Asked by At

Utilizng Vultr's terraform provider, I'm creating a few instances of machines. All is great, except I'm now trying to create cloudflare records (subdomains pointing to each new machine respectively) for these machines that are being spawned by terraform.

vultr_instance


resource "vultr_instance" "test" {
  label              = "test"
  region = "dfw"
  plan = "vc2-2c-4gb"
  os_id             = "413" # ubuntu 20.10
  # https://api.vultr.com/v1/os/list
  hostname          = "test"
}

dns record

  zone_id = var.cloudflare_zone_id
  name    = "test"
  #value   = "192.168.0.11"
  value = test.main_ip
  type    = "A"
  ttl     = 3600
}

Per the vultr provider docs, it exports main_ip which is the ip of the machine after being spawned, however terraform won't let me simply call main_ip as a variable

Error: Reference to undeclared resource

  on vultr.tf line 33, in resource "cloudflare_record" "test_dns":
  33:   value = test.main_ip

A managed resource "test" "main_ip" has not been declared in the root
module.

main_ip in vultr provider docs

Trying to get this into 1 tf file if possible, however anyway to get this to work would be amazing

0

There are 0 best solutions below