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 default_security_group to have no rules #1123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

britthouser
Copy link

@britthouser britthouser commented Sep 30, 2024

Description

The current implementation of the aws_default_security_group uses dynamic blocks for both ingress and egress rules. If no rules are passed in, then no dynamic blocks are generated, and no pre-existng rules are changed. In order to implement the CIS benchmark of no rules, the aws_default_security_group resource needs to be created passing empty lists as ingress and egress rules.

This commit updates the default ingress/egress rules to be those AWS uses when it initially created the default SG. It then sets the boolen local.empty_default_security_group if both ingress and egress rules passed in are empty lists. Finally it conditionally creates empty aws_default_security_group resource if local.empty_default_security_group is true. If local.empty_default_security_group is false, the original aws_default_security_group resource is utilized.

Motivation and Context

#759
hashicorp/terraform-provider-aws#20697

Breaking Changes

Yes and No. If the user has specified any custom security group rules, then those are honored and won't break. If the user has not specified any custom security group rules, and has not changed the default rules which AWS created when the security group was created, then those are preserved and won't break. But if the user has not specified any custom security group rules AND outside of terraform changed the rules to something different from the ones AWS supplies, then those will get reverted back to the AWS supplied rules.

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

@britthouser britthouser changed the title Allow default_security_group to have no rules fix: Allow default_security_group to have no rules Sep 30, 2024
The current implementation of the aws_default_security_group
uses dynamic blocks for both ingress and egress rules. If no
rules are passed in, then no dynamic blocks are generated,
and no pre-existng rules are changed. In order to implement the
CIS benchmark of no rules, the aws_default_security_group
resorce needs to be created passing empty lists as ingress
and egress rules.

This commit updates the default ingress/egress rules to be
those AWS uses when it initially created the default SG.
It then sets the boolen local.empty_default_security_group
if both ingress and egress rules passed in are empty lists.
Finally it conditionally creates empty aws_default_security_group
resource if local.empty_default_security_group is true.  If
local.empty_default_security_group is false, the original
aws_default_security_group resource is utilized.
@britthouser
Copy link
Author

@bryantbiggs - would love to get your thoughts on this implementation whenever you get a minute.

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.

1 participant