Skip to content

Commit

Permalink
feat(iam): update IAM policy ARNs to use dynamic AWS partition
Browse files Browse the repository at this point in the history
feat(iam): replace static AWS partition with variable for resource ARNs
  • Loading branch information
Aleksandr Cupacenko committed Dec 12, 2024
1 parent 21f7af9 commit 580a71b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
26 changes: 13 additions & 13 deletions iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ data "aws_iam_policy_document" "this" {
actions = [
"ec2:CreateTags"
]
resources = ["arn:aws:ec2:*:*:security-group/*"]
resources = ["arn:${var.aws_partition}:ec2:*:*:security-group/*"]
condition {
test = "StringEquals"
variable = "ec2:CreateAction"
Expand All @@ -120,7 +120,7 @@ data "aws_iam_policy_document" "this" {
"ec2:CreateTags",
"ec2:DeleteTags"
]
resources = ["arn:aws:ec2:*:*:security-group/*"]
resources = ["arn:${var.aws_partition}:ec2:*:*:security-group/*"]
condition {
test = "Null"
variable = "aws:RequestTag/elbv2.k8s.aws/cluster"
Expand Down Expand Up @@ -180,9 +180,9 @@ data "aws_iam_policy_document" "this" {
"elasticloadbalancing:RemoveTags"
]
resources = [
"arn:aws:elasticloadbalancing:*:*:targetgroup/*/*",
"arn:aws:elasticloadbalancing:*:*:loadbalancer/net/*/*",
"arn:aws:elasticloadbalancing:*:*:loadbalancer/app/*/*"
"arn:${var.aws_partition}:elasticloadbalancing:*:*:targetgroup/*/*",
"arn:${var.aws_partition}:elasticloadbalancing:*:*:loadbalancer/net/*/*",
"arn:${var.aws_partition}:elasticloadbalancing:*:*:loadbalancer/app/*/*"
]
condition {
test = "Null"
Expand All @@ -203,10 +203,10 @@ data "aws_iam_policy_document" "this" {
"elasticloadbalancing:RemoveTags"
]
resources = [
"arn:aws:elasticloadbalancing:*:*:listener/net/*/*/*",
"arn:aws:elasticloadbalancing:*:*:listener/app/*/*/*",
"arn:aws:elasticloadbalancing:*:*:listener-rule/net/*/*/*",
"arn:aws:elasticloadbalancing:*:*:listener-rule/app/*/*/*"
"arn:${var.aws_partition}:elasticloadbalancing:*:*:listener/net/*/*/*",
"arn:${var.aws_partition}:elasticloadbalancing:*:*:listener/app/*/*/*",
"arn:${var.aws_partition}:elasticloadbalancing:*:*:listener-rule/net/*/*/*",
"arn:${var.aws_partition}:elasticloadbalancing:*:*:listener-rule/app/*/*/*"
]
}

Expand All @@ -216,9 +216,9 @@ data "aws_iam_policy_document" "this" {
"elasticloadbalancing:AddTags"
]
resources = [
"arn:aws:elasticloadbalancing:*:*:targetgroup/*/*",
"arn:aws:elasticloadbalancing:*:*:loadbalancer/net/*/*",
"arn:aws:elasticloadbalancing:*:*:loadbalancer/app/*/*"
"arn:${var.aws_partition}:elasticloadbalancing:*:*:targetgroup/*/*",
"arn:${var.aws_partition}:elasticloadbalancing:*:*:loadbalancer/net/*/*",
"arn:${var.aws_partition}:elasticloadbalancing:*:*:loadbalancer/app/*/*"
]
condition {
test = "StringEquals"
Expand Down Expand Up @@ -263,7 +263,7 @@ data "aws_iam_policy_document" "this" {
"elasticloadbalancing:RegisterTargets",
"elasticloadbalancing:DeregisterTargets"
]
resources = ["arn:aws:elasticloadbalancing:*:*:targetgroup/*/*"]
resources = ["arn:${var.aws_partition}:elasticloadbalancing:*:*:targetgroup/*/*"]
}

statement {
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,9 @@ variable "helm_lint" {
default = false
description = "Run the helm chart linter during the plan"
}

variable "aws_partition" {
type = string
default = "aws"
description = "AWS partition in which the resources are located. Available values are `aws`, `aws-cn`, `aws-us-gov`"
}

0 comments on commit 580a71b

Please sign in to comment.