Skip to content

Commit 4e8f6ed

Browse files
authored
feat(extra-vars): allow to pass extra CI/CD variables (#45)
* feat(extra-vars): allow to pass extra CI/CD variables
1 parent ce3be4f commit 4e8f6ed

File tree

6 files changed

+61
-3
lines changed

6 files changed

+61
-3
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,16 @@ module "static-site" {
9393

9494
| Name | Version |
9595
|------|---------|
96-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.61.0 |
97-
| <a name="provider_gitlab"></a> [gitlab](#provider\_gitlab) | 17.2.0 |
96+
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 5.27 |
97+
| <a name="provider_gitlab"></a> [gitlab](#provider\_gitlab) | >= 15.7, < 18.0 |
9898

9999
## Modules
100100

101101
| Name | Source | Version |
102102
|------|--------|---------|
103103
| <a name="module_certificate"></a> [certificate](#module\_certificate) | terraform-aws-modules/acm/aws | 5.1.1 |
104104
| <a name="module_gitlab"></a> [gitlab](#module\_gitlab) | ./modules/gitlab | n/a |
105-
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | 4.7.0 |
105+
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | 4.8.0 |
106106

107107
## Resources
108108

@@ -147,6 +147,7 @@ module "static-site" {
147147
| <a name="input_enable_deploy_user"></a> [enable\_deploy\_user](#input\_enable\_deploy\_user) | Toggle s3 deploy user creation | `bool` | `true` | no |
148148
| <a name="input_encrypt_with_kms"></a> [encrypt\_with\_kms](#input\_encrypt\_with\_kms) | Enable server side s3 bucket encryption with KMS key | `bool` | `false` | no |
149149
| <a name="input_extra_domains"></a> [extra\_domains](#input\_extra\_domains) | Map of extra\_domains with domain name and zone\_id | `map(string)` | `{}` | no |
150+
| <a name="input_extra_gitlab_cicd_variables"></a> [extra\_gitlab\_cicd\_variables](#input\_extra\_gitlab\_cicd\_variables) | List of additional gitlab CI/CD variables | <pre>list(object({<br/> protected = optional(bool, false)<br/> masked = optional(bool, false)<br/> raw = optional(bool, true)<br/> key = string<br/> value = string<br/> }))</pre> | `[]` | no |
150151
| <a name="input_functions"></a> [functions](#input\_functions) | n/a | <pre>object({<br/> viewer_request = optional(string)<br/> viewer_response = optional(string)<br/> })</pre> | `{}` | no |
151152
| <a name="input_gitlab_environment"></a> [gitlab\_environment](#input\_gitlab\_environment) | GitLab environment name | `string` | `"*"` | no |
152153
| <a name="input_gitlab_project_id"></a> [gitlab\_project\_id](#input\_gitlab\_project\_id) | Deprecated: Use gitlab\_project\_ids instead | `string` | `""` | no |

deploy.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ module "gitlab" {
100100

101101
enable_deploy_role = var.enable_deploy_role
102102
enable_deploy_user = var.enable_deploy_user
103+
extra_gitlab_cicd_variables = var.extra_gitlab_cicd_variables
103104
aws_s3_bucket_name = module.s3_bucket.s3_bucket_id
104105
aws_cloudfront_distribution_id = aws_cloudfront_distribution.this.id
105106
aws_role_arn = var.enable_deploy_role ? aws_iam_role.deploy[0].arn : null

modules/gitlab/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ No modules.
6868
|------|------|
6969
| [gitlab_project_variable.aws_default_region](https://registry.terraform.io/providers/gitlabhq/gitlab/latest/docs/resources/project_variable) | resource |
7070
| [gitlab_project_variable.cloudfront_distribution_id](https://registry.terraform.io/providers/gitlabhq/gitlab/latest/docs/resources/project_variable) | resource |
71+
| [gitlab_project_variable.extra](https://registry.terraform.io/providers/gitlabhq/gitlab/latest/docs/resources/project_variable) | resource |
7172
| [gitlab_project_variable.s3_bucket](https://registry.terraform.io/providers/gitlabhq/gitlab/latest/docs/resources/project_variable) | resource |
7273
| [gitlab_project_variable.site_aws_access_key_id](https://registry.terraform.io/providers/gitlabhq/gitlab/latest/docs/resources/project_variable) | resource |
7374
| [gitlab_project_variable.site_aws_role_arn](https://registry.terraform.io/providers/gitlabhq/gitlab/latest/docs/resources/project_variable) | resource |
@@ -87,6 +88,7 @@ No modules.
8788
| <a name="input_aws_secret_access_key"></a> [aws\_secret\_access\_key](#input\_aws\_secret\_access\_key) | n/a | `string` | n/a | yes |
8889
| <a name="input_enable_deploy_role"></a> [enable\_deploy\_role](#input\_enable\_deploy\_role) | n/a | `bool` | n/a | yes |
8990
| <a name="input_enable_deploy_user"></a> [enable\_deploy\_user](#input\_enable\_deploy\_user) | n/a | `bool` | n/a | yes |
91+
| <a name="input_extra_gitlab_cicd_variables"></a> [extra\_gitlab\_cicd\_variables](#input\_extra\_gitlab\_cicd\_variables) | n/a | <pre>list(object({<br/> protected = optional(bool, false)<br/> masked = optional(bool, false)<br/> raw = optional(bool, true)<br/> key = string<br/> value = string<br/> }))</pre> | `[]` | no |
9092
| <a name="input_gitlab_environment"></a> [gitlab\_environment](#input\_gitlab\_environment) | n/a | `string` | `"*"` | no |
9193
| <a name="input_gitlab_project_ids"></a> [gitlab\_project\_ids](#input\_gitlab\_project\_ids) | n/a | `list(string)` | n/a | yes |
9294

modules/gitlab/main.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
locals {
2+
cicd_variable_flat_list = flatten([
3+
for project_id in var.gitlab_project_ids : [
4+
for variable in var.extra_gitlab_cicd_variables : {
5+
id = "${project_id}-${variable.key}"
6+
project_id = project_id
7+
variable = variable
8+
}
9+
]
10+
])
11+
12+
cicd_variable_flat_map = {
13+
for item in local.cicd_variable_flat_list :
14+
item.id => merge(item.variable, { project_id = item.project_id })
15+
}
16+
}
17+
118
data "gitlab_project" "this" {
219
for_each = toset(var.gitlab_project_ids)
320
id = each.value
@@ -92,3 +109,18 @@ resource "gitlab_project_variable" "site_aws_secret_access_key" {
92109

93110
environment_scope = var.gitlab_environment
94111
}
112+
113+
resource "gitlab_project_variable" "extra" {
114+
for_each = local.cicd_variable_flat_map
115+
116+
project = each.value.project_id
117+
118+
protected = each.value.protected
119+
masked = each.value.masked
120+
raw = each.value.raw
121+
122+
key = each.value.key
123+
value = each.value.value
124+
125+
environment_scope = var.gitlab_environment
126+
}

modules/gitlab/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,14 @@ variable "aws_env_vars_suffix" {
4444
type = string
4545
default = ""
4646
}
47+
48+
variable "extra_gitlab_cicd_variables" {
49+
type = list(object({
50+
protected = optional(bool, false)
51+
masked = optional(bool, false)
52+
raw = optional(bool, true)
53+
key = string
54+
value = string
55+
}))
56+
default = []
57+
}

variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,14 @@ variable "custom_headers" {
246246
default = null
247247
}
248248

249+
variable "extra_gitlab_cicd_variables" {
250+
type = list(object({
251+
protected = optional(bool, false)
252+
masked = optional(bool, false)
253+
raw = optional(bool, true)
254+
key = string
255+
value = string
256+
}))
257+
default = []
258+
description = "List of additional gitlab CI/CD variables"
259+
}

0 commit comments

Comments
 (0)