From 9487b8d04403662d975e592e0fcf6a9096e9fdd5 Mon Sep 17 00:00:00 2001 From: Michael Abadilla <60165806+mabadillamycwt@users.noreply.github.com> Date: Wed, 4 Mar 2020 16:04:28 +0800 Subject: [PATCH] Make template for output file configurable (#38) * Make template for output file configurable * Document new variable * Updated README.md Co-authored-by: actions-bot <58130806+actions-bot@users.noreply.github.com> --- README.md | 1 + docs/terraform.md | 1 + main.tf | 4 +++- variables.tf | 8 +++++++- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ba16e07..74c1791 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,7 @@ Available targets: | tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map(string) | `` | no | | terraform_backend_config_file_name | Name of terraform backend config file | string | `terraform.tf` | no | | terraform_backend_config_file_path | The path to terrafrom project directory | string | `` | no | +| terraform_backend_config_template_file | The path to the template used to generate the config file | string | `` | no | | terraform_state_file | The path to the state file inside the bucket | string | `terraform.tfstate` | no | | terraform_version | The minimum required terraform version | string | `0.12.2` | no | | write_capacity | DynamoDB write capacity units | string | `5` | no | diff --git a/docs/terraform.md b/docs/terraform.md index 29794bb..b2d7c88 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -31,6 +31,7 @@ | tags | Additional tags (e.g. `map('BusinessUnit','XYZ')` | map(string) | `` | no | | terraform_backend_config_file_name | Name of terraform backend config file | string | `terraform.tf` | no | | terraform_backend_config_file_path | The path to terrafrom project directory | string | `` | no | +| terraform_backend_config_template_file | The path to the template used to generate the config file | string | `` | no | | terraform_state_file | The path to the state file inside the bucket | string | `terraform.tfstate` | no | | terraform_version | The minimum required terraform version | string | `0.12.2` | no | | write_capacity | DynamoDB write capacity units | string | `5` | no | diff --git a/main.tf b/main.tf index c8c57ef..70dd6f2 100644 --- a/main.tf +++ b/main.tf @@ -12,6 +12,8 @@ locals { var.terraform_backend_config_file_name ) + terraform_backend_config_template_file = var.terraform_backend_config_template_file != "" ? var.terraform_backend_config_template_file : "${path.module}/templates/terraform.tf.tpl" + bucket_name = var.s3_bucket_name != "" ? var.s3_bucket_name : module.s3_bucket_label.id } @@ -197,7 +199,7 @@ resource "aws_dynamodb_table" "without_server_side_encryption" { } data "template_file" "terraform_backend_config" { - template = file("${path.module}/templates/terraform.tf.tpl") + template = file(local.terraform_backend_config_template_file) vars = { region = var.region diff --git a/variables.tf b/variables.tf index ad4bb8f..5d98803 100644 --- a/variables.tf +++ b/variables.tf @@ -191,6 +191,12 @@ variable "terraform_backend_config_file_path" { description = "The path to terrafrom project directory" } +variable "terraform_backend_config_template_file" { + type = string + default = "" + description = "The path to the template used to generate the config file" +} + variable "terraform_version" { type = string default = "0.12.2" @@ -207,4 +213,4 @@ variable "s3_bucket_name" { type = string default = "" description = "S3 bucket name. If not provided, the name will be generated by the label module in the format namespace-stage-name" -} \ No newline at end of file +}