我正在尝试创建一个基本的Terraform脚本,以在AWS上启动ec2。暂时的。我正在使用local-exec
预配器。脚本看起来像这样。
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"
}
}
我想回显provider region
,就像我在回响aws实例的公共IP。
我收到以下错误消息,因为提供者显然不是资源。
Error: Reference to undeclared resource
那么,如何访问提供者属性?
谢谢
答案 0 :(得分:1)
您需要使用数据组件来get to the current region:
data "aws_region" "current" {}
然后您可以回显data.aws_region.current.name