Skip to content

Commit 1c2f946

Browse files
authored
Dynamic Assume Role Creation (#421) (#426)
1 parent 9241313 commit 1c2f946

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

terraform/eks/container-insights-agent/service_account_fargate.yml renamed to terraform/eks/container-insights-agent/service_account_fargate.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ metadata:
44
name: adot-collector-service-account
55
namespace: default
66
annotations:
7-
eks.amazonaws.com/role-arn: arn:aws:iam::611364707713:role/ServiceAccount-eks-test-aoc-role
7+
eks.amazonaws.com/role-arn: ${RoleArn}

terraform/eks/container_insights_agent.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,14 @@ data "template_file" "daemonset_file" {
3131
}
3232

3333
resource "kubectl_manifest" "service_account" {
34-
count = var.aoc_base_scenario == "infra" && var.deployment_type == "fargate" ? 1 : 0
35-
yaml_body = file("./container-insights-agent/service_account_fargate.yml")
34+
count = var.aoc_base_scenario == "infra" && var.deployment_type == "fargate" ? 1 : 0
35+
yaml_body = templatefile("./container-insights-agent/service_account_fargate.tpl",
36+
{
37+
RoleArn : module.iam_assumable_role_admin.iam_role_arn
38+
})
39+
depends_on = [
40+
module.iam_assumable_role_admin
41+
]
3642
}
3743

3844
resource "kubectl_manifest" "cluster_role" {

terraform/eks/main.tf

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,28 @@ resource "kubernetes_service_account" "aoc-fargate-role" {
116116
name = "aoc-fargate-role-${module.common.testing_id}"
117117
namespace = "default"
118118
annotations = {
119-
"eks.amazonaws.com/role-arn" : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/ServiceAccount-eks-test-aoc-role"
119+
"eks.amazonaws.com/role-arn" : module.iam_assumable_role_admin.iam_role_arn
120120
}
121121
}
122122

123123
automount_service_account_token = true
124+
depends_on = [module.iam_assumable_role_admin]
125+
}
126+
127+
module "iam_assumable_role_admin" {
128+
create_role = true
129+
130+
role_name = "aoc-eks-assume-role-${module.common.testing_id}"
131+
132+
provider_url = trimprefix(data.aws_eks_cluster.testing_cluster.identity[0].oidc[0].issuer, "https://")
133+
134+
role_policy_arns = [
135+
"arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy",
136+
"arn:aws:iam::aws:policy/AWSXrayFullAccess",
137+
"arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess",
138+
]
139+
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role-with-oidc"
140+
version = "4.7.0"
124141
}
125142

126143
resource "kubernetes_cluster_role_binding" "aoc-role-binding" {

0 commit comments

Comments
 (0)