Skip to content

Commit

Permalink
add ip and vpce restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
ashle001 committed Oct 19, 2020
1 parent b3906b1 commit a9b8f60
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
23 changes: 23 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ locals {
# "boc:tf_module_version" = var._module_version
"boc:created_by" = "terraform"
}
condition_allowed_cidr = {
"test": "NotIpAddress"
"variable": "aws:sourceIp"
"values": var.allowed_cidr
}
condition_allowed_endpoints = {
"test": "StringNotEquals"
"variable": "aws:sourceVpce"
"values": var.allowed_endpoints
}
s3_bucket_conditions_list = list(local.condition_allowed_cidr,local.condition_allowed_endpoints)
s3_bucket_conditions = [ for x in local.s3_bucket_conditions_list: x if length(x.values)>0 ]
}

#---
Expand Down Expand Up @@ -117,6 +129,17 @@ data "aws_iam_policy_document" "this" {
values = ["false"]
}
}
statement {
dynamic "condition" {
for_each = local.s3_bucket_conditions
iterator = c
content {
test = c.value.test
variable = c.value.variable
values = c.value.values
}
}
}
}

#---
Expand Down
13 changes: 13 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,16 @@ variable "access_log_bucket" {
type = string
# default = null
}

variable "allowed_cidr" {
description = "List of allowed source IPs (NOT from within the VPC)"
type = list(string)
default = [ ]
}

variable "allowed_endpoints" {
description = "List of allowed VPC endpoint IDs"
type = list(string)
default = [ ]
}

0 comments on commit a9b8f60

Please sign in to comment.