Functions/Publish-DatabricksClustersToWorkspace.ps1
<#
.SYNOPSIS Deploys DataBricks Cluster(s) from configuration json file(s) to a workspace .DESCRIPTION Deploys DataBricks Cluster(s) from configuration json file(s) to a workspace .PARAMETER config Configuration json file from the environment used to workout whether to deploy a clusters from a folder or file(s) .PARAMETER bearerToken Your Databricks Bearer token to authenticate to your workspace (see User Settings in Datatbricks WebUI) .PARAMETER localOutputPath The name path of the clusters configuration files. .EXAMPLE Publish-DatabricksClustersToWorkspace -config $config -bearerToken 'dapi1234567890' -localOutputPath ./ .NOTES Author: Sabin IO #> Function Publish-DatabricksClustersToWorkspace { [cmdletbinding()] Param( [parameter(Mandatory = $true)]$config, [parameter(Mandatory = $true)][string]$bearerToken, [parameter(Mandatory = $true)][string]$localOutputPath ) try { if (($config.deployClustersByFolder -eq $true) -and ($config.deployClustersByFileNames.Length -ge 1)) { Write-Error "deployClustersByFolder in config set to true and deployClustersByFileNames has values. Options are mutually exclusive!" Throw } if (($config.deployClustersByFileNames.Length -ge 1) -and (!($config.PSObject.Properties.Item('deployClustersByFolder')))) { Write-Error "deployClustersByFileNames has values, deployClustersByFolder is not defined! Please define deployClustersByFolder as false if you want to use deployClustersByFileNames" Throw } if (($config.deployClustersByFolder -eq $true) -and ($config.deployClustersByFileNames.Length -eq 0)) { Write-Output "[Deploy] clusters by folder, Ignoring deployClustersByFileNames" $clusterConfigFiles = Get-ChildItem -LiteralPath $localOutputPath -Filter "*.cluster.config.json" foreach ($clusterConfig in $clusterConfigFiles) { Publish-DatabricksClusterConfigToWorkspace -config $config ` -bearerToken $bearerToken ` -clusterConfig $clusterConfig } } if (($config.deployClustersByFolder -eq $false) -and ($config.deployClustersByFileNames.Length -ge 1)) { Write-Output "[Deploy] clusters by file(s), Ignoring deployClustersByFolder" foreach ($clusterConfig in $config.deployClustersByFileNames) { $clusterPath = (Join-Path $localOutputPath $clusterConfig) if (Test-Path $clusterPath) { Publish-DatabricksClusterConfigToWorkspace -config $config ` -bearerToken $bearerToken ` -clusterConfig $clusterPath } else { Write-Error "Path $($clusterPath) does not exist. Check file names are correct." } } } } catch { #uh oh throw $_.Exception } } |