Skip to content

Commit

Permalink
docs: update docs for tf and ci
Browse files Browse the repository at this point in the history
Signed-off-by: Said Sef <saidsef@gmail.com>
  • Loading branch information
saidsef committed Aug 3, 2024
1 parent 6f904c9 commit 3546911
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 32 deletions.
7 changes: 5 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ stages:
- aws-test

.assume-role:
id_tokens:
AWS_ID_TOKEN:
aud: https://oidc.provider.com
before_script:
- >
STS=($(aws sts assume-role-with-web-identity
--role-arn $ROLE_ARN
--region $AWS_REGION
--role-session-name "GitLabRunner-${CI_PROJECT_ID}-${CI_PIPELINE_ID}"
--web-identity-token $CI_JOB_JWT_V2
--web-identity-token $AWS_ID_TOKEN
--duration-seconds 3600
--query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]'
--output text))
Expand All @@ -32,7 +35,7 @@ validate:
stage: validate
needs: []
image:
name: hashicorp/terraform:1.1.9
name: hashicorp/terraform:latest
entrypoint:
- "/usr/bin/env"
- "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ Please see [TERRAFORM.md](./TERRAFORM.md)

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

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

> `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.
## ID Tokens

## Source

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!
Expand Down
14 changes: 7 additions & 7 deletions TERRAFORM.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

Expand Down Expand Up @@ -39,22 +39,22 @@ No modules.
| <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 |
| <a name="input_create_oidc_provider"></a> [create\_oidc\_provider](#input\_create\_oidc\_provider) | Enable creation of the GitLab OIDC provider | `bool` | `true` | no |
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Enable creation of resources | `bool` | `true` | no |
| <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 |
| <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 |
| <a name="input_gitlab_organisation"></a> [gitlab\_organisation](#input\_gitlab\_organisation) | GitLab organisation name | `string` | n/a | yes |
| <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 |
| <a name="input_iam_role_name"></a> [iam\_role\_name](#input\_iam\_role\_name) | Name of the IAM role | `string` | `"gitlab-runner"` | no |
| <a name="input_iam_role_path"></a> [iam\_role\_path](#input\_iam\_role\_path) | Path to the IAM role | `string` | `"/"` | no |
| <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 |
| <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 |
| <a name="input_max_session_duration"></a> [max\_session\_duration](#input\_max\_session\_duration) | Maximum session duration in seconds | `number` | `3600` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Map of tags to be applied to all resources | `map(string)` | `{}` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Map of tags to be applied to all resources. | `map(string)` | `{}` | no |
| <a name="input_url"></a> [url](#input\_url) | URL of identity provider | `string` | `"gitlab.com"` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_repositories"></a> [repositories](#output\_repositories) | List of GitLab repositories and refs |
| <a name="output_role_arn"></a> [role\_arn](#output\_role\_arn) | AWS IAM role ARN |
| <a name="output_role_id"></a> [role\_id](#output\_role\_id) | AWS IAM role ID |
| <a name="output_thumbprint"></a> [thumbprint](#output\_thumbprint) | GitLab certificates thumbprints |
| <a name="output_repositories"></a> [repositories](#output\_repositories) | A list of GitLab repositories and their references. |
| <a name="output_role_arn"></a> [role\_arn](#output\_role\_arn) | The ARN of the AWS IAM role. |
| <a name="output_role_id"></a> [role\_id](#output\_role\_id) | The ID of the AWS IAM role. |
| <a name="output_thumbprint"></a> [thumbprint](#output\_thumbprint) | Thumbprints of GitLab certificates. |
10 changes: 5 additions & 5 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ No resources.
| <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 |
| <a name="input_create_oidc_provider"></a> [create\_oidc\_provider](#input\_create\_oidc\_provider) | Enable creation of the GitLab OIDC provider | `bool` | `true` | no |
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Enable creation of resources | `bool` | `true` | no |
| <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 |
| <a name="input_gitlab_organisation"></a> [gitlab\_organisation](#input\_gitlab\_organisation) | GitLab organisation name | `string` | `"saidsef"` | no |
| <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 |
| <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 |
| <a name="input_gitlab_organisation"></a> [gitlab\_organisation](#input\_gitlab\_organisation) | GitLab organisation name | `string` | n/a | yes |
| <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 |
| <a name="input_iam_role_name"></a> [iam\_role\_name](#input\_iam\_role\_name) | Name of the IAM role | `string` | `"gitlab-runner"` | no |
| <a name="input_iam_role_path"></a> [iam\_role\_path](#input\_iam\_role\_path) | Path to the IAM role | `string` | `"/"` | no |
| <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 |
| <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 |
| <a name="input_max_session_duration"></a> [max\_session\_duration](#input\_max\_session\_duration) | Maximum session duration in seconds | `number` | `3600` | no |
| <a name="input_region"></a> [region](#input\_region) | AWS Region name | `string` | `"eu-west-1"` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Map of tags to be applied to all resources | `map(string)` | `{}` | no |
| <a name="input_region"></a> [region](#input\_region) | AWS Region name. | `string` | `"eu-west-1"` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | Map of tags to be applied to all resources. | `map(string)` | `{}` | no |
| <a name="input_url"></a> [url](#input\_url) | URL of identity provider | `string` | `"gitlab.com"` | no |

## Outputs
Expand Down
43 changes: 33 additions & 10 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
variable "region" {
default = "eu-west-1"
description = "AWS Region name"
type = string
}

variable "attach_admin_policy" {
default = false
description = "Enable attachment of the AdministratorAccess policy"
Expand Down Expand Up @@ -31,13 +25,17 @@ variable "enabled" {
variable "force_detach_policies" {
default = false
description = "Force detachment of policies attached to the IAM role"
type = string
type = bool
}

variable "gitlab_organisation" {
default = "saidsef"
description = "GitLab organisation name"
type = string

validation {
condition = length(var.gitlab_organisation) > 0
error_message = "GitLab organisation name must not be empty."
}
}

variable "gitlab_repositories" {
Expand All @@ -53,21 +51,35 @@ variable "gitlab_repositories" {
ref_type = ""
}
]

description = "List of GitLab repository name(s) and refs names or patterns"

validation {
condition = alltrue([for repo in var.gitlab_repositories : length(repo.name) > 0])
error_message = "Each GitLab repository must have a non-empty name."
}
}

variable "iam_role_name" {
default = "gitlab-runner"
description = "Name of the IAM role"
type = string

validation {
condition = length(var.iam_role_name) > 0
error_message = "IAM role name must not be empty."
}
}

variable "iam_role_path" {
default = "/"
description = "Path to the IAM role"
type = string
sensitive = false

validation {
condition = length(var.iam_role_path) > 0
error_message = "IAM role path must not be empty."
}
}

variable "iam_role_permissions_boundary" {
Expand Down Expand Up @@ -101,11 +113,22 @@ variable "url" {
description = "URL of identity provider"
default = "gitlab.com"
sensitive = false

validation {
condition = can(regex("^https?://", var.url))
error_message = "URL must be a valid HTTP or HTTPS URL."
}
}

variable "region" {
default = "eu-west-1"
description = "AWS Region name."
type = string
}

variable "tags" {
default = {}
description = "Map of tags to be applied to all resources"
description = "Map of tags to be applied to all resources."
type = map(string)
sensitive = false
}
4 changes: 3 additions & 1 deletion examples/remote/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ module "gitlab_oidc" {
gitlab_organisation = "saidsef"
gitlab_repositories = [{
name = "terraform-aws-gitlab-oidc",
branches = ["main", "pr-*", "*pull*", "*"]
refs = ["main", "pr-*", "*pull*", "*"]
ref_type = "branch"

}]
iam_role_name = "gitlab-runner"
iam_role_path = "/"
Expand Down
2 changes: 1 addition & 1 deletion examples/remote/variables.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variable "region" {
default = "eu-west-1"
description = "AWS Region name"
description = "AWS Region name."
type = string
}
8 changes: 4 additions & 4 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
output "role_id" {
value = aws_iam_role.role[0].id
sensitive = false
description = "AWS IAM role ID"
description = "The ID of the AWS IAM role."
}

output "role_arn" {
value = aws_iam_role.role[0].arn
sensitive = false
description = "AWS IAM role ARN"
description = "The ARN of the AWS IAM role."
}

output "repositories" {
value = local.repositories_refs
sensitive = false
description = "List of GitLab repositories and refs"
description = "A list of GitLab repositories and their references."
}

output "thumbprint" {
value = [for fingerprint in data.tls_certificate.provider.certificates : fingerprint.sha1_fingerprint]
sensitive = false
description = "GitLab certificates thumbprints"
description = "Thumbprints of GitLab certificates."
}
29 changes: 27 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ variable "enabled" {
variable "force_detach_policies" {
default = false
description = "Force detachment of policies attached to the IAM role"
type = string
type = bool
}

variable "gitlab_organisation" {
description = "GitLab organisation name"
type = string

validation {
condition = length(var.gitlab_organisation) > 0
error_message = "GitLab organisation name must not be empty."
}
}

variable "gitlab_repositories" {
Expand All @@ -47,19 +52,34 @@ variable "gitlab_repositories" {
}
]
description = "List of GitLab repository name(s) and refs names or patterns"

validation {
condition = alltrue([for repo in var.gitlab_repositories : length(repo.name) > 0])
error_message = "Each GitLab repository must have a non-empty name."
}
}

variable "iam_role_name" {
default = "gitlab-runner"
description = "Name of the IAM role"
type = string

validation {
condition = length(var.iam_role_name) > 0
error_message = "IAM role name must not be empty."
}
}

variable "iam_role_path" {
default = "/"
description = "Path to the IAM role"
type = string
sensitive = false

validation {
condition = length(var.iam_role_path) > 0
error_message = "IAM role path must not be empty."
}
}

variable "iam_role_permissions_boundary" {
Expand Down Expand Up @@ -93,11 +113,16 @@ variable "url" {
description = "URL of identity provider"
default = "gitlab.com"
sensitive = false

validation {
condition = can(regex("^https?://", var.url))
error_message = "URL must be a valid HTTP or HTTPS URL."
}
}

variable "tags" {
default = {}
description = "Map of tags to be applied to all resources"
description = "Map of tags to be applied to all resources."
type = map(string)
sensitive = false
}

0 comments on commit 3546911

Please sign in to comment.