我正在使用Terraform创建一个S3 bucket,我需要将创建bucket的区域名称aws_s3_bucket.website_bucket.region
发送到以下格式的json文件(root/region.json
(中。
root/reregion.json
{
"region": "us-east-2"
}
root/s3.tf
resource "aws_s3_bucket" "website_bucket" {
bucket = var.website_bucket_name
provider = aws.east
acl = "public-read"
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["PUT", "POST", "GET", "DELETE"]
allowed_origins = ["*"]
}
website {
index_document = "index.html"
}
}
以下内容应能完成任务:
resource "local_file" "region" {
filename = "root/region.json"
content = jsonencode({
"region": aws_s3_bucket.website_bucket.region,
})
}