Terraform错误“您的查询未返回结果" [英] Terraform error "Your query returned no results"
问题描述
我在bom-asg.tf文件下面.
I have below bom-asg.tf file.
data "aws_ami" "bom-ami" {
most_recent = true
filter {
name = "tag:ami_name"
values = ["${var.environment}-bom-ami"]
}
owners = ["****"]
}
resource "aws_security_group" "bom-sg" {
name_prefix = "${var.environment}-bom-asg-sg"
vpc_id = "${var.vpc_id}"
.....
我无法成功执行刷新和计划命令.我遇到了错误.
I am unable to successfully execute refresh and plan commands. I am getting below errors.
terraform plan --var-file=environment-parity.tfvars -target=bom-asg.tf --out apply.out
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.
------------------------------------------------------------------------
No changes. Infrastructure is up-to-date.
This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.
但是当我运行刷新时.我遇到错误了.
But when I run refresh. I am getting below error.
terraform refresh --var-file=environment-parity.tfvars
data.template_file.es_access_policy_search: Refreshing state...
data.aws_ami.nginx-ami: Refreshing state...
data.aws_ami.php-search-ami: Refreshing state...
data.aws_ami.ng-ami: Refreshing state...
data.aws_ami.mysql-ami: Refreshing state...
data.aws_ami.frontend-search-ami: Refreshing state...
data.aws_ami.bom-ami: Refreshing state...
data.aws_ami.lg-ami: Refreshing state...
data.aws_ami.rabbitmq-search-ami: Refreshing state...
data.aws_ami.ngas-ng-drupal-ami: Refreshing state...
data.aws_ami.mongodb-ami: Refreshing state...
Error: Error refreshing state: 1 error(s) occurred:
* data.aws_ami.bom-ami: 1 error(s) occurred:
* data.aws_ami.bom-ami: data.aws_ami.bom-ami: Your query returned no results. Please change your search criteria and try again.
可以帮忙吗?
推荐答案
Terraform 数据源是访问现有资源,而不是创建资源.
Terraform data source is to access an existing resource, not to create one.
data "aws_ami" "bom-ami"
与文档中一样,AMI必须已经存在.
As in the documentation, the AMI needs to exist already.
使用此数据源获取已注册 AMI的ID,以在其他资源中使用.
Use this data source to get the ID of a registered AMI for use in other resources.
如果要通过从EC2实例(例如Amazon Linux EC2)获取的EBS快照创建AMI,则:
If you are creating an AMI from an EBS snapshot taken from an EC2 instance (e.g. Amazon Linux EC2), then:
请注意数据和资源之间的区别.
要创建自定义AMI图像,还请考虑 Hashicorp包装器
To create a custom AMI image, please also consider Hashicorp packer.
这篇关于Terraform错误“您的查询未返回结果"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!