From 47f0cb3ba5bcd389fc170c480248e698e4686278 Mon Sep 17 00:00:00 2001 From: Prashant Shewale Date: Wed, 19 Apr 2023 08:23:44 +0530 Subject: [PATCH] fix expansion for the case of ENV var is not set --- lib/terraspace/plugin/expander/interface.rb | 2 +- spec/terraspace/provider/expander/generic_spec.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/terraspace/plugin/expander/interface.rb b/lib/terraspace/plugin/expander/interface.rb index d145cde0..f7839d29 100644 --- a/lib/terraspace/plugin/expander/interface.rb +++ b/lib/terraspace/plugin/expander/interface.rb @@ -84,7 +84,7 @@ def var_value(unexpanded) elsif !ENV[name].blank? return ENV[name] else - return unexpanded + return '' end if downcase == "namespace" && Terraspace.config.layering.enable_names.expansion value = friendly_name(value) diff --git a/spec/terraspace/provider/expander/generic_spec.rb b/spec/terraspace/provider/expander/generic_spec.rb index 0d0e8064..f07ad469 100644 --- a/spec/terraspace/provider/expander/generic_spec.rb +++ b/spec/terraspace/provider/expander/generic_spec.rb @@ -3,7 +3,7 @@ let(:props) do { bucket: "my-bucket", - key: ":env/:build_dir/terraform.tfstate", # variable notation expanded by terraspace + key: ":env/:TEAM/:ENVNOTSET/:build_dir/terraform.tfstate", # variable notation expanded by terraspace region: "us-west-2", encrypt: true, dynamodb_table: "terraform_locks" @@ -15,12 +15,14 @@ mod end + before { stub_const('ENV', {'TEAM' => 'backend'}) } + context "default path" do it "expand" do result = expander.expand(props) expect(result).to eq({ bucket: "my-bucket", - key: "dev/stacks/core/terraform.tfstate", + key: "dev/backend/stacks/core/terraform.tfstate", region: "us-west-2", encrypt: true, dynamodb_table: "terraform_locks"