我有地形问题。我想像显示可用性区域一样显示输出。我有两个EC2实例和一个数据源,可以通过filter参数获取其中一个实例的可用性区域之类的详细信息,并将结果转发到输出,但我得到了一个错误。
Main.tf
resource "aws_instance" "ec2-1"{
ami="ami-0a54aef4ef3b5f881"
instance_type="t2.micro"
tags={
Name="Instance-1"
}
depends_on=[aws_instance.ec2-2]
}
resource "aws_instance" "ec2-2"{
ami="ami-026dea5602e368e96"
instance_type="t2.micro"
tags={
Name="Instance-2"
}
}
data "aws_instance" "instancesearch"{
filter {
name="tag:Name"
values=["Instance-2"]
}
}
output "instanceid"{
value = data.aws_instance.instancesearch.availability_zone
}terraform plan result:
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
data.aws_instance.instancesearch: Refreshing state...
Error: Your query returned no results. Please change your search criteria and try again.
on main.tf line 19, in data "aws_instance" "instancesearch":
19: data "aws_instance" "instancesearch"{ 发布于 2020-06-26 22:05:00
您不需要使用单独的数据源来获取可用性区域。您可以将其作为资源本身的属性。试试这个:
output "availability_zone" {
value = aws_instance.ec2-2.availability_zone
}https://stackoverflow.com/questions/62601615
复制相似问题