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

Make it optional to override the origin s3 policy #67

Merged
merged 2 commits into from
Feb 25, 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
5 changes: 4 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ data "template_file" "default" {
}

resource "aws_s3_bucket_policy" "default" {
count = ! local.using_existing_origin || var.override_origin_bucket_policy ? 1 : 0
bucket = local.bucket
policy = data.template_file.default.rendered
}
Expand All @@ -102,7 +103,7 @@ data "aws_region" "current" {
}

resource "aws_s3_bucket" "origin" {
count = signum(length(var.origin_bucket)) == 1 ? 0 : 1
count = local.using_existing_origin ? 0 : 1
bucket = module.origin_label.id
acl = "private"
tags = module.origin_label.tags
Expand Down Expand Up @@ -173,6 +174,8 @@ data "aws_s3_bucket" "selected" {
}

locals {
using_existing_origin = signum(length(var.origin_bucket)) == 1

bucket = join("",
compact(
concat([var.origin_bucket], concat([""], aws_s3_bucket.origin.*.id))
Expand Down
8 changes: 7 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ variable "additional_bucket_policy" {
description = "Additional policies for the bucket. If included in the policies, the variables `$${bucket_name}`, `$${origin_path}` and `$${cloudfront_origin_access_identity_iam_arn}` will be substituted. It is also possible to override the default policy statements by providing statements with `S3GetObjectForCloudFront` and `S3ListBucketForCloudFront` sid."
}

variable "override_origin_bucket_policy" {
type = bool
default = true
description = "When using an existing origin bucket (through var.origin_bucket), setting this to 'false' will make it so the existing bucket policy will not be overriden"
}

variable "origin_bucket" {
type = string
default = ""
Expand All @@ -97,7 +103,7 @@ variable "origin_path" {
variable "origin_force_destroy" {
type = bool
default = false
description = "Delete all objects from the bucket so that the bucket can be destroyed without error (e.g. `true` or `false`)"
description = "Delete all objects from the bucket so that the bucket can be destroyed without error (e.g. `true` or `false`)"
}

variable "bucket_domain_format" {
Expand Down