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: Ensure the correct service CIDR and IP family is used in the rendered user data #2963

Merged

Conversation

bryantbiggs
Copy link
Member

@bryantbiggs bryantbiggs commented Mar 10, 2024

Description

Motivation and Context

Before (#2960):
image

After (this PR):
image

Breaking Changes

  • No

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

@bryantbiggs bryantbiggs marked this pull request as ready for review March 11, 2024 21:27
@@ -388,6 +389,9 @@ module "disabled_eks_managed_node_group" {
source = "../../modules/eks-managed-node-group"

create = false

# Hard requirement
cluster_service_cidr = ""
Copy link
Member

Choose a reason for hiding this comment

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

This is the first time we require something to be set for "disabled" modules, as far as I see. Can we still make it optional to be consistent?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've come up with a way to make this only required when create = true using precondition on a null_resource that does nothing (but enforce the check) https://github.com/terraform-aws-modules/terraform-aws-eks/pull/2963/files#diff-87747f89f95b121dfc7a5f6e40ee0a56f1f98449581c02bd34f2171210c2f14dR1-R12

When create = true and you do not provide a cluster_service_cidr you now get this error which is what we (I) want since it is required when creating a nodegroup:
image

I did have to bump the Terraform MSV from 1.3.0 to 1.3.2 to pick up this patch hashicorp/terraform#31846

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.

Why 6? and LGTM :)

resource "null_resource" "validate_cluster_service_cidr" {
lifecycle {
precondition {
condition = var.create ? length(local.cluster_service_cidr) > 6 : true # length(local.cluster_service_cidr) == 0
Copy link
Member

Choose a reason for hiding this comment

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

Where does 6 come from?

Copy link
Member Author

Choose a reason for hiding this comment

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

I just picked something 😅 - the smallest is 4 with IPv6 ::/0 but thats not a valid service CIDR range. On the IPv4 side, the smallest is 11 with something like 10.0.0.0/16 - I didn't want to be overly restrictive or pedantic on what value so I went with 6 🤷🏽‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

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

Theres probably a better way, but the gist of the check is that something needs to be provided when create = true

Copy link
Member Author

Choose a reason for hiding this comment

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

Cleaned up the commented out code and added a note on the arbitrary value of 6 in 1f2ef2a

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation! Something like this is a bit more flexible (probably): try(cidrhost(local.cluster_service_cidr, 0) != "::", false)

@bryantbiggs bryantbiggs merged commit aeb9f0c into terraform-aws-modules:master Mar 12, 2024
17 checks passed
@bryantbiggs bryantbiggs deleted the fix/service-cidr branch March 12, 2024 14:36
antonbabenko pushed a commit that referenced this pull request Mar 12, 2024
## [20.8.3](v20.8.2...v20.8.3) (2024-03-12)

### Bug Fixes

* Ensure the correct service CIDR and IP family is used in the rendered user data ([#2963](#2963)) ([aeb9f0c](aeb9f0c))
@antonbabenko
Copy link
Member

This PR is included in version 20.8.3 🎉

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 Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants