hashicorp / hashicorp/terraform-plugin-testing
Consider Persisting Each Plan File During Each Step
- Dominant language
- Go
- Stars
- 68
- Forks
- 22
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 1
Description
### terraform-plugin-testing version
```
v1.2.0
```
### Use cases
When using the `TF_ACC_PERSIST_WORKING_DIR=1` environment variable, the directory is filled with some handy contents showing file artifacts during the testing (output assuming #114 implementation):
```console
$ tree /Users/bflad/test/testing55
/Users/bflad/test/testing55
0 directories, 0 files
$ TF_ACC_PERSIST_WORKING_DIR=1 go test -count=1 -v ./internal/provider
=== RUN TestExampleDataSource_basic
testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/TestExampleDataSource_basic/step_1
--- PASS: TestExampleDataSource_basic (0.54s)
=== RUN TestExampleResource_basic
testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/TestExampleResource_basic/step_1
testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/TestExampleResource_basic/step_2
testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/TestExampleResource_basic/step_3
--- PASS: TestExampleResource_basic (0.89s)
PASS
ok github.com/bflad/terraform-provider-framework/internal/provider 1.717s
$ tree /Users/bflad/test/testing55
/Users/bflad/test/testing55
├── TestExampleDataSource_basic
│ └── step_1
│ ├── terraform.tfstate
│ ├── terraform_plugin_test.tf
│ └── tfplan
├── TestExampleResource_basic
│ ├── step_1
│ │ ├── terraform.tfstate
│ │ ├── terraform.tfstate.backup
│ │ ├── terraform_plugin_test.tf
│ │ └── tfplan
│ ├── step_2
│ │ ├── terraform.tfstate
│ │ ├── terraform.tfstate.backup
│ │ ├── terraform_plugin_test.tf
│ │ └── tfplan
│ └── step_3
│ ├── terraform.tfstate
│ ├── terraform.tfstate.backup
│ ├── terraform_plugin_test.tf
│ └── tfplan
├── work1058235289
│ ├── terraform.tfstate
│ ├── terraform.tfstate.backup
│ ├── terraform_plugin_test.tf
│ └── tfplan
├── work4271933255
│ ├── terraform.tfstate
│ └── terraform_plugin_test.tf
└── work763334115
├── terraform.tfstate
├── terraform.tfstate.backup
├── terraform_plugin_test.tf
└── tfplan
10 directories, 25 files
```
However, looking at the plan files, they always are the last plan to occur during the test step (which is usually a plan showing no operations to verify providers aren't introducing permanent drift). It would be great to see all the plans that ran, e.g. the plan that actually created the resources in the first step or the plan updating resources in a subsequent step.
### Attempted solutions
Manually look through the TRACE logging to find each plan output.
### Proposal
When executing a plan and when `TF_ACC_PERSIST_WORKING_DIR` is enabled, ensure a plan file is always saved and copy the saved plan with a friendly name. Importantly, these saved plans should _not_ be copied/persisted between steps to prevent confusion.
| Test Step Mode | Plan | Expected Persisted File |
| --- | --- | --- |
| Config | Pre-Apply | config-pre-apply.tfplan |
| Config | Post-Apply Pre-Refresh | config-post-apply-pre-refresh.tfplan |
| Config | Post-Apply Post-Refresh | config-post-apply-post-refresh.tfplan |
| Import | Post-Import | import-post-import.tfplan |
```console
$ tree /Users/bflad/test/testing55
/Users/bflad/test/testing55
0 directories, 0 files
$ TF_ACC_PERSIST_WORKING_DIR=1 go test -count=1 -v ./internal/provider
=== RUN TestExampleDataSource_basic
testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/TestExampleDataSource_basic/step_1
--- PASS: TestExampleDataSource_basic (0.54s)
=== RUN TestExampleResource_basic
testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/TestExampleResource_basic/step_1
testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/TestExampleResource_basic/step_2
testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/TestExampleResource_basic/step_3
--- PASS: TestExampleResource_basic (0.89s)
PASS
ok github.com/bflad/terraform-provider-framework/internal/provider 1.717s
$ tree /Users/bflad/test/testing55
/Users/bflad/test/testing55
├── TestExampleDataSource_basic
│ └── step_1
│ ├── config-post-apply-post-refresh.tfplan
│ ├── config-post-apply-pre-refresh.tfplan
│ ├── config-pre-apply.tfplan
│ ├── terraform.tfstate
│ └── terraform_plugin_test.tf
├── TestExampleResource_basic
│ ├── step_1
│ │ ├── config-post-apply-post-refresh.tfplan
│ │ ├── config-post-apply-pre-refresh.tfplan
│ │ ├── config-pre-apply.tfplan
│ │ ├── terraform.tfstate
│ │ ├── terraform.tfstate.backup
│ │ └── terraform_plugin_test.tf
│ ├── step_2
│ │ ├── import-post-import.tfplan
│ │ ├── terraform.tfstate
│ │ ├── terraform.tfstate.backup
│ │ └── terraform_plugin_test.tf
│ └── step_3
│ ├── config-post-apply-post-refresh.tfplan
│ ├── config-post-apply-pre-refresh.tfplan
│ ├── config-pre-apply.tfplan
│ ├── terraform.tfstate
│ ├── terraform.tfstate.backup
│ └── terraform_plugin_test.tf
├── work1058235289
│ ├── terraform.tfstate
│ ├── terraform.tfstate.backup
│ ├── terraform_plugin_test.tf
│ └── tfplan
├── work4271933255
│ ├── terraform.tfstate
│ └── terraform_plugin_test.tf
└── work763334115
├── terraform.tfstate
├── terraform.tfstate.backup
├── terraform_plugin_test.tf
└── tfplan
10 directories, 31 files
```
### References
- #113
- #114
Contributor guide
Assessment
This issue has not been assessed yet.