Loading
Use TF_HTTP_USERNAME and TF_HTTP_PASSWORD in delete-state
What does this MR do?
gitlab-tofu delete-state always authenticated with gitlab-ci-token:$CI_JOB_TOKEN and ignored TF_HTTP_USERNAME and TF_HTTP_PASSWORD. Every other state operation (init, plan, apply, destroy) uses these variables.
This affected the delete-state job and the destroy job with auto_delete_state: true. For example, with a Developer pipeline and a Maintainer project access token set in TF_HTTP_PASSWORD, the deletion got 403 Forbidden. The job still passed, because curl exits with 0 on an HTTP error.
This MR:
- uses
TF_HTTP_ADDRESS,TF_HTTP_USERNAMEandTF_HTTP_PASSWORDfor theDELETErequest, so it targets the same state with the same credentials asinit,planandapply. They are exported byconfigure_variables_for_tofuand default to the GitLab-managed state address,gitlab-ci-tokenand$CI_JOB_TOKEN, so nothing changes when they are not overridden. - adds
--fail-with-body, so the job fails when the state is not deleted and the response body still shows in the job log.
How to test
New unit tests in tests/unit/gitlab-tofu.bats replace curl with a stub and check that:
- the CI job token is used by default
TF_HTTP_USERNAMEandTF_HTTP_PASSWORDare used when set--fail-with-bodyis passed and the command fails when the request failsTF_HTTP_ADDRESSis used as the deletion URL when set
Related issues
Closes #544 (closed)
Edited by Corentin Hervaud