From 7ffc8b83c72cc3a5a02f14b5d72756df0f18dda8 Mon Sep 17 00:00:00 2001 From: mcgin314 Date: Fri, 13 Sep 2024 07:32:45 -0400 Subject: [PATCH 1/2] Add finops tags to karpenter provisioned nodes --- ec2_node_class.yaml.tpl | 3 +++ main.tf | 1 + 2 files changed, 4 insertions(+) diff --git a/ec2_node_class.yaml.tpl b/ec2_node_class.yaml.tpl index 74c4172..2a8deef 100644 --- a/ec2_node_class.yaml.tpl +++ b/ec2_node_class.yaml.tpl @@ -58,3 +58,6 @@ spec: # Optional, configures detailed monitoring for the instance detailedMonitoring: true + + # Add finops tags to karpenter provisioned nodes + tags: ${tags} diff --git a/main.tf b/main.tf index 8831008..2860b72 100644 --- a/main.tf +++ b/main.tf @@ -200,6 +200,7 @@ resource "kubectl_manifest" "karpenter_ec2_node_class" { ] yaml_body = templatefile("${path.module}/ec2_node_class.yaml.tpl", { cluster_name = var.cluster_name + tags = jsonencode(var.tags) amd_ami_family = "Bottlerocket" amd_ami_alias = "bottlerocket" }) From 0b9b0adfc13532dbd305b57b8e571e68fe875907 Mon Sep 17 00:00:00 2001 From: mcgin314 Date: Fri, 13 Sep 2024 08:17:40 -0400 Subject: [PATCH 2/2] Lookup tags to pass to karpenter CRD --- main.tf | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 2860b72..c010bbc 100644 --- a/main.tf +++ b/main.tf @@ -192,6 +192,9 @@ resource "aws_iam_service_linked_role" "ec2_spot" { aws_service_name = "spot.amazonaws.com" } +# Get the default tags from the provider +data "aws_default_tags" "default_tags" {} + # SHOULD PROBABLY PUT THESE OBJECTS INTO A HELM CHART # Create karpenter default resource "kubectl_manifest" "karpenter_ec2_node_class" { @@ -200,7 +203,7 @@ resource "kubectl_manifest" "karpenter_ec2_node_class" { ] yaml_body = templatefile("${path.module}/ec2_node_class.yaml.tpl", { cluster_name = var.cluster_name - tags = jsonencode(var.tags) + tags = jsonencode(data.aws_default_tags.default_tags.tags) amd_ami_family = "Bottlerocket" amd_ami_alias = "bottlerocket" })