Skip to content

Instantly share code, notes, and snippets.

@terraboops
Created July 10, 2019 16:27
Show Gist options
  • Save terraboops/a5b96826fb70892f0dd8266bee8d0cfb to your computer and use it in GitHub Desktop.
Save terraboops/a5b96826fb70892f0dd8266bee8d0cfb to your computer and use it in GitHub Desktop.
Terraform module for iam policy docco to block non-VPC access
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}/*"
]
}
}
output "bucket_policy" {
description = "JSON string of bucket policy"
value = "${data.aws_iam_policy_document.s3_bucket_policy.json}"
}
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