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

[#98] Add a flag to redirect HTTP traffic to HTTPS #218

Merged
merged 20 commits into from
Feb 14, 2023

Conversation

sestrella
Copy link
Contributor

@sestrella sestrella commented Nov 27, 2022

what

  • Add a flag to redirect HTTP traffic to HTTPS
  • The hostname included in the redirection can be customized

why

  • It is a common best practice to redirect HTTP traffic to HTTPS
  • This workaround is necessary since Elastic Beanstalk HTTP listener rule can't be changed to a redirect action via the general options

references

@sestrella sestrella marked this pull request as ready for review November 27, 2022 22:08
@sestrella sestrella requested review from a team as code owners November 27, 2022 22:08
@sestrella sestrella marked this pull request as draft November 27, 2022 22:34
Copy link
Sponsor Member

@joe-niland joe-niland left a comment

Choose a reason for hiding this comment

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

Thanks @sestrella
Looks good. I have a couple of suggestions.
Let us know when it can be moved out of draft.

main.tf Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
main.tf Outdated Show resolved Hide resolved
@sestrella
Copy link
Contributor Author

@joe-niland thank you for the review, I addressed most of the comments, however, I would like to do some testing on a project before flagging this PR as "Ready for Review"

@sestrella sestrella marked this pull request as ready for review February 8, 2023 05:17

data "aws_lb_listener" "http" {
count = local.enabled && var.loadbalancer_redirect_http_to_https ? 1 : 0
load_balancer_arn = var.loadbalancer_is_shared ? var.shared_loadbalancer_arn : one(aws_elastic_beanstalk_environment.default.0.load_balancers)
Copy link
Contributor Author

@sestrella sestrella Feb 8, 2023

Choose a reason for hiding this comment

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

@joe-niland I tried to avoid hard-coding the 0 index here, however, it didn't work:

one(aws_elastic_beanstalk_environment.default.*.load_balancers)

On the other hand, I noticed the 0 index is hard-coded on the load_balancers output, so I'm using the same approach for now.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

What was the error you saw with the above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one:

image

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Sorry this was my mistake - in the example code I was thinking of something else and forgot the indexing was there just because count is used on the eb environment resource. This seems fine now.

@sestrella
Copy link
Contributor Author

@joe-niland I did some local testing and it seems to work fine, this is the rule added to the HTTP listener:

image

@joe-niland
Copy link
Sponsor Member

/rebuild-readme

@joe-niland
Copy link
Sponsor Member

@sestrella would you mind adding this new var to https://github.com/cloudposse/terraform-aws-elastic-beanstalk-environment/tree/master/examples/complete so we can check it with Terratest?

@sestrella
Copy link
Contributor Author

@joe-niland done

@joe-niland
Copy link
Sponsor Member

/test all

@joe-niland
Copy link
Sponsor Member

/rebuild-readme

@joe-niland
Copy link
Sponsor Member

@sestrella just a minor thing in the BATS test to look at

@joe-niland
Copy link
Sponsor Member

Also @sestrella could you please run the following:

make
make readme

@joe-niland
Copy link
Sponsor Member

@sestrella
Copy link
Contributor Author

@joe-niland I updated the README.md and docs/terraform.md files as suggested

@joe-niland
Copy link
Sponsor Member

/test all

@joe-niland
Copy link
Sponsor Member

@sestrella can you please update the version constraint in examples/**/versions.tf also?

@joe-niland
Copy link
Sponsor Member

/test bats

@joe-niland
Copy link
Sponsor Member

/test readme

@joe-niland
Copy link
Sponsor Member

/test terratest

@joe-niland
Copy link
Sponsor Member

@sestrella since you changed the main versions.tf again you'll need to regenerate the readme as well

@sestrella
Copy link
Contributor Author

sestrella commented Feb 14, 2023

@joe-niland sorry for taking so long updating the README file, I got a weird error running make readme/build on Mac with M1:

make: *** [/Users/sestrella/code/stackbuilders/terraform-aws-elastic-beanstalk-environment/build-harness/modules/readme/Makefile:32: readme/build] Killed: 9

After taking a closer look, I realized that readme/deps step downloads the wrong binary for the arm64 architecture:

❯ uname -a
Darwin Administrators-MacBook-Pro 22.3.0 Darwin Kernel Version 22.3.0: Thu Jan  5 20:48:54 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T6000 arm64 arm Darwin
…anstalk-environment on  redirect_http_to_https [?] via 💠 default via ❄️  impure (nix-shell)
➜ file build-harness/vendor/gomplate
build-harness/vendor/gomplate: Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL>
…anstalk-environment on  redirect_http_to_https [?] via 💠 default via ❄️  impure (nix-shell)
➜ file build-harness/vendor/terraform-docs
build-harness/vendor/terraform-docs: Mach-O 64-bit x86_64 executable

Anyway, I found a workaround and I'm planning to report this issue to cloudposse/build-harness later.

README.md Outdated Show resolved Hide resolved
@joe-niland
Copy link
Sponsor Member

/test all

@joe-niland joe-niland merged commit d4009cb into cloudposse:master Feb 14, 2023
@joe-niland
Copy link
Sponsor Member

Thanks for your contribution and patience @sestrella.
Released as https://github.com/cloudposse/terraform-aws-elastic-beanstalk-environment/releases/tag/0.49.0

Regarding the aws provider version constraint, was this updated by the make target?

@sestrella sestrella deleted the redirect_http_to_https branch February 14, 2023 19:49
@sestrella
Copy link
Contributor Author

@joe-niland thank you for the code review and guidance! About:

Regarding the aws provider version constraint, was this updated by the make target?

I realized this version was coming from the .terraform.lock.hcl generated by terraform init so in the end I decided to delete this file and run make readme/build again which changed the constraint back to >= 3.0

@joe-niland
Copy link
Sponsor Member

I realized this version was coming from the .terraform.lock.hcl generated by terraform init so in the end I decided to delete this file and run make readme/build again which changed the constraint back to >= 3.0

Thanks for clarifying!

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.

Redirect http to https
2 participants