Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added attach_public_policy as conditional switch #34

Merged
merged 3 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.30.0
rev: v1.31.0
hooks:
- id: terraform_fmt
- id: terraform_docs
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ module "s3_bucket" {
| acl | (Optional) The canned ACL to apply. Defaults to 'private'. | `string` | `"private"` | no |
| attach\_elb\_log\_delivery\_policy | Controls if S3 bucket should have ELB log delivery policy attached | `bool` | `false` | no |
| attach\_policy | Controls if S3 bucket should have bucket policy attached (set to `true` to use value of `policy` as bucket policy) | `bool` | `false` | no |
| attach\_public\_policy | Controls if a user defined public bucket policy will be attached (set to `false` to allow upstream to apply defaults to the bucket) | `bool` | `true` | no |
| block\_public\_acls | Whether Amazon S3 should block public ACLs for this bucket. | `bool` | `false` | no |
| block\_public\_policy | Whether Amazon S3 should block public bucket policies for this bucket. | `bool` | `false` | no |
| bucket | (Optional, Forces new resource) The name of the bucket. If omitted, Terraform will assign a random, unique name. | `string` | `null` | no |
Expand Down
1 change: 1 addition & 0 deletions examples/notification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ No requirements.
| Name | Version |
|------|---------|
| aws | n/a |
| null | n/a |
| random | n/a |

## Inputs
Expand Down
12 changes: 6 additions & 6 deletions examples/notification/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ module "all_notifications" {

lambda_notifications = {
lambda1 = {
function_arn = module.lambda_function1.this_lambda_function_arn
function_arn = module.lambda_function1.this_lambda_function_arn
function_name = module.lambda_function1.this_lambda_function_name
events = ["s3:ObjectCreated:Put"]
filter_prefix = "prefix/"
filter_suffix = ".json"
events = ["s3:ObjectCreated:Put"]
filter_prefix = "prefix/"
filter_suffix = ".json"
}

lambda2 = {
function_arn = module.lambda_function2.this_lambda_function_arn
function_arn = module.lambda_function2.this_lambda_function_arn
function_name = module.lambda_function2.this_lambda_function_name
events = ["s3:ObjectCreated:Post"]
events = ["s3:ObjectCreated:Post"]
}
}

Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ data "aws_iam_policy_document" "elb_log_delivery" {
}

resource "aws_s3_bucket_public_access_block" "this" {
count = var.create_bucket ? 1 : 0
count = var.create_bucket && var.attach_public_policy ? 1 : 0

// Chain resources (s3_bucket -> s3_bucket_policy -> s3_bucket_public_access_block)
// to prevent "A conflicting conditional operation is currently in progress against this resource."
Expand Down
2 changes: 1 addition & 1 deletion modules/notification/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ resource "aws_lambda_permission" "allow" {
statement_id_prefix = "AllowLambdaS3BucketNotification-"
action = "lambda:InvokeFunction"
function_name = each.value.function_name
qualifier = lookup(each.value, "qualifier", null)
qualifier = lookup(each.value, "qualifier", null)
principal = "s3.amazonaws.com"
source_arn = local.bucket_arn
}
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ variable "attach_policy" {
default = false
}

variable "attach_public_policy" {
description = "Controls if a user defined public bucket policy will be attached (set to `false` to allow upstream to apply defaults to the bucket)"
type = bool
default = true
}

variable "bucket" {
description = "(Optional, Forces new resource) The name of the bucket. If omitted, Terraform will assign a random, unique name."
type = string
Expand Down