Skip to content

Commit aa3bdf1

Browse files
authored
feat: Add irsa_tag_values variable (#2584)
1 parent 0f9d9fa commit aa3bdf1

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

modules/karpenter/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ No modules.
168168
| <a name="input_irsa_ssm_parameter_arns"></a> [irsa\_ssm\_parameter\_arns](#input\_irsa\_ssm\_parameter\_arns) | List of SSM Parameter ARNs that contain AMI IDs launched by Karpenter | `list(string)` | <pre>[<br> "arn:aws:ssm:*:*:parameter/aws/service/*"<br>]</pre> | no |
169169
| <a name="input_irsa_subnet_account_id"></a> [irsa\_subnet\_account\_id](#input\_irsa\_subnet\_account\_id) | Account ID of where the subnets Karpenter will utilize resides. Used when subnets are shared from another account | `string` | `""` | no |
170170
| <a name="input_irsa_tag_key"></a> [irsa\_tag\_key](#input\_irsa\_tag\_key) | Tag key (`{key = value}`) applied to resources launched by Karpenter through the Karpenter provisioner | `string` | `"karpenter.sh/discovery"` | no |
171+
| <a name="input_irsa_tag_values"></a> [irsa\_tag\_values](#input\_irsa\_tag\_values) | Tag values (`{key = value}`) applied to resources launched by Karpenter through the Karpenter provisioner. Defaults to cluster name when not set. | `list(string)` | `null` | no |
171172
| <a name="input_irsa_tags"></a> [irsa\_tags](#input\_irsa\_tags) | A map of additional tags to add the the IAM role for service accounts | `map(any)` | `{}` | no |
172173
| <a name="input_irsa_use_name_prefix"></a> [irsa\_use\_name\_prefix](#input\_irsa\_use\_name\_prefix) | Determines whether the IAM role for service accounts name (`irsa_name`) is used as a prefix | `bool` | `true` | no |
173174
| <a name="input_policies"></a> [policies](#input\_policies) | Policies to attach to the IAM role in `{'static_name' = 'policy_arn'}` format | `map(string)` | `{}` | no |

modules/karpenter/main.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ resource "aws_iam_role" "irsa" {
6363
tags = merge(var.tags, var.irsa_tags)
6464
}
6565

66+
locals {
67+
irsa_tag_values = coalescelist([var.cluster_name], var.irsa_tag_values)
68+
}
69+
6670
data "aws_iam_policy_document" "irsa" {
6771
count = local.create_irsa ? 1 : 0
6872

@@ -97,7 +101,7 @@ data "aws_iam_policy_document" "irsa" {
97101
condition {
98102
test = "StringEquals"
99103
variable = "ec2:ResourceTag/${var.irsa_tag_key}"
100-
values = [var.cluster_name]
104+
values = local.irsa_tag_values
101105
}
102106
}
103107

@@ -110,7 +114,7 @@ data "aws_iam_policy_document" "irsa" {
110114
condition {
111115
test = "StringEquals"
112116
variable = "ec2:ResourceTag/${var.irsa_tag_key}"
113-
values = [var.cluster_name]
117+
values = local.irsa_tag_values
114118
}
115119
}
116120

modules/karpenter/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ variable "irsa_tag_key" {
8686
default = "karpenter.sh/discovery"
8787
}
8888

89+
variable "irsa_tag_values" {
90+
description = "Tag values (`{key = value}`) applied to resources launched by Karpenter through the Karpenter provisioner. Defaults to cluster name when not set."
91+
type = list(string)
92+
default = null
93+
}
94+
8995
variable "irsa_ssm_parameter_arns" {
9096
description = "List of SSM Parameter ARNs that contain AMI IDs launched by Karpenter"
9197
type = list(string)

0 commit comments

Comments
 (0)