Add testenv.Destroy for deleting resources #29
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
testenv.Destroy()
can be used to delete resources from a terraform configuration directory without going through the whole infrastructure set up steps. This is to be used in CI to always run at the end to make sure that everything has been destroyed after the test run.In ideal case, this won't be needed, as the environment constructor,
testenv.New()
, has signal handlers to gracefully delete the infrastructure. But if the whole test process gets terminated, a new process can just runtestenv.Destroy()
to perform the cleanup separately, ensuring everything gets deleted.This is based on a recently failure in pkg repo OCI GCP integration test. The GKE cluster creation took more than 30 minutes. The test runner timed out and terminated with the following error:
*** Test killed with quit: ran too long (31m0s).
In the GKE dashboard, it showed that some of the provisioned nodes were not healthy. This happened for the first time.
Refer: https://github.com/fluxcd/pkg/actions/runs/7409263553/job/20159178143#step:13:338
To handle such scenarios, a new step can be added in github workflows to run a new process that just runs terraform destroy with all the configurations that were used to provision the infrastructure. This can run with its own timeout, without affecting the test run.
In addition, the testenv
Environment
now hastfApplyOptions
andtfDestroyOptions
to configure the terraform apply and destroy options. This is added due to the need to ignore lock state in destroy-only mode.See fluxcd/pkg#712 for an example of how this is used.