Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
7 changes: 5 additions & 2 deletions modules/karpenter/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ data "aws_caller_identity" "current" {

locals {
account_id = try(data.aws_caller_identity.current[0].account_id, "")
dns_suffix = try(data.aws_partition.current[0].dns_suffix, "")
partition = try(data.aws_partition.current[0].partition, "")
region = try(data.aws_region.current[0].region, "")
}
Expand All @@ -25,6 +24,10 @@ locals {
create_iam_role = var.create && var.create_iam_role
}

data "aws_service_principal" "ec2" {
service_name = "ec2"
}

data "aws_iam_policy_document" "controller_assume_role" {
count = local.create_iam_role ? 1 : 0

Expand Down Expand Up @@ -271,7 +274,7 @@ data "aws_iam_policy_document" "node_assume_role" {

principals {
type = "Service"
identifiers = ["ec2.${local.dns_suffix}"]
identifiers = [data.aws_service_principal.ec2.name]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/karpenter/policy.tf
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ data "aws_iam_policy_document" "controller" {
condition {
test = "StringEquals"
variable = "iam:PassedToService"
values = distinct(["ec2.${local.dns_suffix}", "ec2.amazonaws.com"])
values = [data.aws_service_principal.ec2.name]
}
}

Expand Down