amazon-web-services - terraform 将现有 AWS 资源导入模块
问题描述
我有一个已经准备好 ECR 和 IAM 的 AWS 账户。我现在正在使用 terraform 模块创建一个新环境。但我找不到将现有 IAM 和 ECR 资源导入我的模块的方法。当我运行命令terraform import aws_ecr_repository.c2m_an c2m_an
时,我收到一个错误
Error: resource address "aws_ecr_repository.c2m_cs" does not exist in the configuration.
Before importing this resource, please create its configuration in the root module. For example:
resource "aws_ecr_repository" "c2m_cs" {
# (resource arguments)
}
我的 ECR 模块定义如下:
resource "aws_ecr_repository" "c2m_cs" {
name = var.c2m_cs#"c2m_cs"
}
output "c2m_cs" {
value = "terraform import aws_ecr_repository.c2m_cs c2m_cs"
}
在我main.tf
的环境文件夹中的文件中,我的模块定义如下:
module "ecr" {
source = "../modules/ecr"
c2m_cs = module.ecr.c2m_cs
}
解决方案
文档中举例说明了将资源导入模块的正确方法:
terraform import module.foo.aws_instance.bar i-abcd1234
因此,在您的情况下,它将是:
terraform import module.aws_ecr_repository.c2m_an c2m_an
推荐阅读
- vue.js - Vue 道具未正确传递
- python - FileField PDF 不会打开 Django
- r - 如何在这里删除trace0?
- ruby-on-rails - 保存在控制器中后,关联记录在集成测试中为零
- node.js - NodeJS - 'WEB' 客户端类型不允许使用自定义方案 URI
- python - 我应该如何在 docker 中安装 python 包?
- javascript - 如何使用 SameSite None 和 Secure 正确设置跨域 cookie?
- amazon-web-services - AWS 无法连接到终端节点 URL:“https://rekognition.eu-west-3.amazonaws.com/”
- c - 如何每次在常量数组中打印下一个最大元素?
- amazon-web-services - 无法在cloudformation中查看下载的文件