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: Allow security_group_ids to take null values #825

Merged
merged 1 commit into from
Sep 2, 2022

Conversation

Jorge-Rodriguez
Copy link
Contributor

Description

Allow the security_group_ids argument to aws_vpc_endpoint to take null values when the endpoint is of Interface type

Motivation and Context

When defining a VPC endpoint of type Interface, if no security_group_ids are defined either as defaults or in the individual endpoint definition, the value passed to the aws_vpc_endpoint resource is an empty list.

This PR modifies that behaviour so that if no security_group_ids are defined, the aws_vpc_endpoint receives a null value instead of an empty list. Semantically, it makes no difference and it causes the default security group to be associated with the endpoint. However, functionally, a null value enables the use of aws_vpc_endpoint_security_group_association resources without triggering changes on the aws_vpc_endpoint resource.

How Has This Been Tested?

I have tested this changes against an environment where the side effects that this change addresses were occuring

@Jorge-Rodriguez Jorge-Rodriguez changed the title Allow security_group_ids to take null values Fix: Allow security_group_ids to take null values Sep 1, 2022
@Jorge-Rodriguez Jorge-Rodriguez changed the title Fix: Allow security_group_ids to take null values fix: Allow security_group_ids to take null values Sep 1, 2022
Copy link
Member

@antonbabenko antonbabenko left a comment

Choose a reason for hiding this comment

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

LGTM.

@bryantbiggs WDYT?

@@ -26,7 +26,7 @@ resource "aws_vpc_endpoint" "this" {
vpc_endpoint_type = lookup(each.value, "service_type", "Interface")
auto_accept = lookup(each.value, "auto_accept", null)

security_group_ids = lookup(each.value, "service_type", "Interface") == "Interface" ? distinct(concat(var.security_group_ids, lookup(each.value, "security_group_ids", []))) : null
security_group_ids = lookup(each.value, "service_type", "Interface") == "Interface" ? length(distinct(concat(var.security_group_ids, lookup(each.value, "security_group_ids", [])))) > 0 ? distinct(concat(var.security_group_ids, lookup(each.value, "security_group_ids", []))) : 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.

A bit shorter way:

Suggested change
security_group_ids = lookup(each.value, "service_type", "Interface") == "Interface" ? length(distinct(concat(var.security_group_ids, lookup(each.value, "security_group_ids", [])))) > 0 ? distinct(concat(var.security_group_ids, lookup(each.value, "security_group_ids", []))) : null : null
security_group_ids = lookup(each.value, "service_type", "Interface") == "Interface" ? try(coalescelist(distinct(concat(var.security_group_ids, lookup(each.value, "security_group_ids", [])))), null) : null

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.

Looks good to me, thanks @Jorge-Rodriguez !

@bryantbiggs bryantbiggs merged commit 67ef09a into terraform-aws-modules:master Sep 2, 2022
antonbabenko pushed a commit that referenced this pull request Sep 2, 2022
### [3.14.3](v3.14.2...v3.14.3) (2022-09-02)

### Bug Fixes

* Allow `security_group_ids` to take `null` values ([#825](#825)) ([67ef09a](67ef09a))
@antonbabenko
Copy link
Member

This PR is included in version 3.14.3 🎉

@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.

None yet

3 participants