Repository: chanzuckerberg/fogg (go)

Issue:
turn off generating a saved plan when in remote backend mode
The remote backend does not support locally saving a plan. We use this when running `make check-plan`.

When the remote backend is configured we need to not try to save the plan locally.



Pull request:
[fix] skip saving planfiles with backend=remote
The terraform remote backend does not support saving a plan file
locally (I can't find docs for this, but that's what the CLI tells me). This
means our check-plan implementation cannot save it for analysis.

With this PR we turn off locally saving a plan file when backend_kind =
remote.

### Test Plan
* CI
* tested on 2 interal repos - one that is all remote backend and one that is all s3 backend

### References
* Fixes #464

Patch:
diff --git a/templates/repo/scripts/component.mk b/templates/repo/scripts/component.mk
index bd797916..d4e05673 100644
--- a/templates/repo/scripts/component.mk
+++ b/templates/repo/scripts/component.mk
@@ -71,7 +71,7 @@ refresh:
 .PHONY: refresh
 
 refresh-cached:
-	@last_refresh=`cat .terraform/refreshed_at || echo '0'`; \
+	@last_refresh=`cat .terraform/refreshed_at 2>/dev/null || echo '0'`; \
 	current_time=`date +%s`; \
 	if (( current_time - last_refresh > 600 )); then \
 		echo "It has been awhile since the last refresh. It is time."; \
@@ -106,8 +106,17 @@ init: terraform check-auth ## run terraform init for this component
 .PHONY: init
 
 check-plan: check-auth init refresh-cached ## run a terraform plan and check that it does not fail
-	@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
-	ERR=$$?; \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
+		ERR=$$?; \
+		if [ -n "$(BUILDEVENT_FILE)" ]; then \
+			fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
+		fi; \
+		rm $(CHECK_PLANFILE_PATH) 2>/dev/null; \
+	else \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false; \
+		ERR=$$?; \
+	fi; \
 	if [ $$ERR -eq 0 ] ; then \
 		echo "Success"; \
 	elif [ $$ERR -eq 1 ] ; then \
@@ -115,11 +124,7 @@ check-plan: check-auth init refresh-cached ## run a terraform plan and check tha
 		exit 1; \
 	elif [ $$ERR -eq 2 ] ; then \
 		echo "Diff";  \
-	fi ; \
-	if [ -n "$(BUILDEVENT_FILE)" ]; then \
-		fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
-	fi
-	rm $(CHECK_PLANFILE_PATH)
+	fi;
 .PHONY: check-plan
 
 run: check-auth ## run an arbitrary terraform command, CMD. ex `make run CMD='show'`


Test patch:
diff --git a/testdata/bless_provider_yaml/scripts/component.mk b/testdata/bless_provider_yaml/scripts/component.mk
index bd797916..d4e05673 100644
--- a/testdata/bless_provider_yaml/scripts/component.mk
+++ b/testdata/bless_provider_yaml/scripts/component.mk
@@ -71,7 +71,7 @@ refresh:
 .PHONY: refresh
 
 refresh-cached:
-	@last_refresh=`cat .terraform/refreshed_at || echo '0'`; \
+	@last_refresh=`cat .terraform/refreshed_at 2>/dev/null || echo '0'`; \
 	current_time=`date +%s`; \
 	if (( current_time - last_refresh > 600 )); then \
 		echo "It has been awhile since the last refresh. It is time."; \
@@ -106,8 +106,17 @@ init: terraform check-auth ## run terraform init for this component
 .PHONY: init
 
 check-plan: check-auth init refresh-cached ## run a terraform plan and check that it does not fail
-	@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
-	ERR=$$?; \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
+		ERR=$$?; \
+		if [ -n "$(BUILDEVENT_FILE)" ]; then \
+			fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
+		fi; \
+		rm $(CHECK_PLANFILE_PATH) 2>/dev/null; \
+	else \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false; \
+		ERR=$$?; \
+	fi; \
 	if [ $$ERR -eq 0 ] ; then \
 		echo "Success"; \
 	elif [ $$ERR -eq 1 ] ; then \
@@ -115,11 +124,7 @@ check-plan: check-auth init refresh-cached ## run a terraform plan and check tha
 		exit 1; \
 	elif [ $$ERR -eq 2 ] ; then \
 		echo "Diff";  \
-	fi ; \
-	if [ -n "$(BUILDEVENT_FILE)" ]; then \
-		fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
-	fi
-	rm $(CHECK_PLANFILE_PATH)
+	fi;
 .PHONY: check-plan
 
 run: check-auth ## run an arbitrary terraform command, CMD. ex `make run CMD='show'`
diff --git a/testdata/circleci/scripts/component.mk b/testdata/circleci/scripts/component.mk
index bd797916..d4e05673 100644
--- a/testdata/circleci/scripts/component.mk
+++ b/testdata/circleci/scripts/component.mk
@@ -71,7 +71,7 @@ refresh:
 .PHONY: refresh
 
 refresh-cached:
-	@last_refresh=`cat .terraform/refreshed_at || echo '0'`; \
+	@last_refresh=`cat .terraform/refreshed_at 2>/dev/null || echo '0'`; \
 	current_time=`date +%s`; \
 	if (( current_time - last_refresh > 600 )); then \
 		echo "It has been awhile since the last refresh. It is time."; \
@@ -106,8 +106,17 @@ init: terraform check-auth ## run terraform init for this component
 .PHONY: init
 
 check-plan: check-auth init refresh-cached ## run a terraform plan and check that it does not fail
-	@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
-	ERR=$$?; \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
+		ERR=$$?; \
+		if [ -n "$(BUILDEVENT_FILE)" ]; then \
+			fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
+		fi; \
+		rm $(CHECK_PLANFILE_PATH) 2>/dev/null; \
+	else \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false; \
+		ERR=$$?; \
+	fi; \
 	if [ $$ERR -eq 0 ] ; then \
 		echo "Success"; \
 	elif [ $$ERR -eq 1 ] ; then \
@@ -115,11 +124,7 @@ check-plan: check-auth init refresh-cached ## run a terraform plan and check tha
 		exit 1; \
 	elif [ $$ERR -eq 2 ] ; then \
 		echo "Diff";  \
-	fi ; \
-	if [ -n "$(BUILDEVENT_FILE)" ]; then \
-		fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
-	fi
-	rm $(CHECK_PLANFILE_PATH)
+	fi;
 .PHONY: check-plan
 
 run: check-auth ## run an arbitrary terraform command, CMD. ex `make run CMD='show'`
diff --git a/testdata/component_kind/scripts/component.mk b/testdata/component_kind/scripts/component.mk
index bd797916..d4e05673 100644
--- a/testdata/component_kind/scripts/component.mk
+++ b/testdata/component_kind/scripts/component.mk
@@ -71,7 +71,7 @@ refresh:
 .PHONY: refresh
 
 refresh-cached:
-	@last_refresh=`cat .terraform/refreshed_at || echo '0'`; \
+	@last_refresh=`cat .terraform/refreshed_at 2>/dev/null || echo '0'`; \
 	current_time=`date +%s`; \
 	if (( current_time - last_refresh > 600 )); then \
 		echo "It has been awhile since the last refresh. It is time."; \
@@ -106,8 +106,17 @@ init: terraform check-auth ## run terraform init for this component
 .PHONY: init
 
 check-plan: check-auth init refresh-cached ## run a terraform plan and check that it does not fail
-	@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
-	ERR=$$?; \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
+		ERR=$$?; \
+		if [ -n "$(BUILDEVENT_FILE)" ]; then \
+			fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
+		fi; \
+		rm $(CHECK_PLANFILE_PATH) 2>/dev/null; \
+	else \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false; \
+		ERR=$$?; \
+	fi; \
 	if [ $$ERR -eq 0 ] ; then \
 		echo "Success"; \
 	elif [ $$ERR -eq 1 ] ; then \
@@ -115,11 +124,7 @@ check-plan: check-auth init refresh-cached ## run a terraform plan and check tha
 		exit 1; \
 	elif [ $$ERR -eq 2 ] ; then \
 		echo "Diff";  \
-	fi ; \
-	if [ -n "$(BUILDEVENT_FILE)" ]; then \
-		fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
-	fi
-	rm $(CHECK_PLANFILE_PATH)
+	fi;
 .PHONY: check-plan
 
 run: check-auth ## run an arbitrary terraform command, CMD. ex `make run CMD='show'`
diff --git a/testdata/github_actions/scripts/component.mk b/testdata/github_actions/scripts/component.mk
index bd797916..d4e05673 100644
--- a/testdata/github_actions/scripts/component.mk
+++ b/testdata/github_actions/scripts/component.mk
@@ -71,7 +71,7 @@ refresh:
 .PHONY: refresh
 
 refresh-cached:
-	@last_refresh=`cat .terraform/refreshed_at || echo '0'`; \
+	@last_refresh=`cat .terraform/refreshed_at 2>/dev/null || echo '0'`; \
 	current_time=`date +%s`; \
 	if (( current_time - last_refresh > 600 )); then \
 		echo "It has been awhile since the last refresh. It is time."; \
@@ -106,8 +106,17 @@ init: terraform check-auth ## run terraform init for this component
 .PHONY: init
 
 check-plan: check-auth init refresh-cached ## run a terraform plan and check that it does not fail
-	@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
-	ERR=$$?; \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
+		ERR=$$?; \
+		if [ -n "$(BUILDEVENT_FILE)" ]; then \
+			fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
+		fi; \
+		rm $(CHECK_PLANFILE_PATH) 2>/dev/null; \
+	else \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false; \
+		ERR=$$?; \
+	fi; \
 	if [ $$ERR -eq 0 ] ; then \
 		echo "Success"; \
 	elif [ $$ERR -eq 1 ] ; then \
@@ -115,11 +124,7 @@ check-plan: check-auth init refresh-cached ## run a terraform plan and check tha
 		exit 1; \
 	elif [ $$ERR -eq 2 ] ; then \
 		echo "Diff";  \
-	fi ; \
-	if [ -n "$(BUILDEVENT_FILE)" ]; then \
-		fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
-	fi
-	rm $(CHECK_PLANFILE_PATH)
+	fi;
 .PHONY: check-plan
 
 run: check-auth ## run an arbitrary terraform command, CMD. ex `make run CMD='show'`
diff --git a/testdata/github_provider_yaml/scripts/component.mk b/testdata/github_provider_yaml/scripts/component.mk
index bd797916..d4e05673 100644
--- a/testdata/github_provider_yaml/scripts/component.mk
+++ b/testdata/github_provider_yaml/scripts/component.mk
@@ -71,7 +71,7 @@ refresh:
 .PHONY: refresh
 
 refresh-cached:
-	@last_refresh=`cat .terraform/refreshed_at || echo '0'`; \
+	@last_refresh=`cat .terraform/refreshed_at 2>/dev/null || echo '0'`; \
 	current_time=`date +%s`; \
 	if (( current_time - last_refresh > 600 )); then \
 		echo "It has been awhile since the last refresh. It is time."; \
@@ -106,8 +106,17 @@ init: terraform check-auth ## run terraform init for this component
 .PHONY: init
 
 check-plan: check-auth init refresh-cached ## run a terraform plan and check that it does not fail
-	@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
-	ERR=$$?; \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
+		ERR=$$?; \
+		if [ -n "$(BUILDEVENT_FILE)" ]; then \
+			fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
+		fi; \
+		rm $(CHECK_PLANFILE_PATH) 2>/dev/null; \
+	else \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false; \
+		ERR=$$?; \
+	fi; \
 	if [ $$ERR -eq 0 ] ; then \
 		echo "Success"; \
 	elif [ $$ERR -eq 1 ] ; then \
@@ -115,11 +124,7 @@ check-plan: check-auth init refresh-cached ## run a terraform plan and check tha
 		exit 1; \
 	elif [ $$ERR -eq 2 ] ; then \
 		echo "Diff";  \
-	fi ; \
-	if [ -n "$(BUILDEVENT_FILE)" ]; then \
-		fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
-	fi
-	rm $(CHECK_PLANFILE_PATH)
+	fi;
 .PHONY: check-plan
 
 run: check-auth ## run an arbitrary terraform command, CMD. ex `make run CMD='show'`
diff --git a/testdata/okta_provider_yaml/scripts/component.mk b/testdata/okta_provider_yaml/scripts/component.mk
index bd797916..d4e05673 100644
--- a/testdata/okta_provider_yaml/scripts/component.mk
+++ b/testdata/okta_provider_yaml/scripts/component.mk
@@ -71,7 +71,7 @@ refresh:
 .PHONY: refresh
 
 refresh-cached:
-	@last_refresh=`cat .terraform/refreshed_at || echo '0'`; \
+	@last_refresh=`cat .terraform/refreshed_at 2>/dev/null || echo '0'`; \
 	current_time=`date +%s`; \
 	if (( current_time - last_refresh > 600 )); then \
 		echo "It has been awhile since the last refresh. It is time."; \
@@ -106,8 +106,17 @@ init: terraform check-auth ## run terraform init for this component
 .PHONY: init
 
 check-plan: check-auth init refresh-cached ## run a terraform plan and check that it does not fail
-	@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
-	ERR=$$?; \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
+		ERR=$$?; \
+		if [ -n "$(BUILDEVENT_FILE)" ]; then \
+			fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
+		fi; \
+		rm $(CHECK_PLANFILE_PATH) 2>/dev/null; \
+	else \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false; \
+		ERR=$$?; \
+	fi; \
 	if [ $$ERR -eq 0 ] ; then \
 		echo "Success"; \
 	elif [ $$ERR -eq 1 ] ; then \
@@ -115,11 +124,7 @@ check-plan: check-auth init refresh-cached ## run a terraform plan and check tha
 		exit 1; \
 	elif [ $$ERR -eq 2 ] ; then \
 		echo "Diff";  \
-	fi ; \
-	if [ -n "$(BUILDEVENT_FILE)" ]; then \
-		fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
-	fi
-	rm $(CHECK_PLANFILE_PATH)
+	fi;
 .PHONY: check-plan
 
 run: check-auth ## run an arbitrary terraform command, CMD. ex `make run CMD='show'`
diff --git a/testdata/snowflake_provider_yaml/scripts/component.mk b/testdata/snowflake_provider_yaml/scripts/component.mk
index bd797916..d4e05673 100644
--- a/testdata/snowflake_provider_yaml/scripts/component.mk
+++ b/testdata/snowflake_provider_yaml/scripts/component.mk
@@ -71,7 +71,7 @@ refresh:
 .PHONY: refresh
 
 refresh-cached:
-	@last_refresh=`cat .terraform/refreshed_at || echo '0'`; \
+	@last_refresh=`cat .terraform/refreshed_at 2>/dev/null || echo '0'`; \
 	current_time=`date +%s`; \
 	if (( current_time - last_refresh > 600 )); then \
 		echo "It has been awhile since the last refresh. It is time."; \
@@ -106,8 +106,17 @@ init: terraform check-auth ## run terraform init for this component
 .PHONY: init
 
 check-plan: check-auth init refresh-cached ## run a terraform plan and check that it does not fail
-	@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
-	ERR=$$?; \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
+		ERR=$$?; \
+		if [ -n "$(BUILDEVENT_FILE)" ]; then \
+			fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
+		fi; \
+		rm $(CHECK_PLANFILE_PATH) 2>/dev/null; \
+	else \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false; \
+		ERR=$$?; \
+	fi; \
 	if [ $$ERR -eq 0 ] ; then \
 		echo "Success"; \
 	elif [ $$ERR -eq 1 ] ; then \
@@ -115,11 +124,7 @@ check-plan: check-auth init refresh-cached ## run a terraform plan and check tha
 		exit 1; \
 	elif [ $$ERR -eq 2 ] ; then \
 		echo "Diff";  \
-	fi ; \
-	if [ -n "$(BUILDEVENT_FILE)" ]; then \
-		fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
-	fi
-	rm $(CHECK_PLANFILE_PATH)
+	fi;
 .PHONY: check-plan
 
 run: check-auth ## run an arbitrary terraform command, CMD. ex `make run CMD='show'`
diff --git a/testdata/tfe_provider_yaml/scripts/component.mk b/testdata/tfe_provider_yaml/scripts/component.mk
index bd797916..d4e05673 100644
--- a/testdata/tfe_provider_yaml/scripts/component.mk
+++ b/testdata/tfe_provider_yaml/scripts/component.mk
@@ -71,7 +71,7 @@ refresh:
 .PHONY: refresh
 
 refresh-cached:
-	@last_refresh=`cat .terraform/refreshed_at || echo '0'`; \
+	@last_refresh=`cat .terraform/refreshed_at 2>/dev/null || echo '0'`; \
 	current_time=`date +%s`; \
 	if (( current_time - last_refresh > 600 )); then \
 		echo "It has been awhile since the last refresh. It is time."; \
@@ -106,8 +106,17 @@ init: terraform check-auth ## run terraform init for this component
 .PHONY: init
 
 check-plan: check-auth init refresh-cached ## run a terraform plan and check that it does not fail
-	@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
-	ERR=$$?; \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
+		ERR=$$?; \
+		if [ -n "$(BUILDEVENT_FILE)" ]; then \
+			fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
+		fi; \
+		rm $(CHECK_PLANFILE_PATH) 2>/dev/null; \
+	else \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false; \
+		ERR=$$?; \
+	fi; \
 	if [ $$ERR -eq 0 ] ; then \
 		echo "Success"; \
 	elif [ $$ERR -eq 1 ] ; then \
@@ -115,11 +124,7 @@ check-plan: check-auth init refresh-cached ## run a terraform plan and check tha
 		exit 1; \
 	elif [ $$ERR -eq 2 ] ; then \
 		echo "Diff";  \
-	fi ; \
-	if [ -n "$(BUILDEVENT_FILE)" ]; then \
-		fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
-	fi
-	rm $(CHECK_PLANFILE_PATH)
+	fi;
 .PHONY: check-plan
 
 run: check-auth ## run an arbitrary terraform command, CMD. ex `make run CMD='show'`
diff --git a/testdata/v2_full_yaml/scripts/component.mk b/testdata/v2_full_yaml/scripts/component.mk
index bd797916..d4e05673 100644
--- a/testdata/v2_full_yaml/scripts/component.mk
+++ b/testdata/v2_full_yaml/scripts/component.mk
@@ -71,7 +71,7 @@ refresh:
 .PHONY: refresh
 
 refresh-cached:
-	@last_refresh=`cat .terraform/refreshed_at || echo '0'`; \
+	@last_refresh=`cat .terraform/refreshed_at 2>/dev/null || echo '0'`; \
 	current_time=`date +%s`; \
 	if (( current_time - last_refresh > 600 )); then \
 		echo "It has been awhile since the last refresh. It is time."; \
@@ -106,8 +106,17 @@ init: terraform check-auth ## run terraform init for this component
 .PHONY: init
 
 check-plan: check-auth init refresh-cached ## run a terraform plan and check that it does not fail
-	@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
-	ERR=$$?; \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
+		ERR=$$?; \
+		if [ -n "$(BUILDEVENT_FILE)" ]; then \
+			fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
+		fi; \
+		rm $(CHECK_PLANFILE_PATH) 2>/dev/null; \
+	else \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false; \
+		ERR=$$?; \
+	fi; \
 	if [ $$ERR -eq 0 ] ; then \
 		echo "Success"; \
 	elif [ $$ERR -eq 1 ] ; then \
@@ -115,11 +124,7 @@ check-plan: check-auth init refresh-cached ## run a terraform plan and check tha
 		exit 1; \
 	elif [ $$ERR -eq 2 ] ; then \
 		echo "Diff";  \
-	fi ; \
-	if [ -n "$(BUILDEVENT_FILE)" ]; then \
-		fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
-	fi
-	rm $(CHECK_PLANFILE_PATH)
+	fi;
 .PHONY: check-plan
 
 run: check-auth ## run an arbitrary terraform command, CMD. ex `make run CMD='show'`
diff --git a/testdata/v2_minimal_valid_yaml/scripts/component.mk b/testdata/v2_minimal_valid_yaml/scripts/component.mk
index bd797916..d4e05673 100644
--- a/testdata/v2_minimal_valid_yaml/scripts/component.mk
+++ b/testdata/v2_minimal_valid_yaml/scripts/component.mk
@@ -71,7 +71,7 @@ refresh:
 .PHONY: refresh
 
 refresh-cached:
-	@last_refresh=`cat .terraform/refreshed_at || echo '0'`; \
+	@last_refresh=`cat .terraform/refreshed_at 2>/dev/null || echo '0'`; \
 	current_time=`date +%s`; \
 	if (( current_time - last_refresh > 600 )); then \
 		echo "It has been awhile since the last refresh. It is time."; \
@@ -106,8 +106,17 @@ init: terraform check-auth ## run terraform init for this component
 .PHONY: init
 
 check-plan: check-auth init refresh-cached ## run a terraform plan and check that it does not fail
-	@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
-	ERR=$$?; \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
+		ERR=$$?; \
+		if [ -n "$(BUILDEVENT_FILE)" ]; then \
+			fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
+		fi; \
+		rm $(CHECK_PLANFILE_PATH) 2>/dev/null; \
+	else \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false; \
+		ERR=$$?; \
+	fi; \
 	if [ $$ERR -eq 0 ] ; then \
 		echo "Success"; \
 	elif [ $$ERR -eq 1 ] ; then \
@@ -115,11 +124,7 @@ check-plan: check-auth init refresh-cached ## run a terraform plan and check tha
 		exit 1; \
 	elif [ $$ERR -eq 2 ] ; then \
 		echo "Diff";  \
-	fi ; \
-	if [ -n "$(BUILDEVENT_FILE)" ]; then \
-		fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
-	fi
-	rm $(CHECK_PLANFILE_PATH)
+	fi;
 .PHONY: check-plan
 
 run: check-auth ## run an arbitrary terraform command, CMD. ex `make run CMD='show'`
diff --git a/testdata/v2_no_aws_provider_yaml/scripts/component.mk b/testdata/v2_no_aws_provider_yaml/scripts/component.mk
index bd797916..d4e05673 100644
--- a/testdata/v2_no_aws_provider_yaml/scripts/component.mk
+++ b/testdata/v2_no_aws_provider_yaml/scripts/component.mk
@@ -71,7 +71,7 @@ refresh:
 .PHONY: refresh
 
 refresh-cached:
-	@last_refresh=`cat .terraform/refreshed_at || echo '0'`; \
+	@last_refresh=`cat .terraform/refreshed_at 2>/dev/null || echo '0'`; \
 	current_time=`date +%s`; \
 	if (( current_time - last_refresh > 600 )); then \
 		echo "It has been awhile since the last refresh. It is time."; \
@@ -106,8 +106,17 @@ init: terraform check-auth ## run terraform init for this component
 .PHONY: init
 
 check-plan: check-auth init refresh-cached ## run a terraform plan and check that it does not fail
-	@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
-	ERR=$$?; \
+	@if [ "$(TF_BACKEND_KIND)" != "remote" ]; then \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false -out=$(CHECK_PLANFILE_PATH) ; \
+		ERR=$$?; \
+		if [ -n "$(BUILDEVENT_FILE)" ]; then \
+			fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
+		fi; \
+		rm $(CHECK_PLANFILE_PATH) 2>/dev/null; \
+	else \
+		$(terraform_command) plan $(TF_ARGS) -detailed-exitcode -lock=false; \
+		ERR=$$?; \
+	fi; \
 	if [ $$ERR -eq 0 ] ; then \
 		echo "Success"; \
 	elif [ $$ERR -eq 1 ] ; then \
@@ -115,11 +124,7 @@ check-plan: check-auth init refresh-cached ## run a terraform plan and check tha
 		exit 1; \
 	elif [ $$ERR -eq 2 ] ; then \
 		echo "Diff";  \
-	fi ; \
-	if [ -n "$(BUILDEVENT_FILE)" ]; then \
-		fogg exp entropy -f $(CHECK_PLANFILE_PATH) -o $(BUILDEVENT_FILE) ; \
-	fi
-	rm $(CHECK_PLANFILE_PATH)
+	fi;
 .PHONY: check-plan
 
 run: check-auth ## run an arbitrary terraform command, CMD. ex `make run CMD='show'`