I'm trying to create a basic terraform script to spin up an ec2 on aws. For time being. I'm using local-exec
provisioner. The script looks like this.
provider "aws" {
profile = "default"
region = "eu-central-1"
version = "2.53"
}
resource "aws_instance" "gsb_ec2" {
ami = "ami-0b418580298265d5c"
instance_type = "t2.micro"
provisioner "local-exec" {
command = "echo ${aws_instance.gsb_ec2.public_ip} > ip_address.txt"
}
provisioner "local-exec" {
command = "echo ${aws_instance.gsb_ec2.public_ip} > ip_address.txt"
}
}
I want to echo provider region
just like I'm echoing aws instance public ip.
I'm getting following error because provider is not a resource obviously.
Error: Reference to undeclared resource
So, how do I access provider attributes?
Thanks