Skip to content

Instantly share code, notes, and snippets.

@hiroki1117
Created April 6, 2020 09:27
Show Gist options
  • Save hiroki1117/d173d5d59e027b02682e9dc6aad2611e to your computer and use it in GitHub Desktop.
Save hiroki1117/d173d5d59e027b02682e9dc6aad2611e to your computer and use it in GitHub Desktop.
S3のバケットポリシーを作成するtf
provider "aws" {
region = "ap-northeast-1"
version = "~> 2.7.0"
}
resource "aws_s3_bucket" "s3_experiment" {
bucket = "hiroki.s3experiment"
acl = "private"
}
data "aws_iam_policy_document" "bucket_policy_document" {
statement = {
principals = [
{
type = "AWS"
identifiers = ["arn:aws:iam::~~"]
}
]
actions = ["s3:*"]
resources = ["arn:aws:s3:::hiroki.s3experiment"]
condition = {
test = "StringLike"
variable = "s3:prefix"
values = [
"access_test/*"
]
}
}
}
resource "aws_s3_bucket_policy" "mys3pol" {
bucket = "${aws_s3_bucket.s3_experiment.id}"
policy = "${data.aws_iam_policy_document.bucket_policy_document.json}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment