provider "aws" {
access_key = "ACCESS_KEY_HERE"
secret_key = "SECRET_KEY_HERE"
region = "us-east-1"
}
resource "aws_instance" "example" {
ami = "ami-0d729a60"
instance_type = "t2.micro"
provisioner "local-exec" {
command = "echo ${aws_instance.example.public_ip} > file.txt"
}
}
resource "aws_eip" "ip" {
instance = "${aws_instance.example.id}"
depends_on = ["aws_instance.example"]
}
Because of the above order, I think "aws_instance.example.public_ip" variable has not been computed at the time of "local-exec" provisioner is executed. However, it turns out this script is working.
Can someone help me to understand how that worked out?
command = "echo ${aws_eip.eip.public_ip} > file.txt"
}
provisioner "local-exec" {
command = "echo ${aws_instance.example.public_ip} > file.txt"
}