amazon-web-services - 如何将现有资源导入 terraform
问题描述
我Terraform v0.12.6
用来管理 AWS 基础设施。将配置部署到 AWS 时出现此错误。我知道我需要导入现有资源,但我不知道我应该使用的参数 ID。
Error: Error creating Security Group: InvalidGroup.Duplicate: The security group 'SecuritySearchElasticSearchencr' already exists for VPC 'vpc-0cce833ea304b0215'
status code: 400, request id: c3bef103-023a-4d6f-888b-bcb8d024eff8
on deploy/infra/modules/elasticsearch/security-groups.tf line 1, in resource "aws_security_group" "es":
1: resource "aws_security_group" "es" {
当我运行时terraform import aws_security_group.es vpc-0cce833ea304b0215
出现此错误:
Error: resource address "aws_security_group.es" does not exist in the configuration.
Before importing this resource, please create its configuration in the root module. For example:
resource "aws_security_group" "es" {
# (resource arguments)
}
我也尝试导入安全组 ID,但仍然出现同样的错误:
#terraform import aws_security_group.es sg-0227291ba8162542d
Error: resource address "aws_security_group.es" does not exist in the configuration.
Before importing this resource, please create its configuration in the root module. For example:
resource "aws_security_group" "es" {
# (resource arguments)
}
当我跑步时terraform plan
,我得到:
+ resource "aws_security_group" "es" {
+ arn = (known after apply)
+ description = "Allow HTTPS inbound traffic"
+ egress = [
+ {
+ cidr_blocks = [
+ "0.0.0.0/0",
]
+ description = ""
+ from_port = 0
+ ipv6_cidr_blocks = []
+ prefix_list_ids = []
+ protocol = "-1"
+ security_groups = []
+ self = false
+ to_port = 0
},
]
+ id = (known after apply)
+ ingress = [
+ {
+ cidr_blocks = []
+ description = ""
+ from_port = 443
+ ipv6_cidr_blocks = []
+ prefix_list_ids = []
+ protocol = "tcp"
+ security_groups = [
+ "sg-08e48ea67d2f8ebd6",
+ "sg-0bdc3d7ce660183d8",
]
+ self = false
+ to_port = 443
},
]
+ name = "SecuritySearchElasticSearchencr"
+ owner_id = (known after apply)
+ revoke_rules_on_delete = false
+ tags = {
+ "Application" = "Security Search"
+ "Client" = "IRESS"
+ "DataClassification" = "NoData"
+ "Name" = "Security Search ElasticSearch"
+ "Owner" = "platform"
+ "Product" = "SharedServices"
+ "Schedule" = "False"
+ "Service" = "Elastic Search Cluster"
+ "TaggingStandardVersion" = "3"
}
+ vpc_id = "vpc-0cce833ea304b0215"
}
我想知道我应该使用什么命令来导入现有资源?
解决方案
可以使用安全组 ID 导入安全组,而您使用 VPC ID 导入。
如果您获取 IDSecuritySearchElasticSearchencr
并将其传递给 terraform import 命令,它应该可以工作。
terraform import aws_security_group.es sg-xxxxxx
推荐阅读
- css - 文本输入如何触发如此昂贵的布局计算?
- python - Pygame在blitting期间返回锁定错误
- python - Django 从数据库模型创建下拉列表并保存在另一个模型中
- android - ViewBinding - 包含的布局绑定导致未解析的引用
- python - OSError: [WinError 10049] L'adresse demandée n'est pas valide dans son contexte
- mongodb - 在 MongoDB 中从 $match、$and 中动态排除字段
- elasticsearch - 在哪个弹性堆栈版本中引入了观察者?
- android - Android:需要下载文件夹 Uri 而不是路径
- html - 如何使用输入类型范围将文本添加到滑块拇指?
- lua - 如果参数是硬编码字符串或包含所述字符串的变量,则 Nmap NSE 脚本函数的行为会有所不同