79386765

Date: 2025-01-25 13:10:01
Score: 0.5
Natty:
Report link

create a new branch. Copy the json file to name it, terraform.tfstate to the same directory as the main.tf file.

Use the code below to initialize the project.

PROJECT_ID="*<gitlab-project-id>*"
TF_USERNAME="*<gitlab-username>*"
TF_PASSWORD="*<gitlab-personal-access-token>*"
TF_ADDRESS="https://gitlab.domain/api/v4/projects/${PROJECT_ID}/terraform/state/**old-state-name**"

terraform init \
  -backend-config=address=${TF_ADDRESS} \
  -backend-config=lock_address=${TF_ADDRESS}/lock \
  -backend-config=unlock_address=${TF_ADDRESS}/lock \
  -backend-config=username=${TF_USERNAME} \
  -backend-config=password=${TF_PASSWORD} \
  -backend-config=lock_method=POST \
  -backend-config=unlock_method=DELETE \
  -backend-config=retry_wait_min=5

At the end, it'll ask you if you want to copy the state to the new back end, type 'yes'.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Jason Sherman