Team,
I am trying to create a IAM assume policy in JSON format from a map. I will be grateful if someone can help me here.
locals {
test = {
cluster1 = {
ns = "ns1"
oidc = "oidc1"
},
cluster2 = {
ns = "ns2"
oidc = "oidc2"
},
cluster3 = {
ns = "ns3"
oidc = "oidc3"
}
}
}
Expected Output
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::12312:oidc-provider/oidc.eks.us-west-2.amazonaws.com/id/<oidc1>"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringLike": {
"oidc.eks.us-west-2.amazonaws.com/id/<oidc1>:sub": "system:serviceaccount:<ns1>:*"
}
}
},
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::12312:oidc-provider/oidc.eks.us-west-2.amazonaws.com/id/<oidc2>"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringLike": {
"oidc.eks.us-west-2.amazonaws.com/id/<oidc2>:sub": "system:serviceaccount:<ns2>:*"
}
}
},
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::12312:oidc-provider/oidc.eks.us-west-2.amazonaws.com/id/<oidc3>"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringLike": {
"oidc.eks.us-west-2.amazonaws.com/id/<oidc3>:sub": "system:serviceaccount:<ns3>:*"
}
}
},
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
The above expected policy will then be attached to a IAM role.