【问题标题】:How to send S3 bucket region name to a json file using Terraform?如何使用 Terraform 将 S3 存储桶区域名称发送到 json 文件?
【发布时间】:2020-07-16 16:07:31
【问题描述】:

我正在使用 Terraform 创建 S3 存储桶,我需要将创建存储桶的区域名称 aws_s3_bucket.website_bucket.region 发送到以下格式的 json 文件 (root/region.json)。

root/region.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"
  }
}

【问题讨论】:

    标签: amazon-web-services terraform terraform-provider-aws


    【解决方案1】:

    以下应该完成任务:

    resource "local_file" "region" {
      filename = "root/region.json"
      content  = jsonencode({
        "region": aws_s3_bucket.website_bucket.region,
      })
    }
    

    【讨论】:

      猜你喜欢
      • 2021-08-02
      • 2021-09-27
      • 2020-11-05
      • 2020-11-10
      • 2021-04-04
      • 1970-01-01
      • 2021-09-04
      • 2021-06-03
      • 2019-09-14
      相关资源
      最近更新 更多