Skip to content

Commit 3546911

Browse files
committed
docs: update docs for tf and ci
Signed-off-by: Said Sef <saidsef@gmail.com>
1 parent 6f904c9 commit 3546911

File tree

9 files changed

+90
-32
lines changed

9 files changed

+90
-32
lines changed

.gitlab-ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ stages:
1414
- aws-test
1515

1616
.assume-role:
17+
id_tokens:
18+
AWS_ID_TOKEN:
19+
aud: https://oidc.provider.com
1720
before_script:
1821
- >
1922
STS=($(aws sts assume-role-with-web-identity
2023
--role-arn $ROLE_ARN
2124
--region $AWS_REGION
2225
--role-session-name "GitLabRunner-${CI_PROJECT_ID}-${CI_PIPELINE_ID}"
23-
--web-identity-token $CI_JOB_JWT_V2
26+
--web-identity-token $AWS_ID_TOKEN
2427
--duration-seconds 3600
2528
--query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]'
2629
--output text))
@@ -32,7 +35,7 @@ validate:
3235
stage: validate
3336
needs: []
3437
image:
35-
name: hashicorp/terraform:1.1.9
38+
name: hashicorp/terraform:latest
3639
entrypoint:
3740
- "/usr/bin/env"
3841
- "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ Please see [TERRAFORM.md](./TERRAFORM.md)
4848

