Home > Net >  Github Actions - Terraform Init - Too many command line arguments
Github Actions - Terraform Init - Too many command line arguments

Time:02-03

I'm currently working on a pipeline where I'm using some backend to ensure my terraform forms will run but the problem that I have is that I'm getting the following issue:

 Too many command-line arguments. Did you mean to use -chdir?
Error: Terraform exited with code 1.
Error: Process completed with exit code 1.

My current command is the following:

        - name: Terraform Init
          run: | 
            terraform init -backend=true -input=false \
            -backend-config=subscription_id=${{ secrets.AZURE_SUBS_ID}} \ 
            -backend-config=resource_group_name={{ secrets.AZURE_RG }} \
            -backend-config=storage_accname=${{ SECRETS.AZURE_AD_STORAGE_ACCOUNT }} \
            -backend-config=container_name="tfstate"  \
            -backend-config=tenant_id=${{ secrets.AZURE_TENANT_ID }} \
            -backend-config=client_id=${{ secrets.AZURE_CLIENT_ID }} \
            -backend-config=client_secret=${{ secrets.AZURE_CSECRET }}

By using my terminal, I can use a file like this, and I'm able to set up all my environment variables on my local machine. However, when I'm using the pipelines it seems that I can't do that. Does anyone know what is the best thing to do?

CodePudding user response:

This is most likely a YAML formatting issue here as the Terraform argument parsing logic is throwing the error. The | inserts newline characters at the end of each line. You need > instead. The \ are also unnecessary as this is a multi-line YAML string, and not a multi-line shell interpreter command:

- name: Terraform Init
  run: > 
    terraform init -backend=true -input=false
    -backend-config=subscription_id=${{ secrets.AZURE_SUBS_ID}}
    -backend-config=resource_group_name={{ secrets.AZURE_RG }}
    -backend-config=storage_accname=${{ SECRETS.AZURE_AD_STORAGE_ACCOUNT }}
    -backend-config=container_name="tfstate"
    -backend-config=tenant_id=${{ secrets.AZURE_TENANT_ID }}
    -backend-config=client_id=${{ secrets.AZURE_CLIENT_ID }}
    -backend-config=client_secret=${{ secrets.AZURE_CSECRET }}
  • Related