Skip to content

Commit

Permalink
Merge pull request #184 from dandi/add-tfcloud-oidc-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
danlamanna authored Jul 30, 2024
2 parents 0bc9a6d + c177402 commit b547159
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions terraform/aws_oidc.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
data "tls_certificate" "tfc_certificate" {
url = "https://app.terraform.io"
}

resource "aws_iam_openid_connect_provider" "tfc_provider" {
url = data.tls_certificate.tfc_certificate.url
client_id_list = ["aws.workload.identity"]
thumbprint_list = [data.tls_certificate.tfc_certificate.certificates[0].sha1_fingerprint]
}

resource "aws_iam_role" "tfc_role" {
name = "terraform-cloud-role"

assume_role_policy = jsonencode({
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Principal" : {
"Federated" : "${aws_iam_openid_connect_provider.tfc_provider.arn}"
},
"Action" : "sts:AssumeRoleWithWebIdentity",
"Condition" : {
"StringEquals" : {
"app.terraform.io:aud" : "${one(aws_iam_openid_connect_provider.tfc_provider.client_id_list)}"
},
"StringLike" : {
"app.terraform.io:sub" : "organization:dandi:project:Default Project:workspace:dandi-prod:run_phase:*"
}
}
}
]
})
}

data "aws_iam_policy" "administrator_access" {
arn = "arn:aws:iam::aws:policy/AdministratorAccess"
}

resource "aws_iam_role_policy_attachment" "tfc_policy_attachment" {
role = aws_iam_role.tfc_role.name
policy_arn = data.aws_iam_policy.administrator_access.arn
}

0 comments on commit b547159

Please sign in to comment.