diags=diags.Append(tfdiags.Sourceless(tfdiags.Error,"Test interrupted","The test operation could not be completed due to an interrupt signal. Please read the remaining diagnostics carefully for any sign of failed state cleanup or dangling resources."))
diags=diags.Append(tfdiags.Sourceless(tfdiags.Error,"Test interrupted","The test operation could not be completed due to an interrupt signal. Please read the remaining diagnostics carefully for any sign of failed state cleanup or dangling resources."))
diags=diags.Append(tfdiags.Sourceless(tfdiags.Error,"Test interrupted","The test operation could not be completed due to an interrupt signal. Please read the remaining diagnostics carefully for any sign of failed state cleanup or dangling resources."))
diags=diags.Append(tfdiags.Sourceless(tfdiags.Error,"Test interrupted","The test operation could not be completed due to an interrupt signal. Please read the remaining diagnostics carefully for any sign of failed state cleanup or dangling resources."))
{"@level":"info","@message":"Found 1 file and 2 run blocks","@module":"terraform.ui","@timestamp":"2023-09-12T08:29:27.268731+02:00","test_abstract":{"main.tftest.hcl":["defaults","overrides"]},"type":"test_abstract"}
{"@level":"info","@message":"main.tftest.hcl... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@timestamp":"2023-09-12T08:29:27.268889+02:00","test_file":{"path":"main.tftest.hcl","progress":"starting"},"type":"test_file"}
{"@level":"info","@message":"Found 1 file and 1 run block","@module":"terraform.ui","@timestamp":"2023-09-28T14:57:09.189212+02:00","test_abstract":{"main.tftest.hcl":["just_go"]},"type":"test_abstract"}
{"@level":"info","@message":"main.tftest.hcl... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@timestamp":"2023-09-28T14:57:09.189386+02:00","test_file":{"path":"main.tftest.hcl","progress":"starting"},"type":"test_file"}
{"@level":"info","@message":" \"just_go\"... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"just_go","@timestamp":"2023-09-28T14:57:09.189429+02:00","test_run":{"path":"main.tftest.hcl","run":"just_go","progress":"starting","elapsed":0},"type":"test_run"}
{"@level":"info","@message":" \"just_go\"... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"just_go","@timestamp":"2023-09-28T14:57:11.341278+02:00","test_run":{"path":"main.tftest.hcl","run":"just_go","progress":"running","elapsed":2152},"type":"test_run"}
{"@level":"info","@message":" \"just_go\"... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"just_go","@timestamp":"2023-09-28T14:57:13.343465+02:00","test_run":{"path":"main.tftest.hcl","run":"just_go","progress":"running","elapsed":4154},"type":"test_run"}
{"@level":"info","@message":"Found 1 file and 2 run blocks","@module":"terraform.ui","@timestamp":"2023-09-12T09:24:05.440805+02:00","test_abstract":{"main.tftest.hcl":["defaults","overrides"]},"type":"test_abstract"}
{"@level":"info","@message":"main.tftest.hcl... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@timestamp":"2023-09-12T09:24:05.440916+02:00","test_file":{"path":"main.tftest.hcl","progress":"starting"},"type":"test_file"}
{"@level":"info","@message":"\nInterrupt received.\nPlease wait for Terraform to exit or data loss may occur.\nGracefully shutting down...\n","@module":"terraform.ui","@timestamp":"2023-09-12T09:24:05.606776+02:00","type":"log"}
{"@level":"info","@message":"Found 1 file and 2 run blocks","@module":"terraform.ui","@timestamp":"2023-09-12T09:25:39.771279+02:00","test_abstract":{"main.tftest.hcl":["defaults","overrides"]},"type":"test_abstract"}
{"@level":"info","@message":"main.tftest.hcl... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@timestamp":"2023-09-12T09:25:39.771341+02:00","test_file":{"path":"main.tftest.hcl","progress":"starting"},"type":"test_file"}
{"@level":"info","@message":"\nInterrupt received.\nPlease wait for Terraform to exit or data loss may occur.\nGracefully shutting down...\n","@module":"terraform.ui","@timestamp":"2023-09-12T09:25:41.055021+02:00","type":"log"}
{"@level":"info","@message":"\nTwo interrupts received. Exiting immediately. Note that data loss may have occurred.\n","@module":"terraform.ui","@timestamp":"2023-09-12T09:25:41.206917+02:00","type":"log"}
{"@level":"error","@message":"Terraform was interrupted during test execution, and may not have performed the expected cleanup operations.","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"overrides","@timestamp":"2023-09-12T09:25:41.207183+02:00","test_interrupt":{"planned":["time_sleep.wait_5_seconds","tfcoremock_simple_resource.resource"]},"type":"test_interrupt"}
{"@level":"error","@message":"Error: Test interrupted","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"overrides","@timestamp":"2023-09-12T09:25:41.210638+02:00","diagnostic":{"severity":"error","summary":"Test interrupted","detail":"The test operation could not be completed due to an interrupt signal. Please read the remaining diagnostics carefully for any sign of failed state cleanup or dangling resources."},"type":"diagnostic"}
{"@level":"error","@message":"Error: Create time sleep error","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"overrides","@timestamp":"2023-09-12T09:25:41.211201+02:00","diagnostic":{"severity":"error","summary":"Create time sleep error","detail":"Original Error: context canceled","address":"time_sleep.wait_5_seconds","range":{"filename":"main.tf","start":{"line":7,"column":40,"byte":110},"end":{"line":7,"column":41,"byte":111}},"snippet":{"context":"resource \"time_sleep\" \"wait_5_seconds\"","code":"resource \"time_sleep\" \"wait_5_seconds\" {","start_line":7,"highlight_start_offset":39,"highlight_end_offset":40,"values":[]}},"type":"diagnostic"}
{"@level":"info","@message":"Found 1 file and 1 run block","@module":"terraform.ui","@timestamp":"2023-09-28T14:57:09.189212+02:00","test_abstract":{"main.tftest.hcl":["just_go"]},"type":"test_abstract"}
{"@level":"info","@message":"main.tftest.hcl... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@timestamp":"2023-09-28T14:57:09.189386+02:00","test_file":{"path":"main.tftest.hcl","progress":"starting"},"type":"test_file"}
{"@level":"info","@message":" \"just_go\"... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"just_go","@timestamp":"2023-09-28T14:57:09.189429+02:00","test_run":{"path":"main.tftest.hcl","run":"just_go","progress":"starting","elapsed":0},"type":"test_run"}
{"@level":"info","@message":" \"just_go\"... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"just_go","@timestamp":"2023-09-28T14:57:11.341278+02:00","test_run":{"path":"main.tftest.hcl","run":"just_go","progress":"running","elapsed":2152},"type":"test_run"}
{"@level":"info","@message":" \"just_go\"... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"just_go","@timestamp":"2023-09-28T14:57:13.343465+02:00","test_run":{"path":"main.tftest.hcl","run":"just_go","progress":"running","elapsed":4154},"type":"test_run"}
{"@level":"info","@message":"Found 1 file and 2 run blocks","@module":"terraform.ui","@timestamp":"2023-09-12T08:30:36.453493+02:00","test_abstract":{"main.tftest.hcl":["defaults","overrides"]},"type":"test_abstract"}
{"@level":"info","@message":"main.tftest.hcl... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@timestamp":"2023-09-12T08:30:36.453557+02:00","test_file":{"path":"main.tftest.hcl","progress":"starting"},"type":"test_file"}
{"@level":"info","@message":"-verbose flag enabled, printing plan","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"defaults","@timestamp":"2023-09-12T08:30:37.184891+02:00","test_plan":{"plan_format_version":"1.2","output_changes":{"input":{"actions":["create"],"before":null,"after":"Hello, world!","after_unknown":false,"before_sensitive":false,"after_sensitive":false}},"relevant_attributes":[{"resource":"data.null_data_source.values","attribute":["outputs","data"]}],"provider_format_version":"1.0","provider_schemas":{"registry.terraform.io/hashicorp/null":{"provider":{"version":0,"block":{"description_kind":"plain"}},"resource_schemas":{"null_resource":{"version":0,"block":{"attributes":{"id":{"type":"string","description":"This is set to a random value at create time.","description_kind":"plain","computed":true},"triggers":{"type":["map","string"],"description":"A map of arbitrary strings that, when changed, will force the null resource to be replaced, re-running any associated provisioners.","description_kind":"plain","optional":true}},"description":"The `null_resource` resource implements the standard resource lifecycle but takes no further action.\n\nThe `triggers` argument allows specifying an arbitrary set of values that, when changed, will cause the resource to be replaced.","description_kind":"plain"}}},"data_source_schemas":{"null_data_source":{"version":0,"block":{"attributes":{"has_computed_default":{"type":"string","description":"If set, its literal value will be stored and returned. If not, its value defaults to `\"default\"`. This argument exists primarily for testing and has little practical use.","description_kind":"plain","optional":true,"computed":true},"id":{"type":"string","description":"This attribute is only present for some legacy compatibility issues and should not be used. It will be removed in a future version.","description_kind":"plain","deprecated":true,"computed":true},"inputs":{"type":["map","string"],"description":"A map of arbitrary strings that is copied into the `outputs` attribute, and accessible directly for interpolation.","description_kind":"plain","optional":true},"outputs":{"type":["map","string"],"description":"After the data source is \"read\", a copy of the `inputs` map.","description_kind":"plain","computed":true},"random":{"type":"string","description":"A random value. This is primarily for testing and has little practical use; prefer the [hashicorp/random provider](https://registry.terraform.io/providers/hashicorp/random) for more practical random number use-cases.","description_kind":"plain","computed":true}},"description":"The `null_data_source` data source implements the standard data source lifecycle but does not\ninteract with any external APIs.\n\nHistorically, the `null_data_source` was typically used to construct intermediate values to re-use elsewhere in configuration. The\nsame can now be achieved using [locals](https://www.terraform.io/docs/language/values/locals.html).\n","description_kind":"plain","deprecated":true}}}}}},"type":"test_plan"}
{"@level":"warn","@message":"Warning: Deprecated","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"defaults","@timestamp":"2023-09-12T08:30:37.185952+02:00","diagnostic":{"severity":"warning","summary":"Deprecated","detail":"The null_data_source was historically used to construct intermediate values to re-use elsewhere in configuration, the same can now be achieved using locals","address":"data.null_data_source.values","range":{"filename":"main.tf","start":{"line":7,"column":34,"byte":104},"end":{"line":7,"column":35,"byte":105}},"snippet":{"context":"data \"null_data_source\" \"values\"","code":"data \"null_data_source\" \"values\" {","start_line":7,"highlight_start_offset":33,"highlight_end_offset":34,"values":[]}},"type":"diagnostic"}
{"@level":"warn","@message":"Warning: Deprecated","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"defaults","@timestamp":"2023-09-12T08:30:37.186067+02:00","diagnostic":{"severity":"warning","summary":"Deprecated","detail":"The null_data_source was historically used to construct intermediate values to re-use elsewhere in configuration, the same can now be achieved using locals","address":"data.null_data_source.values","range":{"filename":"main.tf","start":{"line":7,"column":34,"byte":104},"end":{"line":7,"column":35,"byte":105}},"snippet":{"context":"data \"null_data_source\" \"values\"","code":"data \"null_data_source\" \"values\" {","start_line":7,"highlight_start_offset":33,"highlight_end_offset":34,"values":[]}},"type":"diagnostic"}
{"@level":"info","@message":"-verbose flag enabled, printing state","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"overrides","@timestamp":"2023-09-12T08:30:37.246362+02:00","test_state":{"state_format_version":"1.0","root_module":{"resources":[{"address":"data.null_data_source.values","mode":"data","type":"null_data_source","name":"values","provider_name":"registry.terraform.io/hashicorp/null","schema_version":0,"values":{"has_computed_default":"default","id":"static","inputs":{"data":"Hello, universe!"},"outputs":{"data":"Hello, universe!"},"random":"8484833523059069761"},"sensitive_values":{"inputs":{},"outputs":{}}}]},"outputs":{"input":{"sensitive":false,"value":"Hello, universe!","type":"string"}},"provider_format_version":"1.0","provider_schemas":{"registry.terraform.io/hashicorp/null":{"provider":{"version":0,"block":{"description_kind":"plain"}},"resource_schemas":{"null_resource":{"version":0,"block":{"attributes":{"id":{"type":"string","description":"This is set to a random value at create time.","description_kind":"plain","computed":true},"triggers":{"type":["map","string"],"description":"A map of arbitrary strings that, when changed, will force the null resource to be replaced, re-running any associated provisioners.","description_kind":"plain","optional":true}},"description":"The `null_resource` resource implements the standard resource lifecycle but takes no further action.\n\nThe `triggers` argument allows specifying an arbitrary set of values that, when changed, will cause the resource to be replaced.","description_kind":"plain"}}},"data_source_schemas":{"null_data_source":{"version":0,"block":{"attributes":{"has_computed_default":{"type":"string","description":"If set, its literal value will be stored and returned. If not, its value defaults to `\"default\"`. This argument exists primarily for testing and has little practical use.","description_kind":"plain","optional":true,"computed":true},"id":{"type":"string","description":"This attribute is only present for some legacy compatibility issues and should not be used. It will be removed in a future version.","description_kind":"plain","deprecated":true,"computed":true},"inputs":{"type":["map","string"],"description":"A map of arbitrary strings that is copied into the `outputs` attribute, and accessible directly for interpolation.","description_kind":"plain","optional":true},"outputs":{"type":["map","string"],"description":"After the data source is \"read\", a copy of the `inputs` map.","description_kind":"plain","computed":true},"random":{"type":"string","description":"A random value. This is primarily for testing and has little practical use; prefer the [hashicorp/random provider](https://registry.terraform.io/providers/hashicorp/random) for more practical random number use-cases.","description_kind":"plain","computed":true}},"description":"The `null_data_source` data source implements the standard data source lifecycle but does not\ninteract with any external APIs.\n\nHistorically, the `null_data_source` was typically used to construct intermediate values to re-use elsewhere in configuration. The\nsame can now be achieved using [locals](https://www.terraform.io/docs/language/values/locals.html).\n","description_kind":"plain","deprecated":true}}}}}},"type":"test_state"}
{"@level":"warn","@message":"Warning: Deprecated","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"overrides","@timestamp":"2023-09-12T08:30:37.247116+02:00","diagnostic":{"severity":"warning","summary":"Deprecated","detail":"The null_data_source was historically used to construct intermediate values to re-use elsewhere in configuration, the same can now be achieved using locals","address":"data.null_data_source.values","range":{"filename":"main.tf","start":{"line":7,"column":34,"byte":104},"end":{"line":7,"column":35,"byte":105}},"snippet":{"context":"data \"null_data_source\" \"values\"","code":"data \"null_data_source\" \"values\" {","start_line":7,"highlight_start_offset":33,"highlight_end_offset":34,"values":[]}},"type":"diagnostic"}
{"@level":"warn","@message":"Warning: Deprecated","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"overrides","@timestamp":"2023-09-12T08:30:37.247182+02:00","diagnostic":{"severity":"warning","summary":"Deprecated","detail":"The null_data_source was historically used to construct intermediate values to re-use elsewhere in configuration, the same can now be achieved using locals","address":"data.null_data_source.values","range":{"filename":"main.tf","start":{"line":7,"column":34,"byte":104},"end":{"line":7,"column":35,"byte":105}},"snippet":{"context":"data \"null_data_source\" \"values\"","code":"data \"null_data_source\" \"values\" {","start_line":7,"highlight_start_offset":33,"highlight_end_offset":34,"values":[]}},"type":"diagnostic"}
{"@level":"info","@message":"Found 1 file and 2 run blocks","@module":"terraform.ui","@timestamp":"2023-09-12T08:29:27.268731+02:00","test_abstract":{"main.tftest.hcl":["defaults","overrides"]},"type":"test_abstract"}
{"@level":"info","@message":"main.tftest.hcl... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@timestamp":"2023-09-12T08:29:27.268889+02:00","test_file":{"path":"main.tftest.hcl","progress":"starting"},"type":"test_file"}
t.Errorf("failed to unmarshal returned line: %s",line)
continue
}
// Remove the timestamp as it changes every time.
delete(obj,"@timestamp")
ifobj["type"].(string)=="test_run"{
// Then we need to delete the `elapsed` field from within the run
// as it'll cause flaky tests.
run:=obj["test_run"].(map[string]interface{})
ifrun["progress"].(string)!="complete"{
delete(run,"elapsed")
}
}
message,err:=json.Marshal(obj)
iferr!=nil{
t.Errorf("failed to remarshal returned line: %s",line)
continue
}
messages=append(messages,string(message))
}
expected:=[]string{
`{"@level":"info","@message":"Found 1 file and 1 run block","@module":"terraform.ui","test_abstract":{"main.tftest.hcl":["test"]},"type":"test_abstract"}`,
`{"@level":"info","@message":"main.tftest.hcl... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","test_file":{"path":"main.tftest.hcl","progress":"starting"},"type":"test_file"}`,
`{"@level":"info","@message":" \"test\"... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"test","test_run":{"path":"main.tftest.hcl","progress":"starting","run":"test"},"type":"test_run"}`,
`{"@level":"info","@message":" \"test\"... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"test","test_run":{"path":"main.tftest.hcl","progress":"running","run":"test"},"type":"test_run"}`,
`{"@level":"info","@message":" \"test\"... in progress","@module":"terraform.ui","@testfile":"main.tftest.hcl","@testrun":"test","test_run":{"path":"main.tftest.hcl","progress":"running","run":"test"},"type":"test_run"}`,
@ -635,7 +635,7 @@ The `terraform test` command emits a `test_abstract` message describing the test
## Test File
After Terraform completes execution of each test file, `terraform test` emits a `test_file` message with the status of the test file.
Throughout a `terraform test` execution, Terraform will produce several progress updates for each test file. The progress field can be `starting`, `teardown`, or `complete`. Each test file will emit each progress update exactly once. When a test file emits the `complete` progress update, it will also include a status field containing one of `pass`, `error`, `fail`, or `skip` denoting the overall status of the completed test file.
### Example
@ -648,6 +648,7 @@ After Terraform completes execution of each test file, `terraform test` emits a
"@timestamp": "2023-08-09T16:12:30.724368+02:00",
"test_file": {
"path": "validation.tftest.hcl",
"progress": "complete",
"status": "pass"
},
"type": "test_file"
@ -656,9 +657,15 @@ After Terraform completes execution of each test file, `terraform test` emits a
## Test Run
After Terraform completes execution of each test file, `terraform test` emits a series of `test_run` messages with each run block's status within the test file.
While executing `run` blocks within a test file, Terraform will also produce several status updates for each `run` block. The progress field for a `run` block progress update can be `starting`, `running`, `teardown`, and `complete`. The `starting` and `complete` progress updates will be emitted exactly once. While the `running` and `teardown` progress updates can be emitted multiple times.
### Example
The `starting`, `running` and `teardown` updates will also include an `elapsed` field indicating the number of milliseconds the current test operation (for `starting` and `running`) or the current destroy operation (for `teardown`) has been in progress.
The `complete` progress update will also include a `status` field containing one of `pass`, `error`, `fail`, or `skip` denoting the overall status of the completed `run` block`.
Not every `run` block will emit `teardown` progress updates, as only the most recently executed `run` blocks reference the latest in-memory state files that need to be torn down. In addition, the `run` block tear down process is only initiated once the overall test file has already emitted its `teardown` status update. This means you can expect the `complete` progress update to be issued for a `run` block before any `teardown` updates are provided. There will always be a `complete` progress update issued by the enclosing test file when the tear down process for all `run` blocks is complete.
### Examples
```json
{
@ -671,12 +678,31 @@ After Terraform completes execution of each test file, `terraform test` emits a
"test_run": {
"path": "main.tftest.hcl",
"run": "successful_validation",
"progress": "complete",
"status": "pass"
},
"type": "test_run"
}
```
```json
{
"@level": "info",
"@message": " \"successful_validation\"... in progress",
"@module": "terraform.ui",
"@testfile": "validation.tftest.hcl",
"@testrun": "successful_validation",
"@timestamp": "2023-08-09T16:12:30.724407+02:00",
"test_run": {
"path": "main.tftest.hcl",
"run": "successful_validation",
"progress": "running",
"elapsed": 2024
},
"type": "test_run"
}
```
## Test Cleanup
After Terraform completes the execution of each test file, `terraform test` may emit a series of `test_cleanup` messages detailing any state it could not destroy. You must locate and destroy the resources listed in these resources manually.