Hey all,
Wondering if anyone has seen this before. Whenever I try to pass in secrets via -var args in Terraform via GitHub actions, I get the failure "Too many command line arguments. Configuration path expected.". I know it's due to the secret because if I try passing the password in via plain text, it works just fine. Take a look at my code below and let me know if I'm being silly :)
- name: "Terraform Plan"
uses: hashicorp/terraform-github-actions@master
with:
tf_actions_version: 0.12.13
tf_actions_subcommand: "plan"
args: '-var="client_secret=${{ secrets.clientSecret }}"'
Edmondo Porcu
@edmondo1984
or maybe terraform validate?
do you like writing tests in ruby, golang, or some DSL?
Edmondo Porcu
@edmondo1984
if that's the difference, probably in ruby
I deploy env and write scripts for tests, I haven't needed those tools. If you like ruby, you might like the tool that uses it. but IDK.
Edmondo Porcu
@edmondo1984
However just reading Terratest documentation, it is clear that there are scenarios for which Terratest is not enough
Below is a list of other infrastructure testing tools you may wish to use in addition to Terratest. Check out How Terratest compares to other testing tools to understand the trade-offs. kitchen-terraform rspec-terraform serverspec inspec Goss awspec Terraform's acceptance testing framework ruby_terraform
I think it's good to do what you are doing, but you are going to spend a lot of time spinning wheels on this path
I would be more clear in your path, and optimize at a reasonable pace
I'm saying this having built many of these tools before they existed, or in parallel with them, or using those tools to build more awesome solutions. I see a need for the use cases described, but whether or not the tool fits is a little more nuanced of a question to answer. I would figure that out with experience. If you don't even have an example project to work with, start there. Make that deploy the way you want
also, checkout the Makefile approach demonstrated in those examples I referenced.
Edmondo Porcu
@edmondo1984
cheers
Ameya
@bluemind2005_twitter
I am not able to understand why terraform apply in not working on my Azure DevOps Build pipeline
2019-01-21T02:35:06.8497053Z ##[debug]Env:INPUT_ARGUMENTS: 'apply -auto-approve "ax.plan"' 2019-01-21T02:35:06.8532216Z ##[debug]Env:INPUT_PLANPATH (empty) 2019-01-21T02:35:06.8861649Z ##[debug]Entering Invoke-VstsTool. 2019-01-21T02:35:06.8970832Z ##[debug] FileName: 'terraform' 2019-01-21T02:35:06.8989419Z ##[debug] Arguments: 'apply -auto-approve "ax.plan" -input=false -no-color' 2019-01-21T02:35:06.9027497Z ##[command]"terraform" apply -auto-approve "ax.plan" -input=false -no-color 2019-01-21T02:35:06.9834162Z Too many command line arguments. Configuration path expected. 2019-01-21T02:35:06.9988391Z ##[debug]Exit code: 1 2019-01-21T02:35:07.0015274Z ##[debug]Leaving Invoke-VstsTool. 2019-01-21T02:35:07.0110043Z ##[error] Terraform failed to execute. Error: 2019-01-21T02:35:07.0119383Z ##[debug]Processed: ##vso[task.logissue type=error;] Terraform failed to execute. Error: 2019-01-21T02:35:07.0134357Z ##[debug]Processed: ##vso[task.complete result=Failed] 2019-01-21T02:35:07.0134528Z End of Task Terraform 2019-01-21T02:35:07.0319572Z ##[section]Finishing: Terraform apply -auto-approve "ax.plan"Note: I have also tried terraform apply "ax.plan" -auto-approve
terraform apply -auto-approve "ax.plan" does work on command line but not in Azure DevOps! Unable to understand where is the problem!
Ameya
@bluemind2005_twitter
Output from previous task
terraform plan -out ax.planKindly refer to the screenshot above
does that work when you run it yourself? EDIT, sorry, I see where you mention that
IDK enough about azure pipelines
It probably isn't an issue, but I don't see why you'd need the -auto-approve if you are using -out with plan
Ameya
@bluemind2005_twitter
maybe the output of the terraform plan has to be stored
if you are not saving the plan as an artifact, or have some auto-caching, and you have separate "stages" here, that would be an issue (need the plan file to apply it)
Ameya
@bluemind2005_twitter
yes you need to as -out with plan is just a plan but Terraform has explicitly added "approval" hence need to use flag -auto-approve
I use plan with -out all the time and have never used -auto-approve when applying the plan file
-auto-approve is for when you are not using a plan file
Ameya
@bluemind2005_twitter
Let me re-check
Ameya
@bluemind2005_twitter
2019-01-21T03:21:16.3155259Z Terraform version: 2019-01-21T03:21:18.5001821Z Terraform v0.11.11 2019-01-21T03:21:18.7452175Z + provider.azurerm v1.21.0 2019-01-21T03:21:18.7452306Z 2019-01-21T03:21:18.7636650Z ##[debug]Env:INPUT_ARGUMENTS: 'apply "ax.plan"' 2019-01-21T03:21:18.7674073Z ##[debug]Env:INPUT_PLANPATH (empty) 2019-01-21T03:21:18.7971184Z ##[debug]Entering Invoke-VstsTool. 2019-01-21T03:21:18.8077204Z ##[debug] FileName: 'terraform' 2019-01-21T03:21:18.8094467Z ##[debug] Arguments: 'apply "ax.plan" -input=false -no-color' 2019-01-21T03:21:18.8131960Z ##[command]"terraform" apply "ax.plan" -input=false -no-color 2019-01-21T03:21:18.8911687Z Too many command line arguments. Configuration path expected. 2019-01-21T03:21:18.9063569Z ##[debug]Exit code: 1 2019-01-21T03:21:18.9076066Z ##[debug]Leaving Invoke-VstsTool. 2019-01-21T03:21:18.9168535Z ##[error] Terraform failed to execute. Error: 2019-01-21T03:21:18.9176859Z ##[debug]Processed: ##vso[task.logissue type=error;] Terraform failed to execute. Error: 2019-01-21T03:21:18.9190270Z ##[debug]Processed: ##vso[task.complete result=Failed] 2019-01-21T03:21:18.9191102Z End of Task Terraform 2019-01-21T03:21:18.9387221Z ##[section]Finishing: Terraform apply "ax.plan"
Agreed, -auto-approve i not required but still this bugger is not working........
@bluemind2005_twitter have you tried to put the planfile reference after the params?
terraform apply -input=false -no-color ax.plan
Ameya
@bluemind2005_twitter
To be very honest with you I have no idea from where Azure Pipelines/Azure DevOps/VSTS is adding "-input=false -no-color" as that is certainly not in my build task definition.
I tried what you suggested me above and Azure Pipelines added "-input=false -no-color" at the end of it, I doubt that is what is causing us the grief. Please refer to the output below. I am using Terraform plugin by Peter G. I can successfully executed terraform init terraform plan and apply via shell script and it works like a charm so I don't believe this is issue with Terraform itself but with the plugin OR Azure Pipelines itself.
2019-01-21T03:36:32.1873397Z Terraform version: 2019-01-21T03:36:34.0170195Z Terraform v0.11.11 2019-01-21T03:36:34.2648967Z + provider.azurerm v1.21.0 2019-01-21T03:36:34.2651250Z 2019-01-21T03:36:34.2829440Z ##[debug]Env:INPUT_ARGUMENTS: 'apply -input=false -no-color ax.plan' 2019-01-21T03:36:34.2868750Z ##[debug]Env:INPUT_PLANPATH (empty) 2019-01-21T03:36:34.3213433Z ##[debug]Entering Invoke-VstsTool. 2019-01-21T03:36:34.3322814Z ##[debug] FileName: 'terraform' 2019-01-21T03:36:34.3341085Z ##[debug] Arguments: 'apply -input=false -no-color ax.plan -input=false -no-color' 2019-01-21T03:36:34.3378325Z ##[command]"terraform" apply -input=false -no-color ax.plan -input=false -no-color 2019-01-21T03:36:34.4357582Z Too many command line arguments. Configuration path expected. 2019-01-21T03:36:34.4515192Z ##[debug]Exit code: 1 2019-01-21T03:36:34.4542614Z ##[debug]Leaving Invoke-VstsTool. 2019-01-21T03:36:34.4946022Z ##[error] Terraform failed to execute. Error: 2019-01-21T03:36:34.4954930Z ##[debug]Processed: ##vso[task.logissue type=error;] Terraform failed to execute. Error: 2019-01-21T03:36:34.4967756Z ##[debug]Processed: ##vso[task.complete result=Failed] 2019-01-21T03:36:34.4967914Z End of Task Terraform 2019-01-21T03:36:34.5172070Z ##[section]Finishing: Terraform apply -input=false -no-color ax.planI think the doc is pretty clear
ᐅ tf apply -h Usage: terraform apply [options] [DIR-OR-PLAN] Builds or changes infrastructure according to Terraform configuration files in DIR.
so I think that's why you are getting the error
Too many command line arguments. Configuration path expected.
Ameya
@bluemind2005_twitter
Yep, need to figure it out from where the the redundant arguments are been added ;(
Ameya
@bluemind2005_twitter
it's a bug in terraform
I don't see the bug, except that tf apply -input plan.file -no-color should fail
the docs are clear, all options should be before the directory path or plan file path
Ameya
@bluemind2005_twitter
Yep, you are right. I tested it as well and it works as long as we conform to
terraform apply [options] [DIR-OR-PLAN]
But still not able to figure it out why terraform plaugin in Azure DevOps/pipelines is adding options at the end of the arguments.
Ameya
@bluemind2005_twitter
Just a quick one, how to run terraform plan for a single terraform file when there are multiple files?
Example: I have three terraform IaaC files and I want terraform plan on a specific file, how to do that?
a.tf, b.tf and c.tf
terraform plan a.tf ?
I don't want anything to be filtered on resource but filter on file
Looks like I need to create separate folders for each tf file?
But still not able to figure it out why terraform plaugin in Azure DevOps/pipelines is adding options at the end of the arguments.
I think the plugin is assuming you would not use a plan file