@@ -6,67 +6,70 @@ locals {
66 github_organizations = toset ([
77 for repo in var . github_repositories : split (" /" , repo)[0 ]
88 ])
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
1212}
1313
1414resource "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
1816 description = " Role assumed by the GitHub OIDC provider."
1917 force_detach_policies = var. force_detach_policies
2018 max_session_duration = var. max_session_duration
2119 name = var. iam_role_name
2220 path = var. iam_role_path
2321 permissions_boundary = var. iam_role_permissions_boundary
2422 tags = var. tags
25-
2623}
2724
2825resource "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
3331}
3432
3533resource "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
3735
3836 policy_arn = " arn:${ local . partition } :iam::aws:policy/AdministratorAccess"
39- role = aws_iam_role. github [ 0 ] . id
37+ role = aws_iam_role. github . id
4038}
4139
4240resource "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
4442
4543 policy_arn = " arn:${ local . partition } :iam::aws:policy/ReadOnlyAccess"
46- role = aws_iam_role. github [ 0 ] . id
44+ role = aws_iam_role. github . id
4745}
4846
4947resource "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 )
5149
5250 policy_arn = var. iam_role_policy_arns [count . index ]
53- role = aws_iam_role. github [ 0 ] . id
51+ role = aws_iam_role. github . id
5452}
5553
5654resource "aws_iam_openid_connect_provider" "github" {
57- count = var. enabled && var . create_oidc_provider ? 1 : 0
55+ count = var. create_oidc_provider ? 1 : 0
5856
5957 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) ],
6159 [local . audience ],
6260 )
6361
6462 tags = var. tags
65- url = " https://token.actions.githubusercontent.com %{ if var . enterprise_slug != " " } / ${ var . enterprise_slug } %{ endif } "
63+
6664 thumbprint_list = toset (
6765 concat (
6866 [data . tls_certificate . github . certificates [0 ]. sha1_fingerprint ],
6967 var. additional_thumbprints ,
7068 )
7169 )
70+
71+ url = format (
72+ " https://token.actions.githubusercontent.com%v" ,
73+ var. enterprise_slug != " " ? " /${ var . enterprise_slug } " : " " ,
74+ )
7275}
0 commit comments