简体   繁体   English

多个 EC2 实例匹配; 使用额外的约束来减少对单个 EC2 实例的匹配

[英]multiple EC2 Instances matched; use additional constraints to reduce matches to a single EC2 Instance

I am using the following script to query a particular instance.我正在使用以下脚本来查询特定实例。 There will be only one running instance with the given name.将只有一个具有给定名称的正在运行的实例。 It is possible that another instance with the same name may exists but in different instance state.可能存在另一个具有相同名称的实例,但在不同的实例 state 中。

How do I filter instance on instance's state so it only retrieves instance that is running state?如何在实例的 state 上过滤实例,以便它只检索正在运行的实例 state?

data "aws_instance" "ec2" {
  filter {
    name   = "tag:Name"
    values = ["dev-us-west-2-myinstance"]
  } 
}

Currently I get the following error目前我收到以下错误

multiple EC2 Instances matched;多个 EC2 实例匹配; use additional constraints to reduce matches to a single EC2 Instance使用额外的约束来减少对单个 EC2 实例的匹配

The terraform documentation , links to the AWS documentation for the describe-instances filter. terraform 文档链接到describe-instances过滤器的 AWS 文档

That documentation indicates you should do the following:该文档指示您应该执行以下操作:

data "aws_instance" "ec2" {
  filter {
    name   = "tag:Name"
    values = ["dev-us-west-2-myinstance"]
  } 

  filter {
    name   = "instance-state-name"
    values = ["running"]
  } 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM