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

Revert "feat(terraform): add tagging for private and public subnets" #12

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ Truefoundry AWS Network Module

| Name | Type |
|------|------|
| [aws_ec2_tag.private_subnet_tags](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_tag) | resource |
| [aws_ec2_tag.public_subnet_tags](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_tag) | resource |
| [aws_vpc_endpoint.s3](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_endpoint) | resource |
| [aws_iam_policy_document.flow_logs_bucket_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_subnet.private_subnets](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnet) | data source |
Expand Down
39 changes: 1 addition & 38 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ locals {

flow_logs_bucket_arn = var.flow_logs_enable ? module.vpc_flow_logs_bucket[0].s3_bucket_arn : null

# Base tags for all resources
tags = merge(
{
"terraform-module" = "network"
Expand All @@ -12,40 +11,4 @@ locals {
},
var.tags
)

# Define base tags that match the VPC module's tags
private_subnet_base_tags = merge(
{
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
"kubernetes.io/role/internal-elb" = "1"
"subnet" = "private"
},
var.private_subnet_extra_tags,
local.tags
)

public_subnet_base_tags = merge(
{
"kubernetes.io/cluster/${var.cluster_name}" = "shared"
"kubernetes.io/role/elb" = "1"
"subnet" = "public"
},
var.public_subnet_extra_tags,
local.tags
)

# Convert all tags to list format for aws_ec2_tag resources
private_subnet_tags_list = [
for k, v in local.private_subnet_base_tags : {
key = k
value = v
}
]

public_subnet_tags_list = [
for k, v in local.public_subnet_base_tags : {
key = k
value = v
}
]
}
}
20 changes: 2 additions & 18 deletions vpc.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "aws-vpc-module" {
count = var.shim ? 0 : 1
count = var.shim == true ? 0 : 1
source = "terraform-aws-modules/vpc/aws"
version = "5.0.0"

Expand Down Expand Up @@ -67,20 +67,4 @@ data "aws_subnet" "public_subnets" {
count = var.shim ? length(var.public_subnets_ids) : 0

id = element(var.public_subnets_ids, count.index)
}

resource "aws_ec2_tag" "private_subnet_tags" {
count = var.shim ? length(var.private_subnets_ids) * length(local.private_subnet_tags_list) : 0

resource_id = var.private_subnets_ids[floor(count.index / length(local.private_subnet_tags_list))]
key = local.private_subnet_tags_list[count.index % length(local.private_subnet_tags_list)].key
value = local.private_subnet_tags_list[count.index % length(local.private_subnet_tags_list)].value
}

resource "aws_ec2_tag" "public_subnet_tags" {
count = var.shim ? length(var.public_subnets_ids) * length(local.public_subnet_tags_list) : 0

resource_id = var.public_subnets_ids[floor(count.index / length(local.public_subnet_tags_list))]
key = local.public_subnet_tags_list[count.index % length(local.public_subnet_tags_list)].key
value = local.public_subnet_tags_list[count.index % length(local.public_subnet_tags_list)].value
}
}
Loading