jason-johnson / azure-pipelines-tasks-terraform

Azure Pipelines extension for Terraform
MIT License
124 stars 53 forks source link

SecureVarFile with PartialConfiguration #303

Closed kalalvishal closed 11 months ago

kalalvishal commented 1 year ago

Hello,

I am trying to use secureVarsFile with AzureRMBackend partial configuration, however the configuration is unable to leverage the securevarfile for some reason. Here is the var file details I am providing:

INPUT_WORKINGDIRECTORY="./AVDDemo/" backendType="azurerm" ensureBackend=true backendServiceArm="ServiceConnectionName" backendAzureRmSubscriptionId="0000-0000-0000-0000-0000-0000" backendAzureRmResourceGroupName="RG-TFState" backendAzureRmResourceGroupLocation="EastUS" backendAzureRmStorageAccountName="strgact1234567899" backendAzureRmContainerName="tfstate" backendAzureRmKey="tfstate.tfstate" allowTelemetryCollection=false backendServiceArmAuthorizationScheme="ServicePrincipal" backendServiceArmSubscriptionId="0000-0000-0000-0000-0000-0000"

I also tried to populate the details completely in example file given here with and without TF_VAR but no luck. I am sure the details are correct as If I give within the yaml templates, works fine.

Any suggestions will be highly appreciated.

jason-johnson commented 1 year ago

So you run the terraform locally and it doesn't work but if you run it in a pipeline it does?

kalalvishal commented 1 year ago

Hi @jason-johnson, if I use securefile in the pipelines it won't work but works fine if I pass the same values as inputs of task.

jason-johnson commented 1 year ago

Could you run a task (e.g. find if on linux) to print out the files in the terraform directory? Just to make sure the secure file is ending up where you expect it to.

jason-johnson commented 1 year ago

Or, are you using the secureVarsFile variable like:

task: TerraformCLI@0
displayName: 'terraform plan'
inputs:
command: plan
workingDirectory: '$(System.DefaultWorkingDirectory)'
environmentServiceName: '***'
secureVarsFile: 'myFile'

?

kalalvishal commented 1 year ago

@jason-johnson I am passing it like:

kalalvishal commented 1 year ago

Could you run a task (e.g. find if on linux) to print out the files in the terraform directory? Just to make sure the secure file is ending up where you expect it to.

yes, I tried to run ls and I can see the file. Also, in the pipeline run log with debug I see the the file details: ##[debug]secure file name for id 344f26dc-ccde-4f91-b627-XXXXXXXXXXXXX= secure.env

jason-johnson commented 1 year ago

That's bizarre, we have this test which uses secureVarsFile and it's working. I know because when I took over this task I didn't update this file so this test failed until I updated it.

jason-johnson commented 1 year ago

Oh sorry, that's using another task to download the secure file first. This one is using secureVarsFilein the terraformCli task and that is also working. I note it is using the GUID instead of the name though.

kalalvishal commented 1 year ago

@jason-johnson I copied the securefile with CopyFiles@2 to the terraform directory. Also if I do cat, i can see the content of the file. In the example you gave, any reason of not using securefile for init? also, what details are you passing in the securefile?

jason-johnson commented 1 year ago

The first example did not use the secureVarsFile field and I'm not sure why. The second example does use it and that one is also passing the test just fine. I know the file is being used because when I took over this project I didn't have the file and the task was failing until I made one with the correct values. It just has backend variables.

jason-johnson commented 11 months ago

Hi @kalalvishal, were you able to resolve this?

jason-johnson commented 11 months ago

No further updates received. Closing. Feel free to open if there is any additional information.