
Terraform AWS Provider v6 から「リソースレベルで」リージョンを指定できる.たとえばプロバイダーで ap-northeast-1 リージョンを指定しつつ,Amazon ECR リポジトリを us-east-1 リージョンにデプロイする場合は以下のように実装すれば OK👌
resource "aws_ecr_repository" "main" { region = "us-east-1" name = "sandbox-repository" }
詳しくは前にブログにまとめてある.
この region プロパティを指定したリソースをインポートする場合に以下のように import block を実装すると
import { to = aws_ecr_repository.main id = "sandbox-repository" }
リソースが見つからずに Cannot import non-existent remote object というエラーが出てしまう🔥
╷ │ Error: Cannot import non-existent remote object │ │ While attempting to import an existing object to "aws_ecr_repository.main", the provider detected that no object exists with the given id. Only pre-existing objects can be imported; check that the id is correct and │ that it is associated with the provider's configured region or endpoint, or use "terraform apply" to create a new remote object for this resource. ╵
Enhanced Region Support というドキュメントに書いてある通り,インポートするときに ID の末尾に @us-east-1 を付ける必要がある.Amazon ECR リポジトリの場合は sandbox-repository@us-east-1 となる❗️
import { to = aws_ecr_repository.main id = "sandbox-repository@us-east-1" }
覚えておこう \( 'ω')/