Created
July 10, 2019 16:27
-
-
Save terraboops/a5b96826fb70892f0dd8266bee8d0cfb to your computer and use it in GitHub Desktop.
Terraform module for iam policy docco to block non-VPC access
This file contains hidden or 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
data "aws_iam_policy_document" "s3_bucket_policy" { | |
statement { | |
condition { | |
test = "StringNotEquals" | |
variable = "aws:sourceVpc" | |
values = [ | |
"${var.vpc_id}", | |
] | |
} | |
actions = [ | |
"s3:*", | |
] | |
resources = [ | |
"arn:aws:s3:::${var.bucket_name}", | |
"arn:aws:s3:::${var.bucket_name}/*" | |
] | |
} | |
} |
This file contains hidden or 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
output "bucket_policy" { | |
description = "JSON string of bucket policy" | |
value = "${data.aws_iam_policy_document.s3_bucket_policy.json}" | |
} |
This file contains hidden or 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
variable "bucket_name" { | |
description = "Name of S3 bucket" | |
} | |
variable "vpc_id" { | |
description = "VPC ID to allow" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment