Skip to content

Commit 2eb9470

Browse files
authored
chore!: Rename the enabled variable to create (#80)
1 parent 6c252cf commit 2eb9470

File tree

10 files changed

+50
-37
lines changed

10 files changed

+50
-37
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ jobs:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- name: Checkout code
21-
uses: actions/checkout@v4
21+
uses: actions/checkout@v5
2222
- name: Setup Terraform
2323
uses: hashicorp/setup-terraform@v3
2424
with:
25-
terraform_version: "1.10"
25+
terraform_version: "1.12"
2626
- name: Initialise with no backend
2727
run: terraform init -backend=false
2828
- name: Check formatting

.github/workflows/pr.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ jobs:
1818
runs-on: ubuntu-latest
1919
steps:
2020
- name: Checkout code
21-
uses: actions/checkout@v4
21+
uses: actions/checkout@v5
2222
- name: Setup Terraform
2323
uses: hashicorp/setup-terraform@v3
2424
with:
25-
terraform_version: "1.10"
25+
terraform_version: "1.12"
2626
- name: Initialise with no backend
2727
run: terraform init -backend=false
2828
- name: Check formatting

.github/workflows/pr_label.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout code
15-
uses: actions/checkout@v4
15+
uses: actions/checkout@v5
1616
- name: Apply context labels
1717
uses: actions/labeler@v5
1818
with:

.github/workflows/security.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
runs-on: ubuntu-latest
3535
steps:
3636
- name: Checkout code
37-
uses: actions/checkout@v4
37+
uses: actions/checkout@v5
3838
- name: Run tfsec
3939
uses: tfsec/tfsec-sarif-action@v0.1.4
4040
with:

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ between GitHub Actions workflows and AWS resources.
1313

1414
### Requirements
1515

16-
- [AWS Provider] 4.0+
17-
- [TLS Provider] 3.0+
18-
- [Terraform] 1.0+
16+
- [Terraform] 1.12+
1917

2018
### Installation and usage
2119

@@ -88,10 +86,10 @@ applied, the JWT will contain an updated `iss` claim.
8886
| additional_audiences | Additional OIDC audiences allowed to assume the role. | `list(string)` | `null` | no |
8987
| additional_thumbprints | Additional thumbprints for the OIDC provider. | `list(string)` | `[]` | no |
9088
| attach_read_only_policy | Enable/disable the attachment of the ReadOnly policy. | `bool` | `false` | no |
89+
| create | Enable/disable the creation of all resources. | `bool` | `true` | no |
9190
| create_iam_role | Enable/disable creation of the IAM role. | `bool` | `true` | no |
9291
| create_oidc_provider | Enable/disable the creation of the GitHub OIDC provider. | `bool` | `true` | no |
9392
| dangerously_attach_admin_policy | Enable/disable the attachment of the AdministratorAccess policy. | `bool` | `false` | no |
94-
| enabled | Enable/disable the creation of resources. | `bool` | `true` | no |
9593
| enterprise_slug | Enterprise slug for GitHub Enterprise Cloud customers. | `string` | `""` | no |
9694
| force_detach_policies | Force detachment of policies attached to the IAM role. | `bool` | `false` | no |
9795
| github_repositories | GitHub organization/repository names authorized to assume the role. | `list(string)` | n/a | yes |
@@ -130,9 +128,9 @@ Made available under the terms of the [MIT License].
130128
[complete example]: examples/complete
131129
[configuring openid connect in amazon web services]: https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services
132130
[creating openid connect (oidc) identity providers]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc.html
131+
[github actions – update on oidc integration with aws]: https://github.blog/changelog/2023-06-27-github-actions-update-on-oidc-integration-with-aws/
133132
[make]: https://www.gnu.org/software/make/
134133
[mit license]: LICENSE.md
135134
[obtaining the thumbprint for an openid connect identity provider]: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc_verify-thumbprint.html
136135
[terraform]: https://www.terraform.io
137136
[tls provider]: https://registry.terraform.io/providers/hashicorp/tls/latest/docs
138-
[github actions – update on oidc integration with aws]: https://github.blog/changelog/2023-06-27-github-actions-update-on-oidc-integration-with-aws/

data.tf

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
data "aws_partition" "this" {}
55

66
data "aws_iam_policy_document" "assume_role" {
7-
count = var.enabled && var.create_oidc_provider ? 1 : 0
7+
count = local.create_oidc_provider ? 1 : 0
8+
9+
version = "2012-10-17"
810

911
statement {
1012
actions = ["sts:AssumeRoleWithWebIdentity"]
@@ -33,12 +35,10 @@ data "aws_iam_policy_document" "assume_role" {
3335
type = "Federated"
3436
}
3537
}
36-
37-
version = "2012-10-17"
3838
}
3939

4040
data "aws_iam_openid_connect_provider" "github" {
41-
count = !var.create_oidc_provider ? 1 : 0
41+
count = !local.create_oidc_provider ? 1 : 0
4242

4343
url = format(
4444
"https://token.actions.githubusercontent.com%v",
@@ -47,5 +47,7 @@ data "aws_iam_openid_connect_provider" "github" {
4747
}
4848

4949
data "tls_certificate" "github" {
50+
count = local.create_oidc_provider ? 1 : 0
51+
5052
url = "https://token.actions.githubusercontent.com/.well-known/openid-configuration"
5153
}

main.tf

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,30 @@
22
// SPDX-License-Identifier: MIT
33

44
locals {
5+
create_iam_role = var.create && var.create_iam_role
6+
create_oidc_provider = var.create && var.create_oidc_provider
7+
8+
attach_read_only_policy = local.create_iam_role && var.attach_read_only_policy
9+
dangerously_attach_admin_policy = local.create_iam_role && var.dangerously_attach_admin_policy
10+
511
audience = format("sts.%v", local.dns_suffix)
12+
613
github_organizations = toset([
714
for repo in var.github_repositories : split("/", repo)[0]
815
])
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
16+
17+
dns_suffix = data.aws_partition.this.dns_suffix
18+
partition = data.aws_partition.this.partition
19+
20+
oidc_provider_arn = (
21+
var.create_oidc_provider ?
22+
aws_iam_openid_connect_provider.github[0].arn :
23+
data.aws_iam_openid_connect_provider.github[0].arn
24+
)
1225
}
1326

1427
resource "aws_iam_role" "github" {
15-
count = var.enabled && var.create_iam_role ? 1 : 0
28+
count = local.create_iam_role ? 1 : 0
1629

1730
assume_role_policy = data.aws_iam_policy_document.assume_role[0].json
1831
description = "Assumed by the GitHub OIDC provider."
@@ -33,21 +46,21 @@ resource "aws_iam_role_policy" "inline_policies" {
3346
}
3447

3548
resource "aws_iam_role_policy_attachment" "admin" {
36-
count = var.enabled && var.create_iam_role && var.dangerously_attach_admin_policy ? 1 : 0
49+
count = local.create_iam_role && var.dangerously_attach_admin_policy ? 1 : 0
3750

3851
policy_arn = "arn:${local.partition}:iam::aws:policy/AdministratorAccess"
3952
role = aws_iam_role.github[0].id
4053
}
4154

4255
resource "aws_iam_role_policy_attachment" "read_only" {
43-
count = var.enabled && var.create_iam_role && var.attach_read_only_policy ? 1 : 0
56+
count = local.create_iam_role && var.attach_read_only_policy ? 1 : 0
4457

4558
policy_arn = "arn:${local.partition}:iam::aws:policy/ReadOnlyAccess"
4659
role = aws_iam_role.github[0].id
4760
}
4861

4962
resource "aws_iam_role_policy_attachment" "custom" {
50-
count = var.enabled && var.create_iam_role ? length(var.iam_role_policy_arns) : 0
63+
count = local.create_iam_role ? length(var.iam_role_policy_arns) : 0
5164

5265
role = aws_iam_role.github[0].id
5366
policy_arn = format(
@@ -57,7 +70,7 @@ resource "aws_iam_role_policy_attachment" "custom" {
5770
}
5871

5972
resource "aws_iam_openid_connect_provider" "github" {
60-
count = var.create_oidc_provider ? 1 : 0
73+
count = local.create_oidc_provider ? 1 : 0
6174

6275
client_id_list = concat(
6376
[for org in local.github_organizations : format("https://github.com/%v", org)],
@@ -68,7 +81,7 @@ resource "aws_iam_openid_connect_provider" "github" {
6881

6982
thumbprint_list = toset(
7083
concat(
71-
[data.tls_certificate.github.certificates[0].sha1_fingerprint],
84+
[data.tls_certificate.github[0].certificates[0].sha1_fingerprint],
7285
var.additional_thumbprints,
7386
)
7487
)

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
output "iam_role_arn" {
55
description = "The ARN of the IAM role."
6-
value = var.enabled && var.create_iam_role ? aws_iam_role.github[0].arn : ""
6+
value = var.create && var.create_iam_role ? aws_iam_role.github[0].arn : ""
77
}
88

99
output "iam_role_name" {
1010
description = "The name of the IAM role."
11-
value = var.enabled && var.create_iam_role ? aws_iam_role.github[0].name : ""
11+
value = var.create && var.create_iam_role ? aws_iam_role.github[0].name : ""
1212
}
1313

1414
output "oidc_provider_arn" {

variables.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ variable "attach_read_only_policy" {
2424
type = bool
2525
}
2626

27-
variable "create_oidc_provider" {
27+
variable "create" {
2828
default = true
29-
description = "Enable/disable the creation of the GitHub OIDC provider."
29+
description = "Enable/disable the creation of all resources."
3030
type = bool
3131
}
3232

@@ -36,15 +36,15 @@ variable "create_iam_role" {
3636
type = bool
3737
}
3838

39-
variable "dangerously_attach_admin_policy" {
40-
default = false
41-
description = "Enable/disable the attachment of the AdministratorAccess policy."
39+
variable "create_oidc_provider" {
40+
default = true
41+
description = "Enable/disable the creation of the GitHub OIDC provider."
4242
type = bool
4343
}
4444

45-
variable "enabled" {
46-
default = true
47-
description = "Enable/disable the creation of resources."
45+
variable "dangerously_attach_admin_policy" {
46+
default = false
47+
description = "Enable/disable the attachment of the AdministratorAccess policy."
4848
type = bool
4949
}
5050

versions.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
// SPDX-License-Identifier: MIT
33

44
terraform {
5+
required_version = "~> 1.12"
6+
57
required_providers {
68
aws = {
79
source = "hashicorp/aws"
8-
version = ">= 5.0"
10+
version = ">= 6.0"
911
}
1012

1113
tls = {
1214
source = "hashicorp/tls"
1315
version = ">= 4.0"
1416
}
1517
}
16-
17-
required_version = "~> 1.10"
1818
}

0 commit comments

Comments
 (0)