Too many command line arguments Terraform plan
Asked Answered
S

4

6

I am new to terraform. I am trying to create a simple storage account through azure pipeline, however when I run my pipeline I get the error "Too many command line arguments". I am struck and I do not know what I am doing wrong. Can someone please help.

this is my plan script in pipeline:

- script:
    terraform plan -out = plan.tfplan    
  displayName: Terraform plan
  workingDirectory: $(System.DefaultWorkingDirectory)/terraform
  env:
    ARM_CLIENT_ID: $(application_id)
    ARM_CLIENT_SECRET: $(client_secret)
    ARM_TENANT_ID: $(tenant_id)
    ARM_SUBSCRIPTION_ID: $(subscription_id)
    TF_VAR_client_id: $(application_id) 
    TF_VAR_tenant_id: $(tenant_id) 
    TF_VAR_subscription_id: $(subscription_id) 
    TF_VAR_client_secret: $(client_secret

The error that I am getting:

Starting: Terraform plan

Generating script.
Script contents:
terraform plan -out = plan.tfplan
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/3d07140f-ec17-4bfc-9384-a1170fae1248.sh
╷
│ Error: Too many command line arguments
│ 
│ To specify a working directory for the plan, use the global -chdir flag.
╵

For more help on using this command, run:
  terraform plan -help
##[error]Bash exited with code '1'.
Finishing: Terraform plan
Sophiasophie answered 23/3, 2022 at 13:17 Comment(0)
B
6

This has extra spaces, which are not valid:

terraform plan -out = plan.tfplan  

It should be like the following:

terraform plan -out=plan.tfplan  
Behan answered 23/3, 2022 at 13:44 Comment(0)
P
5

My two cents.

Ran the following command

terraform plan -out main.tfplan -var-file=secrets.tfvars

and got the following error.

╷
│ Error: Too many command line arguments
│
│ To specify a working directory for the plan, use the global -chdir flag.
╵

For more help on using this command, run:
  terraform plan -help

Turns out two hyphens(--var-file) instead of one(-var-file) are needed before var-file

terraform plan -out main.tfplan --var-file=secrets.tfvars
Pip answered 30/7, 2022 at 13:59 Comment(1)
I am learning terraform import based on terraform document and faced the same problem, this one solved my issue.Falstaffian
T
1

It seems the help is a bit off. It works like this:

terraform plan -var-file secrets.tfvars

OR

terraform plan --var-file=secrets.tfvars

The same with other options like out, state etc.

Tonina answered 7/11, 2022 at 9:31 Comment(0)
P
1

Please enclose them within the single quote as below

terraform plan '-var-file=variable.tfvars' '-out=tfplan'
Press answered 2/1, 2023 at 20:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.