diff --git a/README.md b/README.md index 7129f45..ee72a80 100644 --- a/README.md +++ b/README.md @@ -35,13 +35,12 @@ The module deploys Karpenter needed AWS resources, namely in IAM. It copies the | Name | Source | Version | |------|--------|---------| | [images](#module\_images) | git@github.e.it.census.gov:terraform-modules/aws-ecr-copy-images.git/ | tf-upgrade | -| [karpenter\_resources](#module\_karpenter\_resources) | git@github.e.it.census.gov:SCT-Engineering/terraform-aws-eks.git//modules/karpenter | v20.24.1 | +| [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 | @@ -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 @@ -69,7 +67,6 @@ The module deploys Karpenter needed AWS resources, namely in IAM. It copies the | [region](#input\_region) | AWS region | `string` | n/a | yes | | [subnets\_name](#input\_subnets\_name) | Define the name of the subnets to be used by this cluster | `string` | `"*-container-*"` | no | | [tags](#input\_tags) | AWS Tags to apply to appropriate resources | `map(string)` | `{}` | no | -| [vpc\_id](#input\_vpc\_id) | vpc to use for subnet tags | `string` | `""` | no | ## Outputs diff --git a/ec2_node_class.yaml.tpl b/ec2_node_class.yaml.tpl index 2a8deef..baf320e 100644 --- a/ec2_node_class.yaml.tpl +++ b/ec2_node_class.yaml.tpl @@ -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 diff --git a/main.tf b/main.tf index 5d8e398..3343453 100644 --- a/main.tf +++ b/main.tf @@ -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 @@ -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 = [ @@ -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 }) } diff --git a/variables.tf b/variables.tf index 3721145..d73f57e 100644 --- a/variables.tf +++ b/variables.tf @@ -65,9 +65,3 @@ variable "tags" { type = map(string) default = {} } - -variable "vpc_id" { - description = "vpc to use for subnet tags" - type = string - default = "" -}