My plan phase keeps failing during plan phase.
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
+ terraform plan '-out=plan.cache'
Error: Error locking state: Error acquiring the state lock: Unexpected HTTP response code 404
Terraform acquires a state lock to protect the state from being written
by multiple users at the same time. Please resolve the issue above and try
again. For most commands, you can disable locking with the "-lock=false"
flag, but this is not recommended.
Here is the ci file.
image:
name: registry.gitlab.com/gitlab-org/terraform-images/releases/0.14
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
variables:
TF_ROOT: ${CI_PROJECT_DIR}
TF_STATE_NAME: s3-bucket-tfstate
TF_CACHE_KEY: s3-bucket-tfstate
TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${CI_PROJECT_NAME}/s3-bucket-tfstate
GITLAB_TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${CI_PROJECT_NAME}/s3-bucket-tfstate
cache:
key: s3-resource
paths:
- ${TF_ROOT}/s3-resource/.terraform
before_script:
- cd ${TF_ROOT}
stages:
- s3_bucket_prepare_validate
- s3_bucket_plan
- s3_bucket_apply
# - validate
# - plan
s3_bucket_prepare_validate:
stage: s3_bucket_prepare_validate
script:
- cd s3-resource
- echo $GITLAB_TF_ADDRESS
- gitlab-terraform init -backend-config="address=${GITLAB_TF_ADDRESS}" \
-backend-config="lock_address=${GITLAB_TF_ADDRESS}/lock" \
-backend-config="unlock_address=${GITLAB_TF_ADDRESS}/lock" \
-backend-config="username=${GITLAB_USER_LOGIN}" \
-backend-config="password=${GITLAB_TF_PASSWORD}" \
-backend-config="lock_method=POST" \
-backend-config="unlock_method=DELETE" \
-backend-config="retry_wait_min=5" \
- gitlab-terraform validate
s3_bucket_plan:
stage: s3_bucket_plan
script:
- cd s3-resource
- echo $GITLAB_TF_ADDRESS
- gitlab-terraform plan
- gitlab-terraform plan-json
dependencies:
- s3_bucket_prepare_validate
artifacts:
paths:
- ${TF_ROOT}/s3-resource/plan.cache
reports:
terraform: ${TF_ROOT}/s3-resource/plan.cache
s3_bucket_apply:
stage: s3_bucket_apply
script:
- cd s3-resource
- gitlab-terraform apply
dependencies:
- s3_bucket_plan
when: manual
only:
- master
curl -H “private-token: xxxxxxx” https://gitlab.com/api/v4/projects/xxxxxx/terraform/state/terraform/s3-bucket-tfstate/lock
{“error”:“404 Not Found”}