skip to Main Content

What I’m trying to do: I have set up a self hosted gitlab instance, and I’m working on automating the terraform process with GitLab CI, for which I have to set up a terraform backend. I followed the steps in the official documentation, but unfortunately I run into an error when running the pipeline. This code is found in my .gitlab-ci.yml file, so it runs on my GitLab runner, which uses a docker image based on python:3.9-buster (Debian)

Here is the code in question, of course I edited out the IP address:

- terraform init  
        -backend-config="address=http://ipaddress//api/v4/projects/3/terraform/state/terraform-state/"  
        -backend-config="lock_address=http://ipaddress//api/v4/projects/3/terraform/state/terraform-state/lock"  
        -backend-config="unlock_address=http://ipaddress//api/v4/projects/3/terraform/state/terraform-state/lock"  
        -backend-config="username=root"  
        -backend-config="password=$ACCESSTOKEN"  
        -backend-config="lock_method=POST"  
        -backend-config="unlock_method=DELETE"  
        -backend-config="retry_wait_min=5"

Unfortunately I’m getting this error when the above command gets executed:

Too many command line arguments. Did you mean to use -chdir?

2

Answers


  1. Chosen as BEST ANSWER

    Just in case anyone would get stuck on a similar issue and happens to find this post, changing my script to this format solved the issue:

      - export TF_ADDRESS=http://ipaddress//api/v4/projects/3/terraform/state/terraform-state/
      - export TF_HTTP_ADDRESS=${TF_ADDRESS}
      - export TF_HTTP_LOCK_ADDRESS=${TF_ADDRESS}/lock
      - export TF_HTTP_LOCK_METHOD=POST
      - export TF_HTTP_UNLOCK_ADDRESS=${TF_ADDRESS}/lock
      - export TF_HTTP_UNLOCK_METHOD=DELETE
      - export TF_HTTP_USERNAME=root
      - export TF_HTTP_PASSWORD=$ACCESSTOKEN
      - export TF_HTTP_RETRY_WAIT_MIN=5
      - terraform init -reconfigure
    

  2. Block Scalar also works

    - >- 
          terraform init
          -backend-config="address=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${TF_STATE_NAME}"
          -backend-config="lock_address=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${TF_STATE_NAME}/lock"
          -backend-config="unlock_address=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${TF_STATE_NAME}/lock"
          -backend-config="username=${USERNAME}"
          -backend-config="password=${TF_BOT_GLPAT}"
          -backend-config="lock_method=POST"
          -backend-config="unlock_method=DELETE"
          -backend-config="retry_wait_min=5"
          -backend-config="skip_cert_verification=true"  
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search