【发布时间】:2019-10-16 19:05:11
【问题描述】:
我正在尝试使用 aws_instance 数据源。我创建了一个简单的配置,它应该创建一个 ec2 实例并返回 ip 作为输出
variable "default_port" {
type = string
default = 8080
}
provider "aws" {
region = "us-west-2"
shared_credentials_file = "/Users/kharandziuk/.aws/creds"
profile = "prototyper"
}
resource "aws_instance" "example" {
ami = "ami-0994c095691a46fb5"
instance_type = "t2.small"
tags = {
name = "example"
}
}
data "aws_instances" "test" {
instance_tags = {
name = "example"
}
instance_state_names = ["pending", "running", "shutting-down", "terminated", "stopping", "stopped"]
}
output "ip" {
value = data.aws_instances.test.public_ips
}
但由于某些原因,我无法正确配置数据源。结果是:
> terraform plan
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_instances.test: Refreshing state...
Error: Your query returned no results. Please change your search criteria and try again.
on main.tf line 21, in data "aws_instances" "test":
21: data "aws_instances" "test" {
我该如何解决?
【问题讨论】:
-
通常使用资源导出属性来处理。您可以将您的
output值更新为aws_instance.example.public_ip并删除您的数据以修复和优化此问题。
标签: amazon-web-services terraform terraform-provider-aws