Terraform 错误“您的查询未返回任何结果"; [英] Terraform error "Your query returned no results"

查看:11
本文介绍了Terraform 错误“您的查询未返回任何结果";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 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:

请注意dataresource之间的区别.

要创建自定义 AMI 映像,还请考虑 Hashicorp 打包程序.

To create a custom AMI image, please also consider Hashicorp packer.

这篇关于Terraform 错误“您的查询未返回任何结果";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