Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #294 - Reliable indication of Azure #312

Merged
merged 2 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ builds:
binary: terraform-provider-databricks_{{ .Tag }}
ldflags:
# sets client version, not the default main.version
- '-X "common.version={{ replace .Version "v" "" }}"'
- '-X github.com/databrickslabs/databricks-terraform/common.version={{ replace .Version "v" "" }}'
goos:
- windows
- linux
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,25 @@ coverage: test
@echo "✓ Opening coverage for unit tests..."
@go tool cover -html=coverage.txt

VERSION = $(shell git describe --long --always | sed 's/v//')

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

install: build
@echo "✓ Installing provider into ~/.terraform.d/plugins ..."
@test -d $(HOME)/.terraform.d/plugins && rm $(HOME)/.terraform.d/plugins/terraform-provider-databricks* || mkdir -p $(HOME)/.terraform.d/plugins
@cp terraform-provider-databricks $(HOME)/.terraform.d/plugins
@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#/#_#')'
@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#/#_#')'
@mkdir -p '$(HOME)/.terraform.d/plugins/registry.terraform.io/databrickslabs/databricks/${VERSION}/$(shell go version | awk '{print $$4}' | sed 's#/#_#')'
@cp terraform-provider-databricks '$(HOME)/.terraform.d/plugins/registry.terraform.io/databrickslabs/databricks/${VERSION}/$(shell go version | awk '{print $$4}' | sed 's#/#_#')'
@echo "✓ Use the following configuration to enable the version you've built"
@echo
@echo "terraform {"
@echo " required_providers {"
@echo " databricks = {"
@echo ' source = "databrickslabs/databricks"'
@echo ' version = "$(shell git describe --long --always | sed 's/v//')"'
@echo ' version = "${VERSION}"'
@echo " }"
@echo " }"
@echo "}"
Expand Down
6 changes: 3 additions & 3 deletions common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (c *DatabricksClient) configureHTTPCLient() {
}
}

// IsUsingAzureAuth returns true if Azure authentication is configured, this is not a valid check to determine if we are running on Azure
func (c *DatabricksClient) IsUsingAzureAuth() bool {
return c.AzureAuth.resourceID() != ""
// IsAzure returns true if client is configured for Azure Databricks - either by using AAD auth or with host+token combination
func (c *DatabricksClient) IsAzure() bool {
return c.AzureAuth.resourceID() != "" || strings.Contains(c.Host, "azuredatabricks.net")
}
8 changes: 3 additions & 5 deletions compute/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ func (a ClustersAPI) Unpin(clusterID string) error {
// up to 70 of the most recently terminated interactive clusters in the past 30 days,
// and up to 30 of the most recently terminated job clusters in the past 30 days
func (a ClustersAPI) List() ([]ClusterInfo, error) {
var clusterList = struct {
Clusters []ClusterInfo `json:"clusters,omitempty" url:"clusters,omitempty"`
}{}
var clusterList ClusterList
err := a.client.Get("/clusters/list", nil, &clusterList)
return clusterList.Clusters, err
}
Expand Down Expand Up @@ -281,7 +279,7 @@ func (a ClustersAPI) GetOrCreateRunningCluster(name string, custom ...Cluster) (
NodeTypeID: smallestNodeType,
AutoterminationMinutes: 10,
}
if !a.client.IsUsingAzureAuth() {
if !a.client.IsAzure() {
r.AwsAttributes = &AwsAttributes{
Availability: "SPOT",
}
Expand All @@ -296,7 +294,7 @@ func (a ClustersAPI) GetOrCreateRunningCluster(name string, custom ...Cluster) (
func (a ClustersAPI) GetSmallestNodeTypeWithStorage() string {
nodeTypes, err := a.ListNodeTypes()
if err != nil || len(nodeTypes) == 0 {
if a.client.IsUsingAzureAuth() {
if a.client.IsAzure() {
return "Standard_D3_v2"
}
return "i3.xlarge"
Expand Down
Loading