3
votes

I was trying to do

terraform apply

but getting below error

1 error(s) occurred:

  • digitalocean_droplet.testvm[0]: Resource 'digitalocean_droplet.testvm' not found for variable 'digitalocean_droplet.testvm.ipv4_address'

Terraform does not automatically rollback in the face of errors. Instead, your Terraform state file has been partially updated with any resources that successfully completed. Please address the error above and apply again to incrementally change your infrastructure.

How can I pass the public ip of the created droplet to provisioner local-exec command.

Below is my .tf file

provider "digitalocean" {
  token = "----TOKEN----"
}

resource "digitalocean_droplet" "testvm" {
    count = "10"
    name = "do-instance-${count.index}"
    image = "ubuntu-16-04-x64"
    size = "512mb"
    region = "nyc3"
    ipv6 = true
    private_networking = false
    ssh_keys = [
      "----SSH KEY----"
    ]
    provisioner "local-exec" {
        command = "fab production deploy ${digitalocean_droplet.testvm.ipv4_address}"
    }
}

Thanks in advance!

1

1 Answers

2
votes

For local-exec provisioner you can make use of the self keyword. In this case it would be {self.ipv4_address}.

My guess is that your snippet would've worked if you don't put count=10 in the testvm droplet. You can also make use of ${count.index}

More info: https://www.terraform.io/docs/provisioners/

Also, found this github issue that might be helpful to you.

Hope it helps