3
1

More than 1 year has passed since last update.

Terraform importでError: Resource already managed by Terraform対策

Last updated at Posted at 2022-02-07

はじめ

terraform plan で差分がゴチャゴチャでapplyしても大丈夫か分からない
terraform importError: Resource already managed by Terraform 怒られる

以下の手順で対処できる

  1. tfstateをバックアップ
$ terraform state pull > tfstate.bk
  1. elementsモジュール削除によるdestroyの差分をstate rmで削除
$ terraform state rm module.network.module.private_route_table
$ terraform state rm module.network.module.public_route_table
  1. これで邪魔なものがなくなりました

terraform plan でモジュールのパス確認 → terraform import 実施

例:

terraform import 'module.rds["hoge"].module.security_group_rds.aws_security_group_rule.ingress_with_cidr[0]' sg-014c9982446a15b94e_ingress_tcp_3306_3306_172.34.163.0/26_172.34.163.64/26

以上です

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1