Closed lupusllc closed 1 year ago
Hi. The instructions for V3 are incorrect and unclear. I am fixing that in the next update. The V2 version of plan did internally first the plan and then again with plan -out {filename}, then a show -json {filename}. this behavior was a bit unclear and not as clean as we wanted it. So for V3 you need to do plan with commandoptions: -out={filename} and then do show with setting outputTo 'file' and outputFormat to 'json' and commandOptions {filename}. You also need to set fileName to '{filename}.json'
the outputvariable will be: showFilePath (https://github.com/microsoft/azure-pipelines-terraform/blob/main/Tasks/TerraformTask/TerraformTaskV3/README.md#output-variables)
example:
- task: TerraformTaskV3@3
name: plan
displayName: 'terraform plan'
inputs:
commandOptions: '-out=<filename>'
provider: 'azurerm'
command: 'plan'
environmentServiceNameAzureRM: '<environmentServiceConnection>'
- task: TerraformTaskV3@3
name: show
displayName: 'terraform show'
inputs:
provider: 'azurerm'
command: 'show'
commandOptions: '<filename>'
outputTo: 'file'
outputFormat: json
fileName: '<filename>.json'
environmentServiceNameAzureRM: '<environmentServiceConnection>'
closing this as a valid solution. feel free re-open if you diagree
@mericstam this does not appear to work with TerraformTaskV4@4
. An output variable with name showFilePath
is not generated.
A normal variable with this name is set as can be seen by this extract from the pipeline log:
##[debug]set showFilePath=/home/vsts/work/1/s/planFile.json
##[debug]Processed: ##vso[task.setvariable variable=showFilePath;isOutput=false;issecret=false;]/home/vsts/work/1/s/planFile.json
##[debug]task result: Succeeded
##[debug]Processed: ##vso[task.complete result=Succeeded;]
Finishing: Terraform: Show
@DavidJFowler please refer to a closed issue rather the posting directly in it. It will be a lot simpler for us to see a new issue the issue list. This time I will reopen it.
no change between v3 and v4 other then updated version of the azure-pipelines-task-lib/task lib which is used for setting variables. my assumption was that they where previously automatically set as output. My guess is that azure-pipelines-task-lib/task, setVariable function has changed behavior. I will take a look
Looks like there was a bit of mix of the setting of output variables. changed them all to output where they should be output.
When doing a Terraform plan in V2 we get an output variable for jsonPlanFilePath but not for V3. Information on this variable is also missing from the readme from V3.
I tried using -out and specifying a tfstate file to output to, but the results were the same with or without -out in V3. I also tried using Terraform show, but it just printed the results to the screen.
V3:
V2: