I have got an AWS account that already has ECR and IAM ready. I am now creating a new environment using terraform modules. But I could not find a way to import the existing IAM and ECR resources to my modules. When I run the command terraform import aws_ecr_repository.c2m_an c2m_an
, I am getting an error as
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)
}
My ECR module definition is as follows:
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"
}
And in my main.tf
file withtin my environment folder, I have module definition as follows:
module "ecr" {
source = "../modules/ecr"
c2m_cs = module.ecr.c2m_cs
}