Skip to content

Commit aafa7d5

Browse files
authored
Fix #294 - Reliable indication of Azure (#312)
* DatabricksClient.IsAzure is checking for both resource id and workspace hostname * Added more unit test coverage for ClustersAPI * Fixed version linking Co-authored-by: Serge Smertin <[email protected]>
1 parent 5f882dd commit aafa7d5

File tree

11 files changed

+623
-68
lines changed

11 files changed

+623
-68
lines changed

.goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ builds:
1010
binary: terraform-provider-databricks_{{ .Tag }}
1111
ldflags:
1212
# sets client version, not the default main.version
13-
- '-X "common.version={{ replace .Version "v" "" }}"'
13+
- '-X github.com/databrickslabs/databricks-terraform/common.version={{ replace .Version "v" "" }}'
1414
goos:
1515
- windows
1616
- linux

Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,25 @@ coverage: test
1818
@echo "✓ Opening coverage for unit tests..."
1919
@go tool cover -html=coverage.txt
2020

21+
VERSION = $(shell git describe --long --always | sed 's/v//')
22+
2123
build:
2224
@echo "✓ Building source code with go build..."
23-
@go build -mod vendor -v -ldflags="-X 'common.version=$(git describe --long --always | sed 's/v//')'" -o terraform-provider-databricks
25+
@go build -mod vendor -v -ldflags="-X github.com/databrickslabs/databricks-terraform/common.version=${VERSION}" -o terraform-provider-databricks
2426

2527
install: build
2628
@echo "✓ Installing provider into ~/.terraform.d/plugins ..."
2729
@test -d $(HOME)/.terraform.d/plugins && rm $(HOME)/.terraform.d/plugins/terraform-provider-databricks* || mkdir -p $(HOME)/.terraform.d/plugins
2830
@cp terraform-provider-databricks $(HOME)/.terraform.d/plugins
29-
@mkdir -p '$(HOME)/.terraform.d/plugins/registry.terraform.io/databrickslabs/databricks/$(shell git describe --long --always | sed 's/v//')/$(shell go version | awk '{print $$4}' | sed 's#/#_#')'
30-
@cp terraform-provider-databricks '$(HOME)/.terraform.d/plugins/registry.terraform.io/databrickslabs/databricks/$(shell git describe --long --always | sed 's/v//')/$(shell go version | awk '{print $$4}' | sed 's#/#_#')'
31+
@mkdir -p '$(HOME)/.terraform.d/plugins/registry.terraform.io/databrickslabs/databricks/${VERSION}/$(shell go version | awk '{print $$4}' | sed 's#/#_#')'
32+
@cp terraform-provider-databricks '$(HOME)/.terraform.d/plugins/registry.terraform.io/databrickslabs/databricks/${VERSION}/$(shell go version | awk '{print $$4}' | sed 's#/#_#')'
3133
@echo "✓ Use the following configuration to enable the version you've built"
3234
@echo
3335
@echo "terraform {"
3436
@echo " required_providers {"
3537
@echo " databricks = {"
3638
@echo ' source = "databrickslabs/databricks"'
37-
@echo ' version = "$(shell git describe --long --always | sed 's/v//')"'
39+
@echo ' version = "${VERSION}"'
3840
@echo " }"
3941
@echo " }"
4042
@echo "}"

common/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func (c *DatabricksClient) configureHTTPCLient() {
210210
}
211211
}
212212

213-
// IsUsingAzureAuth returns true if Azure authentication is configured, this is not a valid check to determine if we are running on Azure
214-
func (c *DatabricksClient) IsUsingAzureAuth() bool {
215-
return c.AzureAuth.resourceID() != ""
213+
// IsAzure returns true if client is configured for Azure Databricks - either by using AAD auth or with host+token combination
214+
func (c *DatabricksClient) IsAzure() bool {
215+
return c.AzureAuth.resourceID() != "" || strings.Contains(c.Host, "azuredatabricks.net")
216216
}

compute/clusters.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,7 @@ func (a ClustersAPI) Unpin(clusterID string) error {
230230
// up to 70 of the most recently terminated interactive clusters in the past 30 days,
231231
// and up to 30 of the most recently terminated job clusters in the past 30 days
232232
func (a ClustersAPI) List() ([]ClusterInfo, error) {
233-
var clusterList = struct {
234-
Clusters []ClusterInfo `json:"clusters,omitempty" url:"clusters,omitempty"`
235-
}{}
233+
var clusterList ClusterList
236234
err := a.client.Get("/clusters/list", nil, &clusterList)
237235
return clusterList.Clusters, err
238236
}
@@ -281,7 +279,7 @@ func (a ClustersAPI) GetOrCreateRunningCluster(name string, custom ...Cluster) (
281279
NodeTypeID: smallestNodeType,
282280
AutoterminationMinutes: 10,
283281
}
284-
if !a.client.IsUsingAzureAuth() {
282+
if !a.client.IsAzure() {
285283
r.AwsAttributes = &AwsAttributes{
286284
Availability: "SPOT",
287285
}
@@ -296,7 +294,7 @@ func (a ClustersAPI) GetOrCreateRunningCluster(name string, custom ...Cluster) (
296294
func (a ClustersAPI) GetSmallestNodeTypeWithStorage() string {
297295
nodeTypes, err := a.ListNodeTypes()
298296
if err != nil || len(nodeTypes) == 0 {
299-
if a.client.IsUsingAzureAuth() {
297+
if a.client.IsAzure() {
300298
return "Standard_D3_v2"
301299
}
302300
return "i3.xlarge"

0 commit comments

Comments
 (0)