Skip to content

Commit cf111b1

Browse files
committed
Fixed missing documented 'oidc_provider_arn' variable
1 parent 864350c commit cf111b1

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ No modules.
112112
| Name | Description | Type | Default | Required |
113113
|------|-------------|------|---------|:--------:|
114114
| <a name="input_create_oidc_provider"></a> [create\_oidc\_provider](#input\_create\_oidc\_provider) | Whether or not to create the associated oidc provider. If false, variable 'oidc\_provider\_arn' is required | `bool` | `true` | no |
115+
| <a name="input_oidc_provider_arn"></a> [oidc\_provider\_arn](#input\_oidc\_provider\_arn) | ARN of the OIDC provider to use. Required if 'create_oidc_provider' is false | `string` | `null` | no |
115116
| <a name="input_create_oidc_role"></a> [create\_oidc\_role](#input\_create\_oidc\_role) | Whether or not to create the OIDC attached role | `bool` | `true` | no |
116117
| <a name="input_github_thumbprint"></a> [github\_thumbprint](#input\_github\_thumbprint) | GitHub OpenID TLS certificate thumbprint. | `string` | `"6938fd4d98bab03faadb97b34396831e3780aea1"` | no |
117118
| <a name="input_max_session_duration"></a> [max\_session\_duration](#input\_max\_session\_duration) | Maximum session duration in seconds. | `number` | `3600` | no |

main.tf

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ resource "aws_iam_openid_connect_provider" "this" {
1515
}
1616

1717
resource "aws_iam_role" "this" {
18-
count = var.create_oidc_provider && var.create_oidc_role ? 1 : 0
18+
count = var.create_oidc_role ? 1 : 0
1919
name = var.role_name
2020
description = var.role_description
2121
max_session_duration = var.max_session_duration
22-
assume_role_policy = join("", data.aws_iam_policy_document.this.*.json)
22+
assume_role_policy = join("", data.aws_iam_policy_document.this[0].*.json)
2323
tags = var.tags
2424
# path = var.iam_role_path
2525
# permissions_boundary = var.iam_role_permissions_boundary
@@ -36,27 +36,24 @@ resource "aws_iam_role_policy_attachment" "attach" {
3636
}
3737

3838
data "aws_iam_policy_document" "this" {
39+
count = var.create_oidc_role ? 1 : 0
40+
41+
statement {
42+
actions = ["sts:AssumeRoleWithWebIdentity"]
43+
effect = "Allow"
44+
45+
condition {
46+
test = "StringLike"
47+
values = [
48+
for repo in var.repositories :
49+
"repo:%{if length(regexall(":+", repo)) > 0}${repo}%{else}${repo}:*%{endif}"
50+
]
51+
variable = "token.actions.githubusercontent.com:sub"
52+
}
3953

40-
dynamic "statement" {
41-
for_each = aws_iam_openid_connect_provider.this
42-
43-
content {
44-
actions = ["sts:AssumeRoleWithWebIdentity"]
45-
effect = "Allow"
46-
47-
condition {
48-
test = "StringLike"
49-
values = [
50-
for repo in var.repositories :
51-
"repo:%{if length(regexall(":+", repo)) > 0}${repo}%{else}${repo}:*%{endif}"
52-
]
53-
variable = "token.actions.githubusercontent.com:sub"
54-
}
55-
56-
principals {
57-
identifiers = [statement.value.arn]
58-
type = "Federated"
59-
}
54+
principals {
55+
identifiers = [try(aws_iam_openid_connect_provider.this[0].arn, var.oidc_provider_arn)]
56+
type = "Federated"
6057
}
6158
}
6259
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ variable "create_oidc_provider" {
44
default = true
55
}
66

7+
variable "oidc_provider_arn" {
8+
description = "ARN of the OIDC provider to use. Required if 'create_oidc_provider' is false"
9+
type = string
10+
default = null
11+
}
12+
713
variable "create_oidc_role" {
814
description = "Whether or not to create the OIDC attached role"
915
type = bool

0 commit comments

Comments
 (0)