I want to deploy databricks notebook using azure devops & terraform.
I get error below:
Error: cannot read notebook: default auth: azure-cli: cannot get access token: ERROR: Please run 'az login' to setup account.
my providers.tf look like this:
terraform {
required_version = ">1.0.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">=3.3.0"
}
azuread = {
source = "hashicorp/azuread"
version = ">=2.22.0"
}
databricks = {
source = "databricks/databricks"
version = ">=1.28.1"
}
}
backend "azurerm" {
# "rg-ne-dev-department-project"
resource_group_name = "devops"
storage_account_name = "sadevop"
container_name = "tf-plans"
key = "notebooks.state.tfstate"
}
}
provider "azurerm" {
features { }
use_msi = true
tenant_id = "xxx"
client_id = "xxx"
client_secret = "xxx"
subscription_id = "xxx"
}
provider "databricks" {
alias = "etl_workspace_provider"
host = data.azurerm_databricks_workspace.etl_workspace.workspace_url
}
everything works ok if I login from vs code on laptop but fails on azure devops pipeline.
YAML Pipeline:
trigger:
- main
pool:
vmImage: ubuntu-latest
parameters:
- name: Action
displayName: Action
type: string
default: 'Plan'
values:
- Plan
- Apply
- Destroy
variables:
- name: backendServiceArm
value: "sp-devops-connection"
- name: backendAzureRmResourceGroupName
value: "devops"
- name: backendAzureRmStorageAccountName
value: "sadevop"
- name: backendAzureRmContainerName
value: "tf-plans"
- name: backendAzureRmKey
value: "notebooks.state.tfstate"
- name: action
value: ${{ parameters.Action }}
steps:
- script: |
echo "(System.DefaultWorkingDirectory): $(System.DefaultWorkingDirectory)"
echo "(build.ArtifactStagingDirectory) - The directory to which all artifacts are copied before being published.: $(build.ArtifactStagingDirectory)"
echo "(build.BinariesDirectory) The directory to which all binaries are copied during the build process.: $(build.BinariesDirectory)"
echo "(build.DefinitionName): $(build.DefinitionName)"
echo "(build.BuildId): $(build.BuildId)"
echo "(build.BuildNumber): $(build.BuildNumber)"
echo "(build.Repository.Name): $(build.Repository.Name)"
echo "(System.DefaultWorkingDirectory): $(System.DefaultWorkingDirectory)"
echo "(System.StageDisplayName): $(System.StageDisplayName)"
echo "(System.JobDisplayName): $(System.JobDisplayName)"
displayName: "Variable Names"
- script: |
echo "Cleaning up build artifacts"
rm -rf $(System.DefaultWorkingDirectory)/dist
displayName: "Clean up build artifacts"
- task: TerraformInstaller@1 # 1st/ install terraform
displayName: "Install Terraform" # install always need to be installed at every stage
inputs:
terraformVersion: "latest"
- task: TerraformTaskV4@4
displayName: Initialize Terraform
inputs:
provider: "azurerm"
command: "init"
backendServiceArm: '${{ variables.backendServiceArm }}'
backendAzureRmResourceGroupName: '${{ variables.backendAzureRmResourceGroupName }}'
backendAzureRmStorageAccountName: '${{ variables.backendAzureRmStorageAccountName }}'
backendAzureRmContainerName: '${{ variables.backendAzureRmContainerName }}'
backendAzureRmKey: '${{ variables.backendAzureRmKey }}'
workingDirectory: '$(System.DefaultWorkingDirectory)/terraform/'
- task: AzureCLI@2
displayName: 'plan '
inputs:
azureSubscription: '${{ variables.backendServiceArm }}'
scriptType: bash
scriptLocation: inlineScript
inlineScript: 'terraform plan'
- task: AzureCLI@2
displayName: 'Azure CLI '
inputs:
azureSubscription: '${{ variables.backendServiceArm }}'
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
echo "##vso[task.setvariable variable=ARM_CLIENT_ID]$servicePrincipalId"
echo "##vso[task.setvariable variable=ARM_CLIENT_SECRET]$servicePrincipalKey"
echo "##vso[task.setvariable variable=ARM_TENANT_ID]$tenantId
"
- task: AzureCLI@2
displayName: 'CLI Plan '
inputs:
azureSubscription: '${{ variables.backendServiceArm }}'
scriptType: bash
scriptLocation: inlineScript
inlineScript: terraform plan -out notebook.state.plan
Currently, pipeline fails at displayName: 'plan '
Error: Error: No configuration files │ │ Plan requires configuration to be present. Planning without a configuration │ would mark everything for destruction, which is normally not what is │ desired. If you would like to destroy everything, run plan with the │ -destroy option. Otherwise, create a Terraform configuration file (.tf │ file) and try again.
Service connection is the owner of the Azure subscription.