4949
Retrieve temporary credentials via [GitLab Runner](https://github.com/saidsef/terraform-aws-gitlab-oidc/blob/a9f7cf02fd5789b41f2aca5978c752b8fc843977/.gitlab-ci.yml#L16-L28)
5050

51+
## JWT
5152
https://github.com/saidsef/terraform-aws-gitlab-oidc/blob/a9f7cf02fd5789b41f2aca5978c752b8fc843977/.gitlab-ci.yml#L16-L28
5253

54+
> `CI_JOB_JWT` and `CI_JOB_JWT_V2` were [deprecated in GitLab 15.9](https://docs.gitlab.com/ee/update/deprecations.html#old-versions-of-json-web-tokens-are-deprecated) and are scheduled to be removed in GitLab 17.0. Use [ID tokens](https://docs.gitlab.com/ee/ci/yaml/index.html#id_tokens) instead.
55+
56+
## ID Tokens
57+
5358
## Source
5459

5560
Our latest and greatest source of `terraform-aws-gitlab-oidc` can be found on [GitHub](https://github.com/saidsef/terraform-aws-gitlab-oidc/). Fork us!

TERRAFORM.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
| Name | Version |
44
|------|---------|
5-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1 |
5+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
66
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4, < 6 |
77
| <a name="requirement_tls"></a> [tls](#requirement\_tls) | >= 4, < 6 |
88

@@ -39,22 +39,22 @@ No modules.
3939
| <a name="input_attach_read_only_policy"></a> [attach\_read\_only\_policy](#input\_attach\_read\_only\_policy) | Enable attachment of the ReadOnly policy | `bool` | `true` | no |
4040
| <a name="input_create_oidc_provider"></a> [create\_oidc\_provider](#input\_create\_oidc\_provider) | Enable creation of the GitLab OIDC provider | `bool` | `true` | no |
4141
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Enable creation of resources | `bool` | `true` | no |
42-
| <a name="input_force_detach_policies"></a> [force\_detach\_policies](#input\_force\_detach\_policies) | Force detachment of policies attached to the IAM role | `string` | `false` | no |
42+
| <a name="input_force_detach_policies"></a> [force\_detach\_policies](#input\_force\_detach\_policies) | Force detachment of policies attached to the IAM role | `bool` | `false` | no |
4343
| <a name="input_gitlab_organisation"></a> [gitlab\_organisation](#input\_gitlab\_organisation) | GitLab organisation name | `string` | n/a | yes |
4444
| <a name="input_gitlab_repositories"></a> [gitlab\_repositories](#input\_gitlab\_repositories) | List of GitLab repository name(s) and refs names or patterns | <pre>list(object({<br> name = string<br> refs = list(string)<br> ref_type = string<br> }))</pre> | <pre>[<br> {<br> "name": "",<br> "ref_type": "",<br> "refs": []<br> }<br>]</pre> | no |
4545
| <a name="input_iam_role_name"></a> [iam\_role\_name](#input\_iam\_role\_name) | Name of the IAM role | `string` | `"gitlab-runner"` | no |
4646
| <a name="input_iam_role_path"></a> [iam\_role\_path](#input\_iam\_role\_path) | Path to the IAM role | `string` | `"/"` | no |
4747
| <a name="input_iam_role_permissions_boundary"></a> [iam\_role\_permissions\_boundary](#input\_iam\_role\_permissions\_boundary) | ARN of the permissions boundary to be used by the IAM role | `string` | `""` | no |
4848
| <a name="input_iam_role_policy_arns"></a> [iam\_role\_policy\_arns](#input\_iam\_role\_policy\_arns) | List of IAM policy ARNs to attach to the IAM role | `list(string)` | `[]` | no |
4949
| <a name="input_max_session_duration"></a> [max\_session\_duration](#input\_max\_session\_duration) | Maximum session duration in seconds | `number` | `3600` | no |
50-
| <a name="input_tags"></a> [tags](#input\_tags) | Map of tags to be applied to all resources | `map(string)` | `{}` | no |
50+
| <a name="input_tags"></a> [tags](#input\_tags) | Map of tags to be applied to all resources. | `map(string)` | `{}` | no |
5151
| <a name="input_url"></a> [url](#input\_url) | URL of identity provider | `string` | `"gitlab.com"` | no |
5252

5353
## Outputs
5454

5555
| Name | Description |
5656
|------|-------------|
57-
| <a name="output_repositories"></a> [repositories](#output\_repositories) | List of GitLab repositories and refs |
58-
| <a name="output_role_arn"></a> [role\_arn](#output\_role\_arn) | AWS IAM role ARN |
59-
| <a name="output_role_id"></a> [role\_id](#output\_role\_id) | AWS IAM role ID |
60-
| <a name="output_thumbprint"></a> [thumbprint](#output\_thumbprint) | GitLab certificates thumbprints |
57+
| <a name="output_repositories"></a> [repositories](#output\_repositories) | A list of GitLab repositories and their references. |
58+
| <a name="output_role_arn"></a> [role\_arn](#output\_role\_arn) | The ARN of the AWS IAM role. |
59+
| <a name="output_role_id"></a> [role\_id](#output\_role\_id) | The ID of the AWS IAM role. |
60+
| <a name="output_thumbprint"></a> [thumbprint](#output\_thumbprint) | Thumbprints of GitLab certificates. |

examples/complete/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ No resources.
2828
| <a name="input_attach_read_only_policy"></a> [attach\_read\_only\_policy](#input\_attach\_read\_only\_policy) | Enable attachment of the ReadOnly policy | `bool` | `true` | no |
2929
| <a name="input_create_oidc_provider"></a> [create\_oidc\_provider](#input\_create\_oidc\_provider) | Enable creation of the GitLab OIDC provider | `bool` | `true` | no |
3030
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Enable creation of resources | `bool` | `true` | no |
31-
| <a name="input_force_detach_policies"></a> [force\_detach\_policies](#input\_force\_detach\_policies) | Force detachment of policies attached to the IAM role | `string` | `false` | no |
32-
| <a name="input_gitlab_organisation"></a> [gitlab\_organisation](#input\_gitlab\_organisation) | GitLab organisation name | `string` | `"saidsef"` | no |
33-
| <a name="input_gitlab_repositories"></a> [gitlab\_repositories](#input\_gitlab\_repositories) | List of GitLab repository name(s) and branche names or patterns | <pre>list(object({<br> name = string<br> branches = list(string)<br> }))</pre> | <pre>[<br> {<br> "branches": null,<br> "name": null<br> }<br>]</pre> | no |
31+
| <a name="input_force_detach_policies"></a> [force\_detach\_policies](#input\_force\_detach\_policies) | Force detachment of policies attached to the IAM role | `bool` | `false` | no |
32+
| <a name="input_gitlab_organisation"></a> [gitlab\_organisation](#input\_gitlab\_organisation) | GitLab organisation name | `string` | n/a | yes |
33+
| <a name="input_gitlab_repositories"></a> [gitlab\_repositories](#input\_gitlab\_repositories) | List of GitLab repository name(s) and refs names or patterns | <pre>list(object({<br> name = string<br> refs = list(string)<br> ref_type = string<br> }))</pre> | <pre>[<br> {<br> "name": "",<br> "ref_type": "",<br> "refs": []<br> }<br>]</pre> | no |
3434
| <a name="input_iam_role_name"></a> [iam\_role\_name](#input\_iam\_role\_name) | Name of the IAM role | `string` | `"gitlab-runner"` | no |
3535
| <a name="input_iam_role_path"></a> [iam\_role\_path](#input\_iam\_role\_path) | Path to the IAM role | `string` | `"/"` | no |
3636
| <a name="input_iam_role_permissions_boundary"></a> [iam\_role\_permissions\_boundary](#input\_iam\_role\_permissions\_boundary) | ARN of the permissions boundary to be used by the IAM role | `string` | `""` | no |
3737
| <a name="input_iam_role_policy_arns"></a> [iam\_role\_policy\_arns](#input\_iam\_role\_policy\_arns) | List of IAM policy ARNs to attach to the IAM role | `list(string)` | `[]` | no |
3838
| <a name="input_max_session_duration"></a> [max\_session\_duration](#input\_max\_session\_duration) | Maximum session duration in seconds | `number` | `3600` | no |
39-
| <a name="input_region"></a> [region](#input\_region) | AWS Region name | `string` | `"eu-west-1"` | no |
40-
| <a name="input_tags"></a> [tags](#input\_tags) | Map of tags to be applied to all resources | `map(string)` | `{}` | no |
39+
| <a name="input_region"></a> [region](#input\_region) | AWS Region name. | `string` | `"eu-west-1"` | no |
40+
| <a name="input_tags"></a> [tags](#input\_tags) | Map of tags to be applied to all resources. | `map(string)` | `{}` | no |
4141
| <a name="input_url"></a> [url](#input\_url) | URL of identity provider | `string` | `"gitlab.com"` | no |
4242

4343
## Outputs

examples/complete/variables.tf

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
variable "region" {
2-
default = "eu-west-1"
3-
description = "AWS Region name"
4-
type = string
5-
}
6-
71
variable "attach_admin_policy" {
82
default = false
93
description = "Enable attachment of the AdministratorAccess policy"
@@ -31,13 +25,17 @@ variable "enabled" {
3125
variable "force_detach_policies" {
3226
default = false
3327
description = "Force detachment of policies attached to the IAM role"
34-
type = string
28+
type = bool
3529
}
3630

3731
variable "gitlab_organisation" {
38-
default = "saidsef"
3932
description = "GitLab organisation name"
4033
type = string
34+
35+
validation {
36+
condition = length(var.gitlab_organisation) > 0
37+
error_message = "GitLab organisation name must not be empty."
38+
}
4139
}
4240

4341
variable "gitlab_repositories" {
@@ -53,21 +51,35 @@ variable "gitlab_repositories" {
5351
ref_type = ""
5452
}
5553
]
56-
5754
description = "List of GitLab repository name(s) and refs names or patterns"
55+
56+
validation {
57+
condition = alltrue([for repo in var.gitlab_repositories : length(repo.name) > 0])
58+
error_message = "Each GitLab repository must have a non-empty name."
59+
}
5860
}
5961

6062
variable "iam_role_name" {
6163
default = "gitlab-runner"
6264
description = "Name of the IAM role"
6365
type = string
66+
67+
validation {
68+
condition = length(var.iam_role_name) > 0
69+
error_message = "IAM role name must not be empty."
70+
}
6471
}
6572

6673
variable "iam_role_path" {
6774
default = "/"
6875
description = "Path to the IAM role"
6976
type = string
7077
sensitive = false
78+
79+
validation {
80+
condition = length(var.iam_role_path) > 0
81+
error_message = "IAM role path must not be empty."
82+
}
7183
}
7284

7385
variable "iam_role_permissions_boundary" {
@@ -101,11 +113,22 @@ variable "url" {
101113
description = "URL of identity provider"
102114
default = "gitlab.com"
103115
sensitive = false
116+
117+
validation {
118+
condition = can(regex("^https?://", var.url))
119+
error_message = "URL must be a valid HTTP or HTTPS URL."
120+
}
121+
}
122+
123+
variable "region" {
124+
default = "eu-west-1"
125+
description = "AWS Region name."
126+
type = string
104127
}
105128

106129
variable "tags" {
107130
default = {}
108-
description = "Map of tags to be applied to all resources"
131+
description = "Map of tags to be applied to all resources."
109132
type = map(string)
110133
sensitive = false
111134
}

examples/remote/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ module "gitlab_oidc" {
1414
gitlab_organisation = "saidsef"
1515
gitlab_repositories = [{
1616
name = "terraform-aws-gitlab-oidc",
17-
branches = ["main", "pr-*", "*pull*", "*"]
17+
refs = ["main", "pr-*", "*pull*", "*"]
18+
ref_type = "branch"
19+
1820
}]
1921
iam_role_name = "gitlab-runner"
2022
iam_role_path = "/"

examples/remote/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
variable "region" {
22
default = "eu-west-1"
3-
description = "AWS Region name"
3+
description = "AWS Region name."
44
type = string
55
}

outputs.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
output "role_id" {
22
value = aws_iam_role.role[0].id
33
sensitive = false
4-
description = "AWS IAM role ID"
4+
description = "The ID of the AWS IAM role."
55
}
66

77
output "role_arn" {
88
value = aws_iam_role.role[0].arn
99
sensitive = false
10-
description = "AWS IAM role ARN"
10+
description = "The ARN of the AWS IAM role."
1111
}
1212

1313
output "repositories" {
1414
value = local.repositories_refs
1515
sensitive = false
16-
description = "List of GitLab repositories and refs"
16+
description = "A list of GitLab repositories and their references."
1717
}
1818

1919
output "thumbprint" {
2020
value = [for fingerprint in data.tls_certificate.provider.certificates : fingerprint.sha1_fingerprint]
2121
sensitive = false
22-
description = "GitLab certificates thumbprints"
22+
description = "Thumbprints of GitLab certificates."
2323
}

variables.tf

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@ variable "enabled" {
2525
variable "force_detach_policies" {
2626
default = false
2727
description = "Force detachment of policies attached to the IAM role"
28-
type = string
28+
type = bool
2929
}
3030

3131
variable "gitlab_organisation" {
3232
description = "GitLab organisation name"
3333
type = string
34+
35+
validation {
36+
condition = length(var.gitlab_organisation) > 0
37+
error_message = "GitLab organisation name must not be empty."
38+
}
3439
}
3540

3641
variable "gitlab_repositories" {
@@ -47,19 +52,34 @@ variable "gitlab_repositories" {
4752
}
4853
]
4954
description = "List of GitLab repository name(s) and refs names or patterns"
55+
56+
validation {
57+
condition = alltrue([for repo in var.gitlab_repositories : length(repo.name) > 0])
58+
error_message = "Each GitLab repository must have a non-empty name."
59+
}
5060
}
5161

5262
variable "iam_role_name" {
5363
default = "gitlab-runner"
5464
description = "Name of the IAM role"
5565
type = string
66+
67+
validation {
68+
condition = length(var.iam_role_name) > 0
69+
error_message = "IAM role name must not be empty."
70+
}
5671
}
5772

5873
variable "iam_role_path" {
5974
default = "/"
6075
description = "Path to the IAM role"
6176
type = string
6277
sensitive = false
78+
79+
validation {
80+
condition = length(var.iam_role_path) > 0
81+
error_message = "IAM role path must not be empty."
82+
}
6383
}
6484

6585
variable "iam_role_permissions_boundary" {
@@ -93,11 +113,16 @@ variable "url" {
93113
description = "URL of identity provider"
94114
default = "gitlab.com"
95115
sensitive = false
116+
117+
validation {
118+
condition = can(regex("^https?://", var.url))
119+
error_message = "URL must be a valid HTTP or HTTPS URL."
120+
}
96121
}
97122

98123
variable "tags" {
99124
default = {}
100-
description = "Map of tags to be applied to all resources"
125+
description = "Map of tags to be applied to all resources."
101126
type = map(string)
102127
sensitive = false
103128
}

0 commit comments

Comments
 (0)