Skip to content

Commit 813c88f

Browse files
cvittoriasonacloudpossebotjamengual
authored
Always add var.security_groups to launch template if provided (#77)
* If sg's are passed in to var.security_groups, always add them to the lt along with cluster sg * Auto Format Co-authored-by: cloudpossebot <[email protected]> Co-authored-by: PePe Amengual <[email protected]>
1 parent 1f767c1 commit 813c88f

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

launch-template.tf

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,16 @@ locals {
3737

3838
launch_template_ami = length(local.configured_ami_image_id) == 0 ? (local.features_require_ami ? data.aws_ami.selected[0].image_id : "") : local.configured_ami_image_id
3939

40-
launch_template_vpc_security_group_ids = (
41-
local.need_remote_access_sg ?
42-
concat(data.aws_eks_cluster.this[0].vpc_config[*].cluster_security_group_id, module.security_group.*.id, var.security_groups) : []
43-
)
40+
launch_template_vpc_security_group_ids = distinct(concat(
41+
(
42+
local.need_remote_access_sg ?
43+
concat(data.aws_eks_cluster.this[0].vpc_config[*].cluster_security_group_id, module.security_group.*.id) : []
44+
),
45+
(
46+
local.add_sgs_to_cluster_default ?
47+
concat(var.security_groups, data.aws_eks_cluster.this[0].vpc_config[*].cluster_security_group_id) : []
48+
)
49+
))
4450

4551
# launch_template_key = join(":", coalescelist(local.launch_template_vpc_security_group_ids, ["closed"]))
4652
}

main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ locals {
99
features_require_launch_template = local.enabled ? length(var.resources_to_tag) > 0 || local.need_userdata || local.features_require_ami || local.need_imds_settings : false
1010
remote_access_enabled = local.enabled && var.remote_access_enabled
1111
need_remote_access_sg = local.generate_launch_template && local.remote_access_enabled
12-
get_cluster_data = local.enabled ? (local.need_cluster_kubernetes_version || local.need_bootstrap || local.need_remote_access_sg) : false
12+
add_sgs_to_cluster_default = local.enabled && length(var.security_groups) > 0 ? true : false
13+
get_cluster_data = local.enabled ? (local.need_cluster_kubernetes_version || local.need_bootstrap || local.need_remote_access_sg || local.add_sgs_to_cluster_default) : false
1314
autoscaler_enabled = var.enable_cluster_autoscaler != null ? var.enable_cluster_autoscaler : var.cluster_autoscaler_enabled == true
1415
#
1516
# Set up tags for autoscaler and other resources

0 commit comments

Comments
 (0)