简体   繁体   中英

Terraform Import aws security group resources created using terraform-aws-modules/security-group/aws//modules/web

I have created a aws security group using the terraform provided aws module which is terraform-aws-modules/security-group/aws//modules/web. Below is the snippet of code used. Resource created properly

module "app_security_group" {
  source  = "terraform-aws-modules/security-group/aws//modules/web"
  version = "3.17.0"

  name        = "web-server-sg"
  description = "Security group for web-servers with HTTP ports open within VPC"
  vpc_id      = module.vpc.vpc_id

  ingress_cidr_blocks = module.vpc.public_subnets_cidr_blocks
}

But not able to import using below command

terraform import -var aws_region=us-east-1 -state-out=us-east-1-recover.terraform.tfstate module.app_security_group.aws_security_group.web-server-sg sg-01c3b636f23c07ed0

getting error

Error: resource address "module.app_security_group.aws_security_group.this" does not exist in the configuration.

Before importing this resource, please create its configuration in module.app_security_group. For example:

resource "aws_security_group" "web-server-sg" {
  # (resource arguments)
}

Try this command

terraform import -var aws_region=us-east-1 -state-out=us-east-1-recover.terraform.tfstate module.app_security_group.web-server-sg sg-01c3b636f23c07ed0

Also note that when you created the resource then it should have already added to the statefile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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