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

fix: Disable endpoint creation when setting create_proxy = false #12

Merged
merged 3 commits into from
Aug 10, 2022

Conversation

fatmcgav-depop
Copy link
Contributor

@fatmcgav-depop fatmcgav-depop commented Aug 9, 2022

Spotted this issue whilst trying to integrate this module into some existing code where we don't always want to create a RDS Proxy instance, but when we are creating a proxy we want a default set of endpoints.

Setting create_proxy = false works for the majority of resources, however the aws_db_proxy_endpoint resource uses a for_each which will try and create endpoints against a non-existent DB proxy.

So switch to using a local which gets set to an empty map if var.create_proxy is false.
In order to fix this, add a conditional to the for_each statement.

Description

Motivation and Context

Breaking Changes

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

Spotted this issue whilst trying to integrate this module into some existing code where we don't always want to create a RDS Proxy instance, but when we are creating a proxy we want a default set of endpoints.

Setting `create_proxy = false` works for the majority of resources, however the `aws_db_proxy_endpoint` resource uses a `for_each` which will try and create endpoints against a non-existent DB proxy.

So switch to using a `local` which gets set to an empty map if `var.create_proxy` is false.
@fatmcgav-depop fatmcgav-depop changed the title Fix issue when attempting to set create_proxy = false fix: issue when attempting to set create_proxy = false Aug 9, 2022
@bryantbiggs bryantbiggs changed the title fix: issue when attempting to set create_proxy = false fix: Disable endpoint creation when setting create_proxy = false Aug 9, 2022
main.tf Outdated
@@ -68,7 +69,7 @@ resource "aws_db_proxy_target" "db_cluster" {
}

resource "aws_db_proxy_endpoint" "this" {
for_each = var.db_proxy_endpoints
for_each = local.db_proxy_endpoints
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for_each = local.db_proxy_endpoints
for_each = {for k,v in var.db_proxy_endpoints: k => v if var.create_proxy }

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 did try this first, but I couldn't get it to work...

I'll try again though...

Copy link
Contributor Author

@fatmcgav-depop fatmcgav-depop Aug 10, 2022

Choose a reason for hiding this comment

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

And for whatever reason it worked this time... Updated in 2a76143 (#12)

Instead add the conditional to the `for_each` statement.
Thanks for the suggestion @bryantbiggs.
Copy link
Member

@bryantbiggs bryantbiggs left a comment

Choose a reason for hiding this comment

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

thank you @fatmcgav-depop !

@bryantbiggs bryantbiggs merged commit 26724ab into terraform-aws-modules:master Aug 10, 2022
antonbabenko pushed a commit that referenced this pull request Aug 10, 2022
### [2.1.1](v2.1.0...v2.1.1) (2022-08-10)

### Bug Fixes

* Disable endpoint creation when setting `create_proxy = false` ([#12](#12)) ([26724ab](26724ab))
* Update documentation to remove prior notice and deprecated workflow ([#9](#9)) ([8c1720c](8c1720c))
@antonbabenko
Copy link
Member

This PR is included in version 2.1.1 🎉

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants