Created
April 6, 2020 09:27
-
-
Save hiroki1117/d173d5d59e027b02682e9dc6aad2611e to your computer and use it in GitHub Desktop.
S3のバケットポリシーを作成するtf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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