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: Fixed service_region argument in the VPC endpoint module #1162

Conversation

mmeidlinger
Copy link
Contributor

@mmeidlinger mmeidlinger commented Jan 27, 2025

Description

Currently, if we pass service_region=null (rather than not passing it at all), the module fails as it passes on [null] rather than null to the underlying data source.

Motivation and Context

See description and the comment in this PR that added cross-region support in the first place.

Breaking Changes

Non breaking, makes things more robust and covers all all cases (no service_region passed, service_region=null passed, valid service region passed)

How Has This Been Tested?

Tested passing no service_region, service_region=null, or a valid service region passed

@@ -13,7 +13,7 @@ data "aws_vpc_endpoint_service" "this" {

service = try(each.value.service, null)
service_name = try(each.value.service_name, null)
service_regions = try([each.value.service_region], null)
service_regions = try(each.value.service_region != null ? [each.value.service_region] : null, null)
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
service_regions = try(each.value.service_region != null ? [each.value.service_region] : null, null)
service_regions = one([each.value.service_region])

Much simpler, but please test it. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback. So I tested

service_regions = one([each.value.service_region])

this does not quite work. If the endpoints maps' service_region value is a valid string, it evaluates just to the string, but the data sources' service_regions expects a list of strings. Further, if service _region is not included in the endpoints map, it also fails.

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 think we could change it to this which is a bit easier to understand and read and I successfully tested for all 3 cases (service_region not included in the endpoints map, service_region=null or service_region="valid-region-string":

service_regions = try(each.value.service_region, null) != null ? [each.value.service_region] : null

Copy link
Member

Choose a reason for hiding this comment

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

I think this is going to work as expected:

service_regions = try(coalescelist(compact([each.value.service_region])), null)

Let's use it if it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does indeed, thank you! Updated the PR accordingly.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for fixing an issue!

@antonbabenko antonbabenko changed the title fix: Make it so we can pass service_region=null to the VPC endpoint module fix: Fixed service_region argument in the VPC endpoint module Jan 28, 2025
@antonbabenko antonbabenko merged commit 5415dee into terraform-aws-modules:master Jan 28, 2025
19 checks passed
antonbabenko pushed a commit that referenced this pull request Jan 28, 2025
## [5.18.1](v5.18.0...v5.18.1) (2025-01-28)

### Bug Fixes

* Fixed service_region argument in the VPC endpoint module ([#1162](#1162)) ([5415dee](5415dee))
@antonbabenko
Copy link
Member

This PR is included in version 5.18.1 🎉

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 Feb 28, 2025
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.

2 participants