-1

I've configured terraform through azure devops pipeline. Now, I donot want to use Null resource to automate by calling my bash and powershell scripts.

I want to use pipeline task to call my scripts. But I didnt find any solution to use the tfvars file variables in powershell task.

Is there any way to do that?

Muhammad_Bilal
  • 107
  • 1
  • 2
  • 14
  • Does this answer your question? [Parsing an output variable, across YAML pipeline, from a powershell script, into a Terraform variable](https://stackoverflow.com/questions/72467031/parsing-an-output-variable-across-yaml-pipeline-from-a-powershell-script-into) – Ecstasy Aug 16 '22 at 04:45
  • [How to Extract the variable values from terraform variables.tf file using PowerShell commands](https://stackoverflow.com/questions/72055453/how-to-extract-the-variable-values-from-terraform-variables-tf-file-using-powers) – Ecstasy Aug 16 '22 at 04:46
  • 1
    Thanks @Deep, the 2nd one helped me out and solve the problem. – Muhammad_Bilal Aug 16 '22 at 10:52
  • You can post the solution as an answer so that it will be helpful to community members who might face the same issue. If it's exactly the same solution as mentioned in the above link then mark it as a duplicate. – Ecstasy Aug 16 '22 at 10:53
  • 1
    okay, I'll do it :) – Muhammad_Bilal Aug 16 '22 at 10:54

1 Answers1

0

Here's the Code which helps me to Get the Raw content of the variable file and after that, I cut out the content according to my need and than use the content by storing it into variables.

        $VariableData = (Get-Content "./Terraform/templates/variables/dev.terraform.tfvarsr" -Raw) 
        $Output=$VariableData.Substring(0,$VariableData.IndexOf("# Storage Account"))
        $location=($Output |ConvertFrom-StringData).location.trim('"')
        $location_abr=($Output |ConvertFrom-StringData).location_abr.trim('"')
        $client_name_prefix=($Output |ConvertFrom-StringData).client_name_prefix.trim('"')
Muhammad_Bilal
  • 107
  • 1
  • 2
  • 14