-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tf
More file actions
67 lines (56 loc) · 1.65 KB
/
Copy pathmain.tf
File metadata and controls
67 lines (56 loc) · 1.65 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
locals {
legacy_repository_refs = [
for repo in var.repository_names :
"repo:${var.github_username}/${repo}:*"
]
immutable_repository_refs = (
var.github_owner_id != null
? [
for repo in var.repository_names :
"repo:${var.github_username}@${var.github_owner_id}/${repo}@${var.github_repository_ids[repo]}:*"
if contains(keys(var.github_repository_ids), repo)
]
: []
)
repository_ref_list = concat(
local.legacy_repository_refs,
local.immutable_repository_refs
)
}
data "aws_iam_policy_document" "assume_role" {
statement {
effect = "Allow"
principals {
type = "Federated"
identifiers = ["arn:aws:iam::${var.aws_account_id}:oidc-provider/token.actions.githubusercontent.com"]
}
actions = ["sts:AssumeRoleWithWebIdentity"]
condition {
test = "StringLike"
variable = "token.actions.githubusercontent.com:sub"
values = local.repository_ref_list
}
condition {
test = "StringEquals"
variable = "token.actions.githubusercontent.com:aud"
values = ["sts.amazonaws.com"]
}
}
}
resource "aws_iam_openid_connect_provider" "github_oidc" {
url = "https://token.actions.githubusercontent.com"
client_id_list = [
"sts.amazonaws.com",
]
thumbprint_list = [
"6938fd4d98bab03faadb97b34396831e3780aea1"
]
}
resource "aws_iam_role" "github_action" {
name = var.role_name
assume_role_policy = data.aws_iam_policy_document.assume_role.json
}
resource "aws_iam_role_policy_attachment" "admin" {
role = aws_iam_role.github_action.name
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
}