简体   繁体   English

使用名称标签对资源进行地形导入

[英]terraform import using name tag for the resource

I am trying to import the existing resources into Terraform state. 我正在尝试将现有资源导入Terraform状态。 But I want to automate the import along with a terraform resource creation script. 但我想自动执行导入以及Terraform资源创建脚本。

I am creating a ELB and 2 instances in existing VPC, so first I have to import the existing VPC into my state file by using the name tag of the VPC. 我正在现有VPC中创建一个ELB和2个实例,因此首先我必须使用VPC的名称标签将现有VPC导入到我的状态文件中。 But I am seeing the import is working only by using the id key. 但是我看到导入只能通过使用id键来工作。 Is it possible to import using other parameters apart from ID? 是否可以使用ID以外的其他参数导入?

You can achieve this using filter field. 您可以使用过滤器字段实现此目的。

eg 例如

data "aws_vpc" "selected" {
        filter = "tag:name=value"
}

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

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