【问题标题】:how to get sid in AWS S3 bucket policy in terraform如何在 terraform 的 AWS S3 存储桶策略中获取 sid
【发布时间】:2020-11-20 18:53:52
【问题描述】:

我想将策略附加到 S3 存储桶资源。

我的 terraform 基础设施,

resource "aws_s3_bucket" "storage" {
  bucket = "${var.service}-${local.stage}-storage"
  acl    = "public-read"

  tags = {
    Service = var.service
    Stage   = local.stage
  }

  cors_rule {
    allowed_headers = [
      "*"
    ]
    allowed_methods = [
      "GET",
      "HEAD"
    ]
    allowed_origins = [
      "*"
    ]
    max_age_seconds = 3000
  }
}

此存储桶用于 Web 静态文件托管。我需要公开存储桶策略。

我在 terraform 中的政策,

resource "aws_s3_bucket_policy" "storage-policy" {
  bucket = aws_s3_bucket.storage.id

  policy = <<POLICY
{
  "Version": "2012-10-17",
  "Id": "????????",
  "Statement": [
    {
      "Sid": "????????",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "*",
      "Resource": "arn:aws:s3:::BUCKET-NAME/*"
    }
  ]
}
POLICY
}

在这段代码中,我需要获取 Id、Sid 字段值。 我怎么能得到这个? 谢谢。

【问题讨论】:

    标签: amazon-web-services amazon-s3 terraform


    【解决方案1】:

    IdSid 是你想要的。例如:

    resource "aws_s3_bucket_policy" "storage-policy" {
      bucket = aws_s3_bucket.storage.id
    
      policy = <<POLICY
    {
      "Version": "2012-10-17",
      "Id": "my-bucket-polict",
      "Statement": [
        {
          "Sid": "allow-all-access",
          "Effect": "Allow",
          "Principal": "*",
          "Action": "*",
          "Resource": "arn:aws:s3:::BUCKET-NAME/*"
        }
      ]
    }
    POLICY
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-04
      • 1970-01-01
      • 2019-05-15
      • 1970-01-01
      • 2019-04-24
      • 2012-11-23
      相关资源
      最近更新 更多