Created
January 24, 2022 15:23
-
-
Save sathya-potharla/9722c77edfb53c4ceae1cd465eecca0a to your computer and use it in GitHub Desktop.
oidc_role
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
locals { | |
github_repos = toset( [for repo in var.github_lambda_repos : join("", ["repo:santander-group-uk/", repo, ":*"])] ) | |
} | |
## Role for the service account | |
resource "aws_iam_role" "Github-EKS-Deploy" { | |
name = "local-github-eks-deploy-ole" | |
permissions_boundary = "arn:aws:iam::${var.account_id}:policy/AccountAutomation_policy_and_boundary" | |
description = "role to deploy to eks" | |
path = "/" | |
force_detach_policies = true | |
assume_role_policy = jsonencode( | |
{ | |
"Version" : "2012-10-17", | |
"Statement" : [ | |
{ | |
"Effect" : "Allow", | |
"Principal" : { | |
"Federated" : "arn:aws:iam::${var.account_id}:oidc-provider/token.actions.githubusercontent.com" | |
}, | |
"Action" : "sts:AssumeRoleWithWebIdentity", | |
"Condition" : { | |
"ForAnyValue:StringLike" : { | |
"token.actions.githubusercontent.com:sub" : local.github_repos | |
} | |
} | |
} | |
] | |
} | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Principal": { | |
"Service": [ | |
"eks.amazonaws.com" | |
] | |
}, | |
"Action": "sts:AssumeRole" | |
} | |
] | |
} | |
) | |
} | |
resource "aws_iam_policy" "eks_deploy_policy" { | |
name = "local-eks-deploy-Policy" | |
policy = file("${path.module}/policies/eks_deploy_policy.json") | |
} | |
resource "aws_iam_role_policy_attachment" "eks_deploy" { | |
policy_arn = aws_iam_policy.eks_deploy_policy.arn | |
role = aws_iam_role.github-eks-deploy.name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment