Skip to content

🐛 fix(subnet-tagging): updated subnet id to use existing tags created… #9

Merged
merged 1 commit into from
Oct 10, 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
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ The module deploys Karpenter needed AWS resources, namely in IAM. It copies the
| Name | Source | Version |
|------|--------|---------|
| <a name="module_images"></a> [images](#module\_images) | git@github.e.it.census.gov:terraform-modules/aws-ecr-copy-images.git/ | tf-upgrade |
| <a name="module_karpenter_resources"></a> [karpenter\_resources](#module\_karpenter\_resources) | git@github.e.it.census.gov:SCT-Engineering/terraform-aws-eks.git//modules/karpenter | v20.24.1 |
| <a name="module_karpenter_resources"></a> [karpenter\_resources](#module\_karpenter\_resources) | git@github.e.it.census.gov:SCT-Engineering/terraform-aws-eks.git//modules/karpenter | v20.24.3 |

## Resources

| Name | Type |
|------|------|
| [aws_ec2_tag.container_subnets](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ec2_tag) | resource |
| [aws_iam_instance_profile.karpenter_node_instance_profile](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_instance_profile) | resource |
| [helm_release.karpenter](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
| [kubectl_manifest.karpenter_ec2_node_class](https://registry.terraform.io/providers/gavinbunney/kubectl/latest/docs/resources/manifest) | resource |
Expand All @@ -51,7 +50,6 @@ The module deploys Karpenter needed AWS resources, namely in IAM. It copies the
| [aws_default_tags.default_tags](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/default_tags) | data source |
| [aws_ecr_image.karpenter_image](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_image) | data source |
| [aws_ecr_image.kubectl_image](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecr_image) | data source |
| [aws_subnets.container_subnets](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/subnets) | data source |

## Inputs

Expand All @@ -69,7 +67,6 @@ The module deploys Karpenter needed AWS resources, namely in IAM. It copies the
| <a name="input_region"></a> [region](#input\_region) | AWS region | `string` | n/a | yes |
| <a name="input_subnets_name"></a> [subnets\_name](#input\_subnets\_name) | Define the name of the subnets to be used by this cluster | `string` | `"*-container-*"` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | AWS Tags to apply to appropriate resources | `map(string)` | `{}` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | vpc to use for subnet tags | `string` | `""` | no |

## Outputs

Expand Down
4 changes: 2 additions & 2 deletions ec2_node_class.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ spec:
# Within a single term, all conditions are ANDed
subnetSelectorTerms:
- tags:
Name: "*-container-*"
# karpenter.sh/discovery: "${cluster_name}"
Name: "${subnets_name}"
"kubernetes.io/cluster/${cluster_name}": "shared"

# Required, discovers security groups to attach to instances
# Each term in the array of securityGroupSelectorTerms is ORed together
Expand Down
23 changes: 2 additions & 21 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
locals {
namespace = "karpenter"
container_subnets_name = var.subnets_name
vpc_id = var.vpc_id
}

data "aws_subnets" "container_subnets" {
filter {
name = "tag:Name"
values = [local.container_subnets_name]
}
filter {
name = "vpc-id"
values = [local.vpc_id]
}
}

# Replicating from here: https://github.e.it.census.gov/SCT-Engineering/terraform-aws-eks/tree/master/modules/karpenter
# Karpenter IRSA roles and policies
module "karpenter_resources" {
source = "git@github.e.it.census.gov:SCT-Engineering/terraform-aws-eks.git//modules/karpenter?ref=v20.24.1"
source = "git@github.e.it.census.gov:SCT-Engineering/terraform-aws-eks.git//modules/karpenter?ref=v20.24.3"

cluster_name = var.cluster_name
enable_irsa = true
Expand All @@ -33,14 +21,6 @@ module "karpenter_resources" {
tags = var.tags
}

# Tag subnets for Karpenter Discovery
resource "aws_ec2_tag" "container_subnets" {
for_each = toset(data.aws_subnets.container_subnets.ids)
resource_id = each.value
key = "karpenter.sh/discovery"
value = var.cluster_name
}

# Install Karpenter
data "aws_ecr_image" "karpenter_image" {
depends_on = [
Expand Down Expand Up @@ -195,6 +175,7 @@ resource "kubectl_manifest" "karpenter_ec2_node_class" {
tags = jsonencode(data.aws_default_tags.default_tags.tags)
amd_ami_family = "Bottlerocket"
amd_ami_alias = "bottlerocket"
subnets_name = local.container_subnets_name
})
}

Expand Down
6 changes: 0 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,3 @@ variable "tags" {
type = map(string)
default = {}
}

variable "vpc_id" {
description = "vpc to use for subnet tags"
type = string
default = ""
}