Repository: chanzuckerberg/fogg
Pull request #293 (2019-06-13 16:49:50)

set TF_IN_AUTOMATION=1
This env var will reduce some of the output from terraform commands.

From [the docs](https://learn.hashicorp.com/terraform/development/running-terraform-in-automation#controlling-terraform-output-in-automation):

> By default, some Terraform commands conclude by presenting a description of a possible next step to the user, often including a specific command to run next.
>
> An automation tool will often abstract away the details of exactly which commands are being run, causing these messages to be confusing and un-actionable, and possibly harmful if they inadvertently encourage a user to bypass the automation tool entirely.
>
> When the environment variable TF_IN_AUTOMATION is set to any non-empty value, Terraform makes some minor adjustments to its output to de-emphasize specific commands to run. The specific changes made will vary over time, but generally-speaking Terraform will consider this variable to indicate that there is some wrapping application that will help the user with the next step.

### Test Plan
* unit tests
* manually tested on shared-infra

### References
* https://learn.hashicorp.com/terraform/development/running-terraform-in-automation#controlling-terraform-output-in-automation


codecov[bot]: # [Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/293?src=pr&el=h1) Report
> Merging [#293](https://codecov.io/gh/chanzuckerberg/fogg/pull/293?src=pr&el=desc) into [master](https://codecov.io/gh/chanzuckerberg/fogg/commit/b5d8cb32d29768eb5bdf562d1a55df469614a1f4?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `n/a`.

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

```diff
@@           Coverage Diff           @@
##           master     #293   +/-   ##
=======================================
  Coverage   80.04%   80.04%           
=======================================
  Files          17       17           
  Lines        1408     1408           
=======================================
  Hits         1127     1127           
  Misses        160      160           
  Partials      121      121
```



------

[Continue to review full report at Codecov](https://codecov.io/gh/chanzuckerberg/fogg/pull/293?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/293?src=pr&el=footer). Last update [b5d8cb3...f6de536](https://codecov.io/gh/chanzuckerberg/fogg/pull/293?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/Makefile b/Makefile
index 50c8ca6b..9c792e9b 100644
--- a/Makefile
+++ b/Makefile
@@ -43,14 +43,14 @@ build: packr ## build the binary
 coverage: ## run the go coverage tool, reading file coverage.out
 	go tool cover -html=coverage.out
 
-test: ## run tests
+test: packr ## run tests
 	gotest -cover ./...
 
-test-offline: ## run only tests that don't require internet
+test-offline: packr  ## run only tests that don't require internet
 	gotest -tags=offline ./...
 .PHONY: test-offline
 
-test-coverage: ## run the test with proper coverage reporting
+test-coverage: packr  ## run the test with proper coverage reporting
 	goverage -coverprofile=coverage.out -covermode=atomic ./...
 	go tool cover -html=coverage.out
 .PHONY: test-coverage
diff --git a/templates/repo/scripts/common.mk b/templates/repo/scripts/common.mk
index b296f9d1..fde073c5 100644
--- a/templates/repo/scripts/common.mk
+++ b/templates/repo/scripts/common.mk
@@ -17,7 +17,7 @@ ifdef USE_DOCKER
 		-v $(REPO_ROOT)/.fogg/bin:/usr/local/bin -v $(REPO_ROOT)/terraform.d:/repo/$(REPO_RELATIVE_PATH)/terraform.d \
 		-e GIT_SSH_COMMAND='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
 		-e RUN_USER_ID=$(shell id -u) -e RUN_GROUP_ID=$(shell id -g) \
-		-e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" \
+		-e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" -e TF_IN_AUTOMATION=1 \
 		-w /repo/$(REPO_RELATIVE_PATH) $(TF_VARS) $(FOGG_DOCKER_FLAGS) $$(sh $(REPO_ROOT)/scripts/docker-ssh-mount.sh)
 	docker_terraform = $(docker_base) chanzuckerberg/terraform:$(IMAGE_VERSION)
 	docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:$(IMAGE_VERSION)
@@ -28,6 +28,7 @@ else
 	export PATH :=$(TFENV_DIR)/versions/$(TERRAFORM_VERSION)/:$(REPO_ROOT)/.fogg/bin:$(PATH)
 	export TF_PLUGIN_CACHE_DIR=$(REPO_ROOT)/.terraform.d/plugin-cache
 	sh_command ?= $(SHELL)
+	export TF_IN_AUTOMATION=1
 	terraform_command ?= $(TFENV_DIR)/versions/$(TERRAFORM_VERSION)/terraform
 endif
 


Test patch:
diff --git a/apply/golden_file_test.go b/apply/golden_file_test.go
index ca75d03a..e31d7999 100644
--- a/apply/golden_file_test.go
+++ b/apply/golden_file_test.go
@@ -1,5 +1,3 @@
-// +build !offline
-
 package apply_test
 
 import (
@@ -98,19 +96,20 @@ func TestIntegration(t *testing.T) {
 						r.NoError(e2)
 						r.NotNil(i2)
 
-						a.Equalf(i1.Size(), i2.Size(), "file size: %s", path)
+						logrus.Debugf("i1 size: %d ii2 size %d", i1.Size(), i2.Size())
+						r.Equalf(i1.Size(), i2.Size(), "file size: %s", path)
 						// This (below) doesn't currently work for files created on a mac then tested on linux. :shrug:
 						// a.Equalf(i1.Mode(), i2.Mode(), "file mode: %s, %o vs %o", path, i1.Mode(), i2.Mode())
 
 						f1, e3 := afero.ReadFile(testdataFs, path)
-						a.NoError(e3)
+						r.NoError(e3)
 						f2, e4 := afero.ReadFile(fs, path)
-						a.NoError(e4)
+						r.NoError(e4)
 
 						logrus.Debugf("f1:\n%s\n\n---- ", f1)
 						logrus.Debugf("f2:\n%s\n\n---- ", f2)
 
-						a.Equal(f1, f2)
+						r.Equal(f1, f2)
 					}
 					return nil
 				}))
diff --git a/testdata/bless_provider/scripts/common.mk b/testdata/bless_provider/scripts/common.mk
index b296f9d1..fde073c5 100644
--- a/testdata/bless_provider/scripts/common.mk
+++ b/testdata/bless_provider/scripts/common.mk
@@ -17,7 +17,7 @@ ifdef USE_DOCKER
 		-v $(REPO_ROOT)/.fogg/bin:/usr/local/bin -v $(REPO_ROOT)/terraform.d:/repo/$(REPO_RELATIVE_PATH)/terraform.d \
 		-e GIT_SSH_COMMAND='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
 		-e RUN_USER_ID=$(shell id -u) -e RUN_GROUP_ID=$(shell id -g) \
-		-e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" \
+		-e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" -e TF_IN_AUTOMATION=1 \
 		-w /repo/$(REPO_RELATIVE_PATH) $(TF_VARS) $(FOGG_DOCKER_FLAGS) $$(sh $(REPO_ROOT)/scripts/docker-ssh-mount.sh)
 	docker_terraform = $(docker_base) chanzuckerberg/terraform:$(IMAGE_VERSION)
 	docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:$(IMAGE_VERSION)
@@ -28,6 +28,7 @@ else
 	export PATH :=$(TFENV_DIR)/versions/$(TERRAFORM_VERSION)/:$(REPO_ROOT)/.fogg/bin:$(PATH)
 	export TF_PLUGIN_CACHE_DIR=$(REPO_ROOT)/.terraform.d/plugin-cache
 	sh_command ?= $(SHELL)
+	export TF_IN_AUTOMATION=1
 	terraform_command ?= $(TFENV_DIR)/versions/$(TERRAFORM_VERSION)/terraform
 endif
 
diff --git a/testdata/snowflake_provider/scripts/common.mk b/testdata/snowflake_provider/scripts/common.mk
index b296f9d1..fde073c5 100644
--- a/testdata/snowflake_provider/scripts/common.mk
+++ b/testdata/snowflake_provider/scripts/common.mk
@@ -17,7 +17,7 @@ ifdef USE_DOCKER
 		-v $(REPO_ROOT)/.fogg/bin:/usr/local/bin -v $(REPO_ROOT)/terraform.d:/repo/$(REPO_RELATIVE_PATH)/terraform.d \
 		-e GIT_SSH_COMMAND='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
 		-e RUN_USER_ID=$(shell id -u) -e RUN_GROUP_ID=$(shell id -g) \
-		-e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" \
+		-e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" -e TF_IN_AUTOMATION=1 \
 		-w /repo/$(REPO_RELATIVE_PATH) $(TF_VARS) $(FOGG_DOCKER_FLAGS) $$(sh $(REPO_ROOT)/scripts/docker-ssh-mount.sh)
 	docker_terraform = $(docker_base) chanzuckerberg/terraform:$(IMAGE_VERSION)
 	docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:$(IMAGE_VERSION)
@@ -28,6 +28,7 @@ else
 	export PATH :=$(TFENV_DIR)/versions/$(TERRAFORM_VERSION)/:$(REPO_ROOT)/.fogg/bin:$(PATH)
 	export TF_PLUGIN_CACHE_DIR=$(REPO_ROOT)/.terraform.d/plugin-cache
 	sh_command ?= $(SHELL)
+	export TF_IN_AUTOMATION=1
 	terraform_command ?= $(TFENV_DIR)/versions/$(TERRAFORM_VERSION)/terraform
 endif
 
diff --git a/testdata/v1_full/scripts/common.mk b/testdata/v1_full/scripts/common.mk
index b296f9d1..fde073c5 100644
--- a/testdata/v1_full/scripts/common.mk
+++ b/testdata/v1_full/scripts/common.mk
@@ -17,7 +17,7 @@ ifdef USE_DOCKER
 		-v $(REPO_ROOT)/.fogg/bin:/usr/local/bin -v $(REPO_ROOT)/terraform.d:/repo/$(REPO_RELATIVE_PATH)/terraform.d \
 		-e GIT_SSH_COMMAND='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
 		-e RUN_USER_ID=$(shell id -u) -e RUN_GROUP_ID=$(shell id -g) \
-		-e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" \
+		-e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" -e TF_IN_AUTOMATION=1 \
 		-w /repo/$(REPO_RELATIVE_PATH) $(TF_VARS) $(FOGG_DOCKER_FLAGS) $$(sh $(REPO_ROOT)/scripts/docker-ssh-mount.sh)
 	docker_terraform = $(docker_base) chanzuckerberg/terraform:$(IMAGE_VERSION)
 	docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:$(IMAGE_VERSION)
@@ -28,6 +28,7 @@ else
 	export PATH :=$(TFENV_DIR)/versions/$(TERRAFORM_VERSION)/:$(REPO_ROOT)/.fogg/bin:$(PATH)
 	export TF_PLUGIN_CACHE_DIR=$(REPO_ROOT)/.terraform.d/plugin-cache
 	sh_command ?= $(SHELL)
+	export TF_IN_AUTOMATION=1
 	terraform_command ?= $(TFENV_DIR)/versions/$(TERRAFORM_VERSION)/terraform
 endif
 
diff --git a/testdata/v2_full/scripts/common.mk b/testdata/v2_full/scripts/common.mk
index b296f9d1..fde073c5 100644
--- a/testdata/v2_full/scripts/common.mk
+++ b/testdata/v2_full/scripts/common.mk
@@ -17,7 +17,7 @@ ifdef USE_DOCKER
 		-v $(REPO_ROOT)/.fogg/bin:/usr/local/bin -v $(REPO_ROOT)/terraform.d:/repo/$(REPO_RELATIVE_PATH)/terraform.d \
 		-e GIT_SSH_COMMAND='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
 		-e RUN_USER_ID=$(shell id -u) -e RUN_GROUP_ID=$(shell id -g) \
-		-e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" \
+		-e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" -e TF_IN_AUTOMATION=1 \
 		-w /repo/$(REPO_RELATIVE_PATH) $(TF_VARS) $(FOGG_DOCKER_FLAGS) $$(sh $(REPO_ROOT)/scripts/docker-ssh-mount.sh)
 	docker_terraform = $(docker_base) chanzuckerberg/terraform:$(IMAGE_VERSION)
 	docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:$(IMAGE_VERSION)
@@ -28,6 +28,7 @@ else
 	export PATH :=$(TFENV_DIR)/versions/$(TERRAFORM_VERSION)/:$(REPO_ROOT)/.fogg/bin:$(PATH)
 	export TF_PLUGIN_CACHE_DIR=$(REPO_ROOT)/.terraform.d/plugin-cache
 	sh_command ?= $(SHELL)
+	export TF_IN_AUTOMATION=1
 	terraform_command ?= $(TFENV_DIR)/versions/$(TERRAFORM_VERSION)/terraform
 endif
 
diff --git a/testdata/v2_minimal_valid/scripts/common.mk b/testdata/v2_minimal_valid/scripts/common.mk
index b296f9d1..fde073c5 100644
--- a/testdata/v2_minimal_valid/scripts/common.mk
+++ b/testdata/v2_minimal_valid/scripts/common.mk
@@ -17,7 +17,7 @@ ifdef USE_DOCKER
 		-v $(REPO_ROOT)/.fogg/bin:/usr/local/bin -v $(REPO_ROOT)/terraform.d:/repo/$(REPO_RELATIVE_PATH)/terraform.d \
 		-e GIT_SSH_COMMAND='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
 		-e RUN_USER_ID=$(shell id -u) -e RUN_GROUP_ID=$(shell id -g) \
-		-e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" \
+		-e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" -e TF_IN_AUTOMATION=1 \
 		-w /repo/$(REPO_RELATIVE_PATH) $(TF_VARS) $(FOGG_DOCKER_FLAGS) $$(sh $(REPO_ROOT)/scripts/docker-ssh-mount.sh)
 	docker_terraform = $(docker_base) chanzuckerberg/terraform:$(IMAGE_VERSION)
 	docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:$(IMAGE_VERSION)
@@ -28,6 +28,7 @@ else
 	export PATH :=$(TFENV_DIR)/versions/$(TERRAFORM_VERSION)/:$(REPO_ROOT)/.fogg/bin:$(PATH)
 	export TF_PLUGIN_CACHE_DIR=$(REPO_ROOT)/.terraform.d/plugin-cache
 	sh_command ?= $(SHELL)
+	export TF_IN_AUTOMATION=1
 	terraform_command ?= $(TFENV_DIR)/versions/$(TERRAFORM_VERSION)/terraform
 endif
 
diff --git a/testdata/v2_no_aws_provider/scripts/common.mk b/testdata/v2_no_aws_provider/scripts/common.mk
index b296f9d1..fde073c5 100644
--- a/testdata/v2_no_aws_provider/scripts/common.mk
+++ b/testdata/v2_no_aws_provider/scripts/common.mk
@@ -17,7 +17,7 @@ ifdef USE_DOCKER
 		-v $(REPO_ROOT)/.fogg/bin:/usr/local/bin -v $(REPO_ROOT)/terraform.d:/repo/$(REPO_RELATIVE_PATH)/terraform.d \
 		-e GIT_SSH_COMMAND='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
 		-e RUN_USER_ID=$(shell id -u) -e RUN_GROUP_ID=$(shell id -g) \
-		-e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" \
+		-e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" -e TF_IN_AUTOMATION=1 \
 		-w /repo/$(REPO_RELATIVE_PATH) $(TF_VARS) $(FOGG_DOCKER_FLAGS) $$(sh $(REPO_ROOT)/scripts/docker-ssh-mount.sh)
 	docker_terraform = $(docker_base) chanzuckerberg/terraform:$(IMAGE_VERSION)
 	docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:$(IMAGE_VERSION)
@@ -28,6 +28,7 @@ else
 	export PATH :=$(TFENV_DIR)/versions/$(TERRAFORM_VERSION)/:$(REPO_ROOT)/.fogg/bin:$(PATH)
 	export TF_PLUGIN_CACHE_DIR=$(REPO_ROOT)/.terraform.d/plugin-cache
 	sh_command ?= $(SHELL)
+	export TF_IN_AUTOMATION=1
 	terraform_command ?= $(TFENV_DIR)/versions/$(TERRAFORM_VERSION)/terraform
 endif