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

Update Security Group rules #186

Merged
merged 4 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'docs/**'
- 'examples/**'
- 'test/**'
- 'README.*'

permissions:
contents: write
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2018-2022 Cloud Posse, LLC
Copyright 2018-2023 Cloud Posse, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 0 additions & 2 deletions security-group-variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ variable "allowed_cidr_blocks" {
EOT
}



variable "custom_ingress_rules" {
type = list(object({
description = string
Expand Down
14 changes: 9 additions & 5 deletions security-group.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,32 @@
# Rules for EKS-managed Security Group
# -----------------------------------------------------------------------

locals {
cluster_security_group_id = one(aws_eks_cluster.default[*].vpc_config[0].cluster_security_group_id)
cluster_security_group_rules_enabled = local.enabled && !local.create_security_group
}

resource "aws_security_group_rule" "managed_ingress_security_groups" {
count = local.enabled ? length(local.allowed_security_group_ids) : 0
count = local.cluster_security_group_rules_enabled ? length(local.allowed_security_group_ids) : 0

description = "Allow inbound traffic from existing Security Groups"
from_port = 0
to_port = 65535
protocol = "-1"
source_security_group_id = local.allowed_security_group_ids[count.index]
security_group_id = one(aws_eks_cluster.default[*].vpc_config[0].cluster_security_group_id)
security_group_id = local.cluster_security_group_id
type = "ingress"
}

resource "aws_security_group_rule" "managed_ingress_cidr_blocks" {
aknysh marked this conversation as resolved.
Show resolved Hide resolved
aknysh marked this conversation as resolved.
Show resolved Hide resolved
aknysh marked this conversation as resolved.
Show resolved Hide resolved
aknysh marked this conversation as resolved.
Show resolved Hide resolved
count = local.enabled && length(var.allowed_cidr_blocks) > 0 ? 1 : 0
count = local.cluster_security_group_rules_enabled && length(var.allowed_cidr_blocks) > 0 ? 1 : 0

description = "Allow inbound traffic from CIDR blocks"
from_port = 0
to_port = 65535
protocol = "-1"
cidr_blocks = var.allowed_cidr_blocks
security_group_id = one(aws_eks_cluster.default[*].vpc_config[0].cluster_security_group_id)
security_group_id = local.cluster_security_group_id
type = "ingress"
}

Expand Down Expand Up @@ -92,7 +97,6 @@ resource "aws_security_group_rule" "ingress_cidr_blocks" {
}

resource "aws_security_group_rule" "custom_ingress_rules" {

for_each = { for sg_rule in var.custom_ingress_rules : sg_rule.source_security_group_id => sg_rule }

description = each.value.description
Expand Down