-
-
Notifications
You must be signed in to change notification settings - Fork 128
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 for remote access and lifecycle issues #30
Changes from 2 commits
178522a
d9891a4
e7d95d4
95987bd
67a1c56
9a15c80
8790ea8
8a8f5ea
d230b68
3be9203
a52fb7e
e0fa427
4ea1a45
9bdd14f
d8bce3f
ef60992
d30e60c
ee2aa7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -25,6 +25,20 @@ locals { | |||||||||
id = coalesce(var.launch_template_id, aws_launch_template.default[0].id) | ||||||||||
latest_version = coalesce(var.launch_template_version, aws_launch_template.default[0].latest_version) | ||||||||||
} | ||||||||||
|
||||||||||
eks_node_group_resources = merge(aws_eks_node_group.default.*.resources, | ||||||||||
{ | ||||||||||
"remote_access_security_group_id" = aws_security_group.remote_access.id | ||||||||||
} | ||||||||||
) | ||||||||||
|
||||||||||
security_group_ids = concat( | ||||||||||
list(data.aws_eks_cluster.eks_cluster.vpc_config[0].cluster_security_group_id), | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needed to enable communication with the EKS control plane There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this always enough? Could there be more than one or some other security group that needs to be added? |
||||||||||
var.ec2_ssh_key != null ? aws_security_group.remote_access[*].id : [] | ||||||||||
) | ||||||||||
|
||||||||||
# Tagging an elastic gpu on create is not yet supported in govcloud | ||||||||||
tag_spec = compact(["instance", "volume", data.aws_partition.current[0].partition == "aws-us-gov" ? "" : "elastic-gpu"]) | ||||||||||
} | ||||||||||
|
||||||||||
module "label" { | ||||||||||
|
@@ -57,6 +71,14 @@ data "aws_iam_policy_document" "assume_role" { | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
data "aws_subnet" "default" { | ||||||||||
id = var.subnet_ids[0] | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is to prevent introducing an additional required variable. happy to modify if that's a more preferred route. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not reference this if it is not needed. |
||||||||||
} | ||||||||||
|
||||||||||
data "aws_eks_cluster" "eks_cluster" { | ||||||||||
name = var.cluster_name | ||||||||||
} | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already in v0.11.0 with appropriate conditions, although now you need to add another condition. |
||||||||||
data "aws_iam_policy_document" "amazon_eks_worker_node_autoscaler_policy" { | ||||||||||
count = (local.enabled && var.enable_cluster_autoscaler) ? 1 : 0 | ||||||||||
statement { | ||||||||||
|
@@ -133,10 +155,12 @@ resource "aws_launch_template" "default" { | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
instance_type = var.instance_types[0] | ||||||||||
instance_type = var.instance_types[0] | ||||||||||
key_name = var.ec2_ssh_key | ||||||||||
vpc_security_group_ids = local.security_group_ids | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case we get the security group list wrong, I do not want to specify it if we do not have to.
Suggested change
|
||||||||||
|
||||||||||
dynamic "tag_specifications" { | ||||||||||
for_each = ["instance", "volume", "elastic-gpu"] | ||||||||||
for_each = local.tag_spec | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is handled in v0.11.0 |
||||||||||
content { | ||||||||||
resource_type = tag_specifications.value | ||||||||||
tags = local.node_group_tags | ||||||||||
|
@@ -170,14 +194,6 @@ resource "aws_eks_node_group" "default" { | |||||||||
version = local.launch_template.latest_version | ||||||||||
} | ||||||||||
|
||||||||||
dynamic "remote_access" { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this block is not supported when using launch templates. currently breaks the entire module if |
||||||||||
for_each = var.ec2_ssh_key != null && var.ec2_ssh_key != "" ? ["true"] : [] | ||||||||||
content { | ||||||||||
ec2_ssh_key = var.ec2_ssh_key | ||||||||||
source_security_group_ids = var.source_security_group_ids | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
# Ensure that IAM Role permissions are created before and deleted after EKS Node Group handling. | ||||||||||
# Otherwise, EKS will not be able to properly delete EC2 Instances and Elastic Network Interfaces. | ||||||||||
depends_on = [ | ||||||||||
|
@@ -195,3 +211,34 @@ resource "aws_eks_node_group" "default" { | |||||||||
ignore_changes = [scaling_config[0].desired_size] | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
resource "aws_security_group" "remote_access" { | ||||||||||
count = local.enabled && var.ec2_ssh_key != null ? 1 : 0 | ||||||||||
name = "eks-${var.cluster_name}-${module.label.id}-remote-access" | ||||||||||
description = "Security group for all nodes in the nodeGroup to allow SSH access" | ||||||||||
vpc_id = data.aws_subnet.default.vpc_id | ||||||||||
tags = module.label.tags | ||||||||||
} | ||||||||||
|
||||||||||
resource "aws_security_group_rule" "public_ssh" { | ||||||||||
count = local.enabled && var.ec2_ssh_key != null && length(var.source_security_group_ids) < 1 ? 1 : 0 | ||||||||||
from_port = 22 | ||||||||||
protocol = "tcp" | ||||||||||
security_group_id = aws_security_group.remote_access[0].id | ||||||||||
to_port = 22 | ||||||||||
type = "ingress" | ||||||||||
|
||||||||||
cidr_blocks = [ | ||||||||||
"0.0.0.0/0" | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this emulates the default behavior of non-launch template node groups that specify a |
||||||||||
] | ||||||||||
} | ||||||||||
|
||||||||||
resource "aws_security_group_rule" "source_sgs_ssh" { | ||||||||||
count = local.enabled && var.ec2_ssh_key != null ? length(var.source_security_group_ids) : 0 | ||||||||||
from_port = 22 | ||||||||||
protocol = "tcp" | ||||||||||
security_group_id = aws_security_group.remote_access[0].id | ||||||||||
to_port = 22 | ||||||||||
source_security_group_id = var.source_security_group_ids[count.index] | ||||||||||
type = "ingress" | ||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is some formatting to maintain backward compatibility with outputs.