Skip to content

Instantly share code, notes, and snippets.

@yuya-takeyama
Created September 18, 2021 16:47
Show Gist options
  • Save yuya-takeyama/57caca28d7dd1aaca73a525e30423ed5 to your computer and use it in GitHub Desktop.
Save yuya-takeyama/57caca28d7dd1aaca73a525e30423ed5 to your computer and use it in GitHub Desktop.
resource "aws_iam_openid_connect_provider" "github" {
url = "https://vstoken.actions.githubusercontent.com"
client_id_list = ["sigstore"]
thumbprint_list = ["a031c46782e6e6c662c2c87c76da9aa62ccabd8e"]
}
data "aws_iam_policy_document" "oidc-assume-role-with-web-identity" {
statement {
actions = ["sts:AssumeRoleWithWebIdentity"]
principals {
type = "Federated"
identifiers = [aws_iam_openid_connect_provider.github.arn]
}
condition {
test = "StringLike"
variable = "vstoken.actions.githubusercontent.com:sub"
values = [
"repo:yuya-takeyama/REPONAME:*",
]
}
}
}
resource "aws_iam_role" "main" {
name = "github-actions-terraform"
assume_role_policy = data.aws_iam_policy_document.oidc-assume-role-with-web-identity.json
}
data "aws_iam_policy_document" "get-caller-identity" {
statement {
actions = ["sts:GetCallerIdentity"]
resources = ["*"]
}
}
resource "aws_iam_policy" "main" {
name = "github-actions-terraform"
policy = data.aws_iam_policy_document.get-caller-identity.json
}
resource "aws_iam_role_policy_attachment" "main" {
role = aws_iam_role.main.name
policy_arn = aws_iam_policy.main.arn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment