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

Conversation

dmattia
Copy link
Contributor

@dmattia dmattia commented Jan 15, 2020

When specifying var.origin_bucket, it can be nice to leave the existing bucket's policy as is.

As an example, I manage an s3 bucket that multiple CloudFront dists use as their origin (without paths, they just use the same code).

In this case, I do not want to restrict the bucket to only talk to a single CF dist, as this module does by default.

@dmattia dmattia requested a review from aknysh January 15, 2020 20:18
@aknysh
Copy link
Member

aknysh commented Jan 16, 2020

@dmattia please rebase

@dmattia
Copy link
Contributor Author

dmattia commented Jan 16, 2020

Just rebased @aknysh

@aknysh
Copy link
Member

aknysh commented Jan 17, 2020

/codefresh run test

variables.tf Outdated Show resolved Hide resolved
Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @dmattia
please see comments

@dmattia
Copy link
Contributor Author

dmattia commented Jan 17, 2020

Oops, thanks for catching that! Updated and rebased @aknysh

Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks again @dmattia
Just to confirm, when usinf an existing origin bucket, will this line work https://github.com/cloudposse/terraform-aws-cloudfront-s3-cdn/pull/67/files?file-filters%5B%5D=.tf#diff-7a370d8342e7203b805911c92454f0f4L169 - here it depends on the bucket which never created in this case

thanks

@dmattia
Copy link
Contributor Author

dmattia commented Jan 19, 2020

yep, I have modules using this code already, both with and without an existing origin given and have had no problems

@aknysh
Copy link
Member

aknysh commented Jan 21, 2020

/codefresh run test

main.tf Outdated
@@ -69,6 +69,7 @@ data "template_file" "default" {
}

resource "aws_s3_bucket_policy" "default" {
count = local.using_existing_origin && ! var.override_origin_bucket_policy ? 0 : 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmattia
do we really need var.override_origin_bucket_policy?
If you specify var.origin_bucket, the policy will not be created as well as the bucket itself.
If you don't specify the origin bucket, we want to create it as well as the policy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the approach you're talking about here, where we only manage the policy if we manage the bucket.

The reason I added the var is for backwards compatibility, as the current code in master will manage the policy even if the bucket isn't managed.

If you're okay with removing var.override_origin_bucket_policy, I'll gladly do it!

@aknysh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

count  = local.using_existing_origin && ! var.override_origin_bucket_policy ? 0 : 1

In the expression above, if the existing bucket is provided, the policy will not be created because local.using_existing_origin is true, so ! var.override_origin_bucket_policy is completely redundant

Please update the logic.
So yes, we want to manage the policy if we create the bucket.
And make it configurable to manage the policy or not when an existing bucket is provided.
(this is not the expression above does. It will never create the policy if an existing bucket is provided).

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Apologies for the delay, I was OOO).

Thanks for the correction! I updated the logic, not sure how I made that mistake the first time round

Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmattia please see comments, thanks

@aknysh
Copy link
Member

aknysh commented Jan 22, 2020

@dmattia please rebase and address the comments, thanks again

@dmattia
Copy link
Contributor Author

dmattia commented Jan 31, 2020

@aknysh rebased and updated code

@aknysh
Copy link
Member

aknysh commented Jan 31, 2020

/codefresh run test

Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @dmattia

please address the error:

TestExamplesComplete 2020-01-31T19:48:11Z command.go:121: Error: Reference to undeclared local value                                                                                      
TestExamplesComplete 2020-01-31T19:48:11Z command.go:121:                                                                                                                                 
TestExamplesComplete 2020-01-31T19:48:11Z command.go:121:   on ../../main.tf line 72, in resource "aws_s3_bucket_policy" "default":                                                       
TestExamplesComplete 2020-01-31T19:48:11Z command.go:121:   72:   count = ! local.use_existing_origin || var.override_origin_bucket_policy ? 1 : 0                                        
TestExamplesComplete 2020-01-31T19:48:11Z command.go:121:                                                                                                                                 
TestExamplesComplete 2020-01-31T19:48:11Z command.go:121: A local value with the name "use_existing_origin" has not been declared.                                                        

aknysh
aknysh previously requested changes Jan 31, 2020
Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, please run terraform fmt

When specifying var.origin_bucket, it can be nice to leave the existing bucket's policy as is.

As an example, I manage an s3 bucket that multiple CloudFront dists use as their origin (without paths, they just use the same code).

In this case, I do not want to restrict the bucket to only talk to a single CF dist, as this module does by default.
@dmattia
Copy link
Contributor Author

dmattia commented Feb 7, 2020

Ran fmt, and fixed the var name so that validate passes

@maximmi
Copy link
Contributor

maximmi commented Feb 24, 2020

/codefresh run test

@maximmi
Copy link
Contributor

maximmi commented Feb 24, 2020

@dmattia can't make a fix because of permission denied to push changes to your fork

! [remote rejected] dmattia/s3_policy -> dmattia/s3_policy (permission denied)
error: failed to push some refs to '[email protected]:dmattia/terraform-aws-cloudfront-s3-cdn.git'

could you please check for permissions there?

Copy link
Contributor

@maximmi maximmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmattia see comments

@dmattia
Copy link
Contributor Author

dmattia commented Feb 25, 2020

@maximmi I added you as a contributor to the repo

@maximmi
Copy link
Contributor

maximmi commented Feb 25, 2020

/codefresh run test

Copy link
Contributor

@maximmi maximmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @dmattia

@maximmi maximmi dismissed aknysh’s stale review February 25, 2020 21:28

comments were addessed

@maximmi maximmi merged commit 493d99d into cloudposse:master Feb 25, 2020
@maximmi maximmi deleted the dmattia/s3_policy branch February 25, 2020 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants