Skip to content

Commit 63e4626

Browse files
joli-sysjindraj
andauthored
feat: Define multiple gitlab projects (#26)
* feat: Define multiple gitlab projects --------- Co-authored-by: Jakub Jindra <[email protected]>
1 parent b3a8c2b commit 63e4626

File tree

6 files changed

+41
-19
lines changed

6 files changed

+41
-19
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ module "static-site" {
9292

9393
| Name | Version |
9494
|------|---------|
95-
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 5.27 |
95+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.61.0 |
9696

9797
## Modules
9898

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

105105
## Resources
106106

@@ -138,9 +138,10 @@ module "static-site" {
138138
| <a name="input_enable_deploy_user"></a> [enable\_deploy\_user](#input\_enable\_deploy\_user) | Toggle s3 deploy user creation | `bool` | `true` | no |
139139
| <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 |
140140
| <a name="input_extra_domains"></a> [extra\_domains](#input\_extra\_domains) | Map of extra\_domains with domain name and zone\_id | `map(string)` | `{}` | no |
141-
| <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 |
141+
| <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 |
142142
| <a name="input_gitlab_environment"></a> [gitlab\_environment](#input\_gitlab\_environment) | GitLab environment name | `string` | `"*"` | no |
143-
| <a name="input_gitlab_project_id"></a> [gitlab\_project\_id](#input\_gitlab\_project\_id) | Integrates with GitLab CI/CD to deploy site and invalidate CloudFront cache | `string` | `null` | no |
143+
| <a name="input_gitlab_project_id"></a> [gitlab\_project\_id](#input\_gitlab\_project\_id) | Deprecated: Use gitlab\_project\_ids instead | `string` | `""` | no |
144+
| <a name="input_gitlab_project_ids"></a> [gitlab\_project\_ids](#input\_gitlab\_project\_ids) | Integrates with GitLab CI/CD to deploy site and invalidate CloudFront cache | `list(string)` | `[]` | no |
144145
| <a name="input_kms_deletion_window_in_days"></a> [kms\_deletion\_window\_in\_days](#input\_kms\_deletion\_window\_in\_days) | The waiting period, specified in number of days. After the waiting period ends, AWS KMS deletes the KMS key | `number` | `30` | no |
145146
| <a name="input_kms_key_policy"></a> [kms\_key\_policy](#input\_kms\_key\_policy) | Additional KSM key policy | `string` | `"{}"` | no |
146147
| <a name="input_logs_bucket"></a> [logs\_bucket](#input\_logs\_bucket) | Bucket to store CloudFront logs | `string` | `null` | no |
@@ -150,12 +151,12 @@ module "static-site" {
150151
| <a name="input_origin_path"></a> [origin\_path](#input\_origin\_path) | Cloudfront origin path | `string` | `""` | no |
151152
| <a name="input_override_status_code_403"></a> [override\_status\_code\_403](#input\_override\_status\_code\_403) | Override status code for 403 error | `number` | `403` | no |
152153
| <a name="input_override_status_code_404"></a> [override\_status\_code\_404](#input\_override\_status\_code\_404) | Override status code for 404 error | `number` | `200` | no |
153-
| <a name="input_proxy_paths"></a> [proxy\_paths](#input\_proxy\_paths) | n/a | <pre>list(object({<br> origin_domain = string<br> path_prefix = string<br> }))</pre> | `[]` | no |
154+
| <a name="input_proxy_paths"></a> [proxy\_paths](#input\_proxy\_paths) | n/a | <pre>list(object({<br/> origin_domain = string<br/> path_prefix = string<br/> }))</pre> | `[]` | no |
154155
| <a name="input_response_header_access_control_allow_credentials"></a> [response\_header\_access\_control\_allow\_credentials](#input\_response\_header\_access\_control\_allow\_credentials) | n/a | `bool` | `false` | no |
155156
| <a name="input_response_header_origin_override"></a> [response\_header\_origin\_override](#input\_response\_header\_origin\_override) | n/a | `bool` | `false` | no |
156157
| <a name="input_s3_bucket_name"></a> [s3\_bucket\_name](#input\_s3\_bucket\_name) | n/a | `string` | n/a | yes |
157158
| <a name="input_s3_bucket_policy"></a> [s3\_bucket\_policy](#input\_s3\_bucket\_policy) | Additional S3 bucket policy | `string` | `"{}"` | no |
158-
| <a name="input_s3_cors_rule"></a> [s3\_cors\_rule](#input\_s3\_cors\_rule) | List of maps containing rules for Cross-Origin Resource Sharing. | <pre>list(object({<br> allowed_headers = optional(list(string))<br> allowed_methods = optional(list(string))<br> allowed_origins = optional(list(string))<br> expose_headers = optional(list(string))<br> max_age_seconds = optional(number)<br> }))</pre> | `[]` | no |
159+
| <a name="input_s3_cors_rule"></a> [s3\_cors\_rule](#input\_s3\_cors\_rule) | List of maps containing rules for Cross-Origin Resource Sharing. | <pre>list(object({<br/> allowed_headers = optional(list(string))<br/> allowed_methods = optional(list(string))<br/> allowed_origins = optional(list(string))<br/> expose_headers = optional(list(string))<br/> max_age_seconds = optional(number)<br/> }))</pre> | `[]` | no |
159160
| <a name="input_tags"></a> [tags](#input\_tags) | n/a | `map(string)` | `{}` | no |
160161

161162
## Outputs

deploy.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
locals {
2+
gitlab_project_ids = toset(concat(var.gitlab_project_ids, var.gitlab_project_id != "" ? [var.gitlab_project_id] : []))
3+
}
4+
15
resource "aws_iam_user" "deploy" {
26
count = var.enable_deploy_user == true ? 1 : 0
37
name = "zvirt-${local.main_domain_sanitized}-deploy"
@@ -42,11 +46,11 @@ resource "aws_iam_user_policy" "deploy" {
4246
}
4347

4448
module "gitlab" {
45-
count = var.gitlab_project_id == null ? 0 : 1
49+
count = length(local.gitlab_project_ids) == 0 ? 0 : 1
4650

4751
source = "./modules/gitlab"
4852

49-
gitlab_project_id = var.gitlab_project_id
53+
gitlab_project_ids = local.gitlab_project_ids
5054
gitlab_environment = var.gitlab_environment
5155

5256
aws_s3_bucket_name = module.s3_bucket.s3_bucket_id

modules/gitlab/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ No modules.
8484
| <a name="input_aws_s3_bucket_name"></a> [aws\_s3\_bucket\_name](#input\_aws\_s3\_bucket\_name) | n/a | `string` | n/a | yes |
8585
| <a name="input_aws_secret_access_key"></a> [aws\_secret\_access\_key](#input\_aws\_secret\_access\_key) | n/a | `string` | n/a | yes |
8686
| <a name="input_gitlab_environment"></a> [gitlab\_environment](#input\_gitlab\_environment) | n/a | `string` | `"*"` | no |
87-
| <a name="input_gitlab_project_id"></a> [gitlab\_project\_id](#input\_gitlab\_project\_id) | n/a | `string` | n/a | yes |
87+
| <a name="input_gitlab_project_ids"></a> [gitlab\_project\_ids](#input\_gitlab\_project\_ids) | n/a | `list(string)` | n/a | yes |
8888

8989
## Outputs
9090

modules/gitlab/main.tf

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
data "gitlab_project" "this" {
2-
id = var.gitlab_project_id
2+
for_each = toset(var.gitlab_project_ids)
3+
id = each.value
34
}
45

56
resource "gitlab_project_variable" "s3_bucket" {
6-
project = data.gitlab_project.this.id
7+
for_each = data.gitlab_project.this
8+
9+
project = each.value.id
710

811
protected = false
912
masked = false
@@ -16,7 +19,9 @@ resource "gitlab_project_variable" "s3_bucket" {
1619
}
1720

1821
resource "gitlab_project_variable" "aws_default_region" {
19-
project = data.gitlab_project.this.id
22+
for_each = data.gitlab_project.this
23+
24+
project = each.value.id
2025

2126
protected = false
2227
masked = false
@@ -29,7 +34,9 @@ resource "gitlab_project_variable" "aws_default_region" {
2934
}
3035

3136
resource "gitlab_project_variable" "cloudfront_distribution_id" {
32-
project = data.gitlab_project.this.id
37+
for_each = data.gitlab_project.this
38+
39+
project = each.value.id
3340

3441
protected = false
3542
masked = false
@@ -42,7 +49,9 @@ resource "gitlab_project_variable" "cloudfront_distribution_id" {
4249
}
4350

4451
resource "gitlab_project_variable" "site_aws_access_key_id" {
45-
project = data.gitlab_project.this.id
52+
for_each = data.gitlab_project.this
53+
54+
project = each.value.id
4655

4756
protected = false
4857
masked = false
@@ -55,7 +64,9 @@ resource "gitlab_project_variable" "site_aws_access_key_id" {
5564
}
5665

5766
resource "gitlab_project_variable" "site_aws_secret_access_key" {
58-
project = data.gitlab_project.this.id
67+
for_each = data.gitlab_project.this
68+
69+
project = each.value.id
5970

6071
protected = false
6172
masked = true

modules/gitlab/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
variable "gitlab_project_id" {
2-
type = string
1+
variable "gitlab_project_ids" {
2+
type = list(string)
33
}
44

55
variable "gitlab_environment" {

variables.tf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ variable "s3_bucket_policy" {
2222
description = "Additional S3 bucket policy"
2323
}
2424

25-
variable "gitlab_project_id" {
25+
variable "gitlab_project_ids" {
2626
description = "Integrates with GitLab CI/CD to deploy site and invalidate CloudFront cache"
27+
type = list(string)
28+
default = []
29+
}
30+
31+
variable "gitlab_project_id" {
2732
type = string
28-
default = null
33+
description = "Deprecated: Use gitlab_project_ids instead"
34+
default = ""
2935
}
3036

3137
variable "gitlab_environment" {

0 commit comments

Comments
 (0)