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

feat: Add security groups and policies to worker launcher template #933

Merged
merged 8 commits into from
Jul 12, 2020

Conversation

mvaal
Copy link
Contributor

@mvaal mvaal commented Jun 26, 2020

PR o'clock

References #934

Add workers_egress_internet security group (and all other security groups and policies) as dependencies to the worker launch config.

Description

In order to ensure proper ordering when running terraform destroy, I need to be able to establish an explicit dependency on the exposed resource because that resource allows pods to communicate with the control plane. Without being able to declare the dependency, terraform will likely destroy the rule early, which will prevent other resources from proper destruction. This makes the workers depend on the SGs and policies without exposing the internals.

Checklist

@mvaal mvaal changed the title feat: Add aws_security_group_rule.workers_egress_internet to output values feat: Add security groups and policies to worker launcher template Jun 26, 2020
mvaal added 2 commits June 26, 2020 13:21
Modified aws_security_group.workers to not depend on aws_eks_cluster.this as it would cause circular dependency.
This should prevent SGs from being destroyed until after cluster is destroyed.
aws_autoscaling_groups.workers already depends on aws_launch_configuration.workers and
aws_launch_configuration.workers is where the security group dependencies are set, makes
the most sense here instead of at the ASG level.
Comment on lines +262 to +274
depends_on = [
aws_security_group_rule.workers_egress_internet,
aws_security_group_rule.workers_ingress_self,
aws_security_group_rule.workers_ingress_cluster,
aws_security_group_rule.workers_ingress_cluster_kubelet,
aws_security_group_rule.workers_ingress_cluster_https,
aws_security_group_rule.workers_ingress_cluster_primary,
aws_security_group_rule.cluster_primary_ingress_workers,
aws_iam_role_policy_attachment.workers_AmazonEKSWorkerNodePolicy,
aws_iam_role_policy_attachment.workers_AmazonEKS_CNI_Policy,
aws_iam_role_policy_attachment.workers_AmazonEC2ContainerRegistryReadOnly,
aws_iam_role_policy_attachment.workers_additional_policies
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Please duplicate this on the aws_launch_template in workers_launch_template.tf

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've made the change, however, now I am thinking it might be a better approach to do this rather than copy/pasting the code. This should also help cover future scenarios.

worker_security_group_id = var.worker_create_security_group ? null_resource.worker_security_group_setup.worker_security_group_id : var.worker_security_group_id

resource "null_resource" "worker_security_group_setup" {
  worker_security_group_id = join("", aws_security_group.workers.*.id)

  depends_on = [
    aws_security_group_rule.workers_egress_internet,
    aws_security_group_rule.workers_ingress_self,
    aws_security_group_rule.workers_ingress_cluster,
    aws_security_group_rule.workers_ingress_cluster_kubelet,
    aws_security_group_rule.workers_ingress_cluster_https,
    aws_security_group_rule.workers_ingress_cluster_primary,
    aws_security_group_rule.cluster_primary_ingress_workers,
    aws_iam_role_policy_attachment.workers_AmazonEKSWorkerNodePolicy,
    aws_iam_role_policy_attachment.workers_AmazonEKS_CNI_Policy,
    aws_iam_role_policy_attachment.workers_AmazonEC2ContainerRegistryReadOnly,
    aws_iam_role_policy_attachment.workers_additional_policies
  ]
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know your thoughts on this when you have time, thanks!

mvaal added 2 commits June 29, 2020 09:34
…h_template

aws_launch_template also depends on worker_security_group_id
Copy link
Contributor

@dpiddockcmp dpiddockcmp left a comment

Choose a reason for hiding this comment

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

Sorry, been a bit busy lately. Finally found time to spin up a test cluster. This all appears to work correctly.

Thank you for your PR

@dpiddockcmp dpiddockcmp merged commit db9bb0b into terraform-aws-modules:master Jul 12, 2020
barryib pushed a commit to Polyconseil/terraform-aws-eks that referenced this pull request Oct 25, 2020
…roup rules and IAM policies (terraform-aws-modules#933)

In order to ensure proper ordering when running terraform destroy. This will block Terraform from removing up security group rules before the cluster has finished its clean up chores.
@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 Nov 17, 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.

2 participants