Skip to content

Commit 88121eb

Browse files
authored
fix(deploy-role): pass enable_deploy_ variables to gitlab submodule to toggle resources creation based on values known during plan (#43)
1 parent 09a476c commit 88121eb

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ module "static-site" {
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.6.1 |
105+
| <a name="module_s3_bucket"></a> [s3\_bucket](#module\_s3\_bucket) | terraform-aws-modules/s3-bucket/aws | 4.7.0 |
106106

107107
## Resources
108108

deploy.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ data "aws_iam_policy_document" "assume_role" {
3636
resource "aws_iam_role" "deploy" {
3737
count = var.enable_deploy_role ? 1 : 0
3838
assume_role_policy = data.aws_iam_policy_document.assume_role[0].json
39-
description = format("Role used by the GitLab project %s", "GITLAB_PROJECT_PLACEHOLDER")
4039
name = "zvirt-${local.main_domain_sanitized}-deploy"
4140
tags = var.tags
4241
}
@@ -99,11 +98,13 @@ module "gitlab" {
9998
gitlab_project_ids = local.gitlab_project_ids
10099
gitlab_environment = var.gitlab_environment
101100

101+
enable_deploy_role = var.enable_deploy_role
102+
enable_deploy_user = var.enable_deploy_user
102103
aws_s3_bucket_name = module.s3_bucket.s3_bucket_id
103104
aws_cloudfront_distribution_id = aws_cloudfront_distribution.this.id
104-
aws_role_arn = aws_iam_role.deploy[0].arn
105-
aws_access_key_id = aws_iam_access_key.deploy[0].id
106-
aws_secret_access_key = aws_iam_access_key.deploy[0].secret
105+
aws_role_arn = var.enable_deploy_role ? aws_iam_role.deploy[0].arn : null
106+
aws_access_key_id = var.enable_deploy_user ? aws_iam_access_key.deploy[0].id : null
107+
aws_secret_access_key = var.enable_deploy_user ? aws_iam_access_key.deploy[0].secret : null
107108
aws_default_region = data.aws_region.current.name
108109
aws_env_vars_suffix = var.aws_env_vars_suffix
109110
}

modules/gitlab/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ No modules.
8585
| <a name="input_aws_role_arn"></a> [aws\_role\_arn](#input\_aws\_role\_arn) | n/a | `string` | n/a | yes |
8686
| <a name="input_aws_s3_bucket_name"></a> [aws\_s3\_bucket\_name](#input\_aws\_s3\_bucket\_name) | n/a | `string` | n/a | yes |
8787
| <a name="input_aws_secret_access_key"></a> [aws\_secret\_access\_key](#input\_aws\_secret\_access\_key) | n/a | `string` | n/a | yes |
88+
| <a name="input_enable_deploy_role"></a> [enable\_deploy\_role](#input\_enable\_deploy\_role) | n/a | `bool` | n/a | yes |
89+
| <a name="input_enable_deploy_user"></a> [enable\_deploy\_user](#input\_enable\_deploy\_user) | n/a | `bool` | n/a | yes |
8890
| <a name="input_gitlab_environment"></a> [gitlab\_environment](#input\_gitlab\_environment) | n/a | `string` | `"*"` | no |
8991
| <a name="input_gitlab_project_ids"></a> [gitlab\_project\_ids](#input\_gitlab\_project\_ids) | n/a | `list(string)` | n/a | yes |
9092

modules/gitlab/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ resource "gitlab_project_variable" "cloudfront_distribution_id" {
4949
}
5050

5151
resource "gitlab_project_variable" "site_aws_role_arn" {
52-
for_each = data.gitlab_project.this
52+
for_each = var.enable_deploy_role ? data.gitlab_project.this : {}
5353

5454
project = each.value.id
5555

@@ -64,7 +64,7 @@ resource "gitlab_project_variable" "site_aws_role_arn" {
6464
}
6565

6666
resource "gitlab_project_variable" "site_aws_access_key_id" {
67-
for_each = data.gitlab_project.this
67+
for_each = var.enable_deploy_user ? data.gitlab_project.this : {}
6868

6969
project = each.value.id
7070

@@ -79,7 +79,7 @@ resource "gitlab_project_variable" "site_aws_access_key_id" {
7979
}
8080

8181
resource "gitlab_project_variable" "site_aws_secret_access_key" {
82-
for_each = data.gitlab_project.this
82+
for_each = var.enable_deploy_user ? data.gitlab_project.this : {}
8383

8484
project = each.value.id
8585

modules/gitlab/variables.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ variable "aws_access_key_id" {
2323
type = string
2424
}
2525

26+
variable "enable_deploy_role" {
27+
type = bool
28+
}
29+
30+
variable "enable_deploy_user" {
31+
type = bool
32+
}
33+
2634
variable "aws_secret_access_key" {
2735
type = string
2836
sensitive = true

0 commit comments

Comments
 (0)