@@ -6,67 +6,70 @@ locals {
6
6
github_organizations = toset ([
7
7
for repo in var . github_repositories : split (" /" , repo)[0 ]
8
8
])
9
- dns_suffix = data. aws_partition . current . dns_suffix
10
- oidc_provider_arn = var. enabled ? (var . create_oidc_provider ? aws_iam_openid_connect_provider. github [0 ]. arn : data. aws_iam_openid_connect_provider . github [0 ]. arn ) : " "
11
- partition = data. aws_partition . current . partition
9
+ dns_suffix = data. aws_partition . this . dns_suffix
10
+ oidc_provider_arn = var. create_oidc_provider ? aws_iam_openid_connect_provider. github [0 ]. arn : data. aws_iam_openid_connect_provider . github [0 ]. arn
11
+ partition = data. aws_partition . this . partition
12
12
}
13
13
14
14
resource "aws_iam_role" "github" {
15
- count = var. enabled ? 1 : 0
16
-
17
- assume_role_policy = data. aws_iam_policy_document . assume_role [0 ]. json
15
+ assume_role_policy = data. aws_iam_policy_document . assume_role . json
18
16
description = " Role assumed by the GitHub OIDC provider."
19
17
force_detach_policies = var. force_detach_policies
20
18
max_session_duration = var. max_session_duration
21
19
name = var. iam_role_name
22
20
path = var. iam_role_path
23
21
permissions_boundary = var. iam_role_permissions_boundary
24
22
tags = var. tags
25
-
26
23
}
27
24
28
25
resource "aws_iam_role_policy" "inline_policies" {
29
- for_each = { for k , v in var . iam_role_inline_policies : k => v if var . enabled }
30
- name = each. key
31
- policy = each. value
32
- role = aws_iam_role. github [0 ]. id
26
+ for_each = { for k , v in var . iam_role_inline_policies : k => v }
27
+
28
+ name = each. key
29
+ policy = each. value
30
+ role = aws_iam_role. github . id
33
31
}
34
32
35
33
resource "aws_iam_role_policy_attachment" "admin" {
36
- count = var. enabled && var . dangerously_attach_admin_policy ? 1 : 0
34
+ count = var. dangerously_attach_admin_policy ? 1 : 0
37
35
38
36
policy_arn = " arn:${ local . partition } :iam::aws:policy/AdministratorAccess"
39
- role = aws_iam_role. github [ 0 ] . id
37
+ role = aws_iam_role. github . id
40
38
}
41
39
42
40
resource "aws_iam_role_policy_attachment" "read_only" {
43
- count = var. enabled && var . attach_read_only_policy ? 1 : 0
41
+ count = var. attach_read_only_policy ? 1 : 0
44
42
45
43
policy_arn = " arn:${ local . partition } :iam::aws:policy/ReadOnlyAccess"
46
- role = aws_iam_role. github [ 0 ] . id
44
+ role = aws_iam_role. github . id
47
45
}
48
46
49
47
resource "aws_iam_role_policy_attachment" "custom" {
50
- count = var . enabled ? length (var. iam_role_policy_arns ) : 0
48
+ count = length (var. iam_role_policy_arns )
51
49
52
50
policy_arn = var. iam_role_policy_arns [count . index ]
53
- role = aws_iam_role. github [ 0 ] . id
51
+ role = aws_iam_role. github . id
54
52
}
55
53
56
54
resource "aws_iam_openid_connect_provider" "github" {
57
- count = var. enabled && var . create_oidc_provider ? 1 : 0
55
+ count = var. create_oidc_provider ? 1 : 0
58
56
59
57
client_id_list = concat (
60
- [for org in local . github_organizations : " https://github.com/${ org } " ],
58
+ [for org in local . github_organizations : format ( " https://github.com/%v " , org) ],
61
59
[local . audience ],
62
60
)
63
61
64
62
tags = var. tags
65
- url = " https://token.actions.githubusercontent.com %{ if var . enterprise_slug != " " } / ${ var . enterprise_slug } %{ endif } "
63
+
66
64
thumbprint_list = toset (
67
65
concat (
68
66
[data . tls_certificate . github . certificates [0 ]. sha1_fingerprint ],
69
67
var. additional_thumbprints ,
70
68
)
71
69
)
70
+
71
+ url = format (
72
+ " https://token.actions.githubusercontent.com%v" ,
73
+ var. enterprise_slug != " " ? " /${ var . enterprise_slug } " : " " ,
74
+ )
72
75
}
0 commit comments