Repository: chanzuckerberg/fogg
Pull request #448 (2020-04-02 08:51:21)

Fix missing quotes in refresh check
### Summary
Fixes missing quotes around a potentially empty env var. Without the quotes and with the var unset, we get the following error message:
```
cat: .terraform/refreshed_at: No such file or directory
It has been awhile since the last refresh. It is time.
/bin/bash: line 0: [: !=: unary operator expected
remote backend does not support the refresh command, skipping
/Users/foo/work/shared-infra/.fogg/tfenv/versions/0.12.24/terraform plan  -refresh=false -input=false
```
The missing env leaves nothing for bash to interpret, and the != comparator fails since it doesn't have a string on the left side. This fixes that, and updates the golden files.

### Test Plan
Tested locally; error message disappeared. Passes unit tests.

codecov-io: # [Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/448?src=pr&el=h1) Report
> :exclamation: No coverage uploaded for pull request base (`master@92ee41f`). [Click here to learn what that means](https://docs.codecov.io/docs/error-reference#section-missing-base-commit).
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/chanzuckerberg/fogg/pull/448/graphs/tree.svg?width=650&token=57DhtZ7g2A&height=150&src=pr)](https://codecov.io/gh/chanzuckerberg/fogg/pull/448?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##             master     #448   +/-   ##
=========================================
  Coverage          ?   61.33%           
=========================================
  Files             ?       19           
  Lines             ?     1906           
  Branches          ?        0           
=========================================
  Hits              ?     1169           
  Misses            ?      586           
  Partials          ?      151
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/448?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/448?src=pr&el=footer). Last update [92ee41f...7dcdf95](https://codecov.io/gh/chanzuckerberg/fogg/pull/448?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/templates/repo/scripts/component.mk b/templates/repo/scripts/component.mk
index 04d5e533..55e07cc0 100644
--- a/templates/repo/scripts/component.mk
+++ b/templates/repo/scripts/component.mk
@@ -62,7 +62,7 @@ endif
 .PHONY: check-auth-heroku
 
 refresh:
-	@if [ $(TF_BACKEND_KIND) != "remote" ]; then \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
 		$(terraform_command) refresh $(TF_ARGS); \
 		date +%s > .terraform/refreshed_at; \
 	else \


Test patch:
diff --git a/testdata/bless_provider_yaml/scripts/component.mk b/testdata/bless_provider_yaml/scripts/component.mk
index 04d5e533..55e07cc0 100644
--- a/testdata/bless_provider_yaml/scripts/component.mk
+++ b/testdata/bless_provider_yaml/scripts/component.mk
@@ -62,7 +62,7 @@ endif
 .PHONY: check-auth-heroku
 
 refresh:
-	@if [ $(TF_BACKEND_KIND) != "remote" ]; then \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
 		$(terraform_command) refresh $(TF_ARGS); \
 		date +%s > .terraform/refreshed_at; \
 	else \
diff --git a/testdata/circleci/scripts/component.mk b/testdata/circleci/scripts/component.mk
index 04d5e533..55e07cc0 100644
--- a/testdata/circleci/scripts/component.mk
+++ b/testdata/circleci/scripts/component.mk
@@ -62,7 +62,7 @@ endif
 .PHONY: check-auth-heroku
 
 refresh:
-	@if [ $(TF_BACKEND_KIND) != "remote" ]; then \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
 		$(terraform_command) refresh $(TF_ARGS); \
 		date +%s > .terraform/refreshed_at; \
 	else \
diff --git a/testdata/component_kind/scripts/component.mk b/testdata/component_kind/scripts/component.mk
index 04d5e533..55e07cc0 100644
--- a/testdata/component_kind/scripts/component.mk
+++ b/testdata/component_kind/scripts/component.mk
@@ -62,7 +62,7 @@ endif
 .PHONY: check-auth-heroku
 
 refresh:
-	@if [ $(TF_BACKEND_KIND) != "remote" ]; then \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
 		$(terraform_command) refresh $(TF_ARGS); \
 		date +%s > .terraform/refreshed_at; \
 	else \
diff --git a/testdata/github_actions/scripts/component.mk b/testdata/github_actions/scripts/component.mk
index 04d5e533..55e07cc0 100644
--- a/testdata/github_actions/scripts/component.mk
+++ b/testdata/github_actions/scripts/component.mk
@@ -62,7 +62,7 @@ endif
 .PHONY: check-auth-heroku
 
 refresh:
-	@if [ $(TF_BACKEND_KIND) != "remote" ]; then \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
 		$(terraform_command) refresh $(TF_ARGS); \
 		date +%s > .terraform/refreshed_at; \
 	else \
diff --git a/testdata/github_provider_yaml/scripts/component.mk b/testdata/github_provider_yaml/scripts/component.mk
index 04d5e533..55e07cc0 100644
--- a/testdata/github_provider_yaml/scripts/component.mk
+++ b/testdata/github_provider_yaml/scripts/component.mk
@@ -62,7 +62,7 @@ endif
 .PHONY: check-auth-heroku
 
 refresh:
-	@if [ $(TF_BACKEND_KIND) != "remote" ]; then \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
 		$(terraform_command) refresh $(TF_ARGS); \
 		date +%s > .terraform/refreshed_at; \
 	else \
diff --git a/testdata/okta_provider_yaml/scripts/component.mk b/testdata/okta_provider_yaml/scripts/component.mk
index 04d5e533..55e07cc0 100644
--- a/testdata/okta_provider_yaml/scripts/component.mk
+++ b/testdata/okta_provider_yaml/scripts/component.mk
@@ -62,7 +62,7 @@ endif
 .PHONY: check-auth-heroku
 
 refresh:
-	@if [ $(TF_BACKEND_KIND) != "remote" ]; then \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
 		$(terraform_command) refresh $(TF_ARGS); \
 		date +%s > .terraform/refreshed_at; \
 	else \
diff --git a/testdata/snowflake_provider_yaml/scripts/component.mk b/testdata/snowflake_provider_yaml/scripts/component.mk
index 04d5e533..55e07cc0 100644
--- a/testdata/snowflake_provider_yaml/scripts/component.mk
+++ b/testdata/snowflake_provider_yaml/scripts/component.mk
@@ -62,7 +62,7 @@ endif
 .PHONY: check-auth-heroku
 
 refresh:
-	@if [ $(TF_BACKEND_KIND) != "remote" ]; then \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
 		$(terraform_command) refresh $(TF_ARGS); \
 		date +%s > .terraform/refreshed_at; \
 	else \
diff --git a/testdata/v2_full_yaml/scripts/component.mk b/testdata/v2_full_yaml/scripts/component.mk
index 04d5e533..55e07cc0 100644
--- a/testdata/v2_full_yaml/scripts/component.mk
+++ b/testdata/v2_full_yaml/scripts/component.mk
@@ -62,7 +62,7 @@ endif
 .PHONY: check-auth-heroku
 
 refresh:
-	@if [ $(TF_BACKEND_KIND) != "remote" ]; then \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
 		$(terraform_command) refresh $(TF_ARGS); \
 		date +%s > .terraform/refreshed_at; \
 	else \
diff --git a/testdata/v2_minimal_valid_yaml/scripts/component.mk b/testdata/v2_minimal_valid_yaml/scripts/component.mk
index 04d5e533..55e07cc0 100644
--- a/testdata/v2_minimal_valid_yaml/scripts/component.mk
+++ b/testdata/v2_minimal_valid_yaml/scripts/component.mk
@@ -62,7 +62,7 @@ endif
 .PHONY: check-auth-heroku
 
 refresh:
-	@if [ $(TF_BACKEND_KIND) != "remote" ]; then \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
 		$(terraform_command) refresh $(TF_ARGS); \
 		date +%s > .terraform/refreshed_at; \
 	else \
diff --git a/testdata/v2_no_aws_provider_yaml/scripts/component.mk b/testdata/v2_no_aws_provider_yaml/scripts/component.mk
index 04d5e533..55e07cc0 100644
--- a/testdata/v2_no_aws_provider_yaml/scripts/component.mk
+++ b/testdata/v2_no_aws_provider_yaml/scripts/component.mk
@@ -62,7 +62,7 @@ endif
 .PHONY: check-auth-heroku
 
 refresh:
-	@if [ $(TF_BACKEND_KIND) != "remote" ]; then \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
 		$(terraform_command) refresh $(TF_ARGS); \
 		date +%s > .terraform/refreshed_at; \
 	else \