Skip to content

Commit

Permalink
feat: add a second identity for role assumtions
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Turrado <[email protected]>
  • Loading branch information
JorTurFer committed Oct 8, 2023
1 parent 050b252 commit d78c661
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
4 changes: 4 additions & 0 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ module "github_secrets" {
name = "TF_AWS_ACCOUNT_ID"
value = data.aws_caller_identity.current.account_id
},
{
name = "TF_AWS_WORKLOAD_ROLE"
value = module.aws_iam.workload_role_arn
},
{
name = "TF_GCP_SA_CREDENTIALS"
value = module.gcp_iam.e2e_user_credentials
Expand Down
57 changes: 56 additions & 1 deletion terraform/modules/aws/iam/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

locals {
workload_role_name = "keda-workload-1"
}

resource "aws_iam_user" "e2e_test" {
name = "e2e-test-user"
path = "/"
Expand Down Expand Up @@ -131,7 +136,7 @@ resource "aws_iam_policy" "policy" {
{
"Effect": "Allow",
"Action": "sqs:*",
"Resource": "arn:aws:sqs:*:589761922677:*"
"Resource": "arn:aws:sqs:regular-queue-*:589761922677:*"
},
{
"Effect": "Allow",
Expand All @@ -151,8 +156,58 @@ resource "aws_iam_policy" "policy" {
"arn:aws:kinesis:*:589761922677:*/*/consumer/*:*",
"arn:aws:kinesis:*:589761922677:stream/*"
]
},
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::*:role/${local.workload_role_name}"
}
]
}
EOF
}

resource "aws_iam_role" "workload_role" {
name = local.workload_role_name
tags = var.tags

assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}

resource "aws_iam_role_policy_attachment" "role_assignements" {
role = aws_iam_role.workload_role.name
policy_arn = aws_iam_policy.workload_role_policy.arn
}


resource "aws_iam_policy" "workload_role_policy" {
name = "e2e-test-assume-role-policy"
tags = var.tags

policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sqs:*",
"Resource": "arn:aws:sqs:asume-role-queue-*:589761922677:*"
},
]
}
EOF
}
6 changes: 5 additions & 1 deletion terraform/modules/aws/iam/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ output "e2e_user_access_key" {

output "e2e_user_secret_key" {
value = aws_iam_access_key.e2e_test.secret
}
}

output "workload_role_arn" {
value = aws_iam_role.workload_role.arn
}

0 comments on commit d78c661

Please sign in to comment.