Skip to content

Commit c659c17

Browse files
authored
Add default values to ENV vars and check if they are not empty (#10)
1 parent 41e4860 commit c659c17

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ module "build" {
4444
| privileged_mode | "" | (Optional) If set to true, enables running the Docker daemon inside a Docker container on the `CodeBuild` instance. Used when building Docker images |
4545
| aws_region | "" | (Optional) AWS Region, _e.g._ `us-east-1`. Used as `CodeBuild` ENV variable when building Docker images |
4646
| aws_account_id | "" | (Optional) AWS Account ID. Used as `CodeBuild` ENV variable when building Docker images |
47-
| image_repo_name | "" | (Optional) ECR repository name to store the Docker image built by this module. Used as `CodeBuild` ENV variable when building Docker images |
48-
| image_tag | "" | (Optional) Docker image tag in the ECR repository, _e.g._ `latest`. Used as `CodeBuild` ENV variable when building Docker images |
47+
| image_repo_name | "UNSET" | (Optional) ECR repository name to store the Docker image built by this module. Used as `CodeBuild` ENV variable when building Docker images |
48+
| image_tag | "latest" | (Optional) Docker image tag in the ECR repository, _e.g._ `latest`. Used as `CodeBuild` ENV variable when building Docker images |
4949

5050

5151

main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ data "aws_region" "default" {
66

77
# Define composite variables for resources
88
module "label" {
9-
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.2.1"
9+
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.2.1"
1010
namespace = "${var.namespace}"
1111
name = "${var.name}"
1212
stage = "${var.stage}"
@@ -98,12 +98,12 @@ resource "aws_codebuild_project" "default" {
9898

9999
environment_variable {
100100
"name" = "IMAGE_REPO_NAME"
101-
"value" = "${var.image_repo_name}"
101+
"value" = "${signum(length(var.image_repo_name)) == 1 ? var.image_repo_name : "UNSET"}"
102102
}
103103

104104
environment_variable {
105105
"name" = "IMAGE_TAG"
106-
"value" = "${var.image_tag}"
106+
"value" = "${signum(length(var.image_tag)) == 1 ? var.image_tag : "latest"}"
107107
}
108108
}
109109

variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ variable "aws_account_id" {
5858

5959
variable "image_repo_name" {
6060
type = "string"
61-
default = ""
61+
default = "UNSET"
6262
description = "(Optional) ECR repository name to store the Docker image built by this module. Used as CodeBuild ENV variable when building Docker images. For more info: http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html"
6363
}
6464

6565
variable "image_tag" {
6666
type = "string"
67-
default = ""
67+
default = "latest"
6868
description = "(Optional) Docker image tag in the ECR repository, e.g. 'latest'. Used as CodeBuild ENV variable when building Docker images. For more info: http://docs.aws.amazon.com/codebuild/latest/userguide/sample-docker.html"
6969
}

0 commit comments

Comments
 (0)