Open2

terraform小技

tabiotabio

terraform state listで管理しているリソースを一覧で確認できる

$ terraform state list

module.network.data.aws_region.current

terraform showでリソースの詳細を閲覧できる

$ terraform show

# module.network.data.aws_region.current:
data "aws_region" "current" {
    description = "Asia Pacific (Tokyo)"
    endpoint    = "ec2.ap-northeast-1.amazonaws.com"
    id          = "ap-northeast-1"
    name        = "ap-northeast-1"
}

tabiotabio

terraformのリソース管理対象から外す

$ terraform state rm module.hoge.api_gateway.aws_api_gateway_account.fuga

aws_api_gateway_accountはawsアカウントで共通のため、定義は1つしか書けない

複数書いたため、意図しない変更が走ってしまい混乱した(アカウントxリージョンで1つという考え方らしい)

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_account