3
votes

I'm trying to pass the databricks workspace name that is generated from the terraform deployment with Azure DevOps to another step as a variable but not sure how to do.

So I defined the output in my output.tf

output "workspace_name" {
  value = azurerm_databricks_workspace.databricks.name
}

and I can see the output :

enter image description here

and going through stackoverflow, there is a solution to make all of your outputs as variables automatically:

1- configure output variable:

enter image description here

2- configure powershell script to get them and populate it

powershell

3- now what ? what will the variable name be, and how can I use it in the Databricks Bearer Token solution ?

2
do you not understand the code you are using? the name would be workspace_name4c74356b41

2 Answers

3
votes
$json = Get-Content $env:jsonPath | Out-String | ConvertFrom-Json

foreach($prop in $json.psobject.properties) {
    Write-Host("##vso[task.setvariable variable=$($prop.Name);]$($prop.Value.value)")
}

The logic of this script is used to loop through the output json file that your previous terraform generated.

And this line "##vso[task.setvariable variable=$($prop.Name);]$($prop.Value.value)" aim to setting the name which showed in the output json file as the pipeline variable name, also set its corresponding value from output json file to the value of its pipeline variable.

Here is their mapping show:

Terraform Output Json                          Azure devops pipeline 

   Output name            ================>      varaible name

   Output value           ================>      variable value

So, in Databricks Bearer Token task, you can directly call the variable via its name you configured in terraform file: workspace_name.

2
votes

I've noticed that you're using Azure Devops to create Databricks Bearer token, which can be simplified by using Databricks Labs Terraform provider, which supports AAD tokens.