forked from sohanso/Backend-Terraform-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.tf
38 lines (33 loc) · 1.13 KB
/
role.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
resource "aws_iam_openid_connect_provider" "default" {
url = "https://token.actions.githubusercontent.com"
client_id_list = [ "sts.amazonaws.com" ]
thumbprint_list = ["6938fd4d98bab03faadb97b34396831e3780aea1"]
}
data "aws_iam_policy_document" "github_access_policy" {
statement {
sid = "github"
actions = ["sts:AssumeRoleWithWebIdentity"]
principals {
type = "Federated"
identifiers = [aws_iam_openid_connect_provider.default.arn]
}
condition {
test = "StringEquals"
variable = "token.actions.githubusercontent.com:aud"
values = ["sts.amazonaws.com"]
}
condition {
test = "StringLike"
variable = "token.actions.githubusercontent.com:sub"
values = ["repo:sohanso/*:*"]
}
}
}
resource "aws_iam_role" "gitub_actions" {
name = "github-actions-oidc"
assume_role_policy = data.aws_iam_policy_document.github_access_policy.json
}
resource "aws_iam_role_policy_attachment" "github_actions_attachment" {
role = aws_iam_role.gitub_actions.name
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
}