AWS Terraform moduleを指定する方法
環境
AWS Terraform
構文
terraform plan -target=module.モジュール名
targetオプションでmoduleを指定すると、そのmodule以下のリソースが対象となります。
使用例
1.モジュールのサンプル
resource "aws_s3_bucket" "cft_bucket" {
bucket = "test-bucket-000000000000"
}
resource "aws_s3_bucket_server_side_encryption_configuration" "cft_bucket" {
bucket = aws_s3_bucket.cft_bucket.bucket
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
resource "aws_s3_bucket_public_access_block" "cft_bucket" {
bucket = aws_s3_bucket.cft_bucket.bucket
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
2.main.tfで上記モジュールを読み込む
module "sample" {
source = "./modules/sample"
}
3.-targetオプションでmodule.sampleを指定すると、modules/sampleディレクトリ以下のリソースが対象となります
$ terraform plan -target=module.sample