Home > Software design >  Retrieve powershell variable in azure devops task and assign to terraform conf
Retrieve powershell variable in azure devops task and assign to terraform conf

Time:10-03

I have an Azire Devops release pipeline, in which i have a task executing a powershell script. In this script, i retrieve the uuid of a (nutanix) vlan according to its name, like this :

parameters:
- name: vlan
  displayName: vlan
  type: string
  default: VLAN_DMZ_1
  values:
  - VLAN_DMZ_1
  - VLAN_DMZ_2

steps:
- task: petergroenewegen.PeterGroenewegen-Xpirit-Vsts-Build-InlinePowershell.Xpirit-Vsts-Build-InlinePowershell.InlinePowershell@1
  displayName: 'Check Parameters'
  inputs:
    Script: 
     $NIC = Get-NTNXNetwork | where { $_.name -eq  "${{ parameters.vlan }}" } | select uuid -ExpandProperty uuid

How can i retrieve the value of this variable into the .tf file?

I tried this :

 nic_list {
    subnet_uuid = "$(NIC)"
  }

But it doesn't work (it takes $(NIC) as the value itself), tried the replace token but it does not seem to be what i am looking for.

Thank your for your help.

CodePudding user response:

The correct way to implement would be to define your terraform variable in the variables.tf file and then pass the variable through Azure devops pipeline from terraform plan command. For example in the below plan I pass into environment terraform variable the azure devops environment parameter.

terraform plan -input=false -out=tf_plan -var=environment="${{ parameters.environment }}"

Otherwise you could just append the value on the .tfvars file that you want. This should be done in powershell

Write-Output "subnet_uuid = $(NIC)" >> terraform_folder\terraform.tfvars
  • Related