From 08e3eb7cbacc964718609d7f4cdfacd5a66e89b2 Mon Sep 17 00:00:00 2001 From: Sriharsha Tikkireddy Date: Mon, 20 Apr 2020 12:27:08 -0400 Subject: [PATCH] Fixed & refactored linting issues in databricks package --- databricks/azure_ws_init.go | 15 ++- databricks/azure_ws_init_test.go | 2 +- databricks/mounts.go | 120 +++++++++++------- databricks/provider.go | 37 +++--- .../resource_databricks_aws_s3_mount.go | 20 +-- ...source_databricks_azure_adls_gen1_mount.go | 45 ++++--- ...source_databricks_azure_adls_gen2_mount.go | 45 ++++--- .../resource_databricks_azure_blob_mount.go | 23 ++-- databricks/resource_databricks_cluster.go | 18 +-- databricks/resource_databricks_dbfs_file.go | 4 +- .../resource_databricks_instance_pool.go | 12 +- .../resource_databricks_instance_profile.go | 4 +- databricks/resource_databricks_job.go | 8 +- databricks/resource_databricks_notebook.go | 4 +- databricks/resource_databricks_scim_group.go | 4 +- databricks/resource_databricks_scim_user.go | 4 +- .../resource_databricks_scim_user_test.go | 2 +- databricks/resource_databricks_secret.go | 12 +- databricks/resource_databricks_secret_acl.go | 38 +++--- .../resource_databricks_secret_acl_test.go | 22 ++-- .../resource_databricks_secret_scope.go | 4 +- .../resource_databricks_secret_scope_test.go | 2 +- databricks/resource_databricks_secret_test.go | 2 +- databricks/resource_databricks_token.go | 8 +- databricks/resource_databricks_token_test.go | 4 +- databricks/utils.go | 65 +++++----- 26 files changed, 273 insertions(+), 251 deletions(-) diff --git a/databricks/azure_ws_init.go b/databricks/azure_ws_init.go index b11b5eb9b..3154e0511 100644 --- a/databricks/azure_ws_init.go +++ b/databricks/azure_ws_init.go @@ -7,11 +7,13 @@ import ( "net/http" ) +// List of management information const ( ManagementResourceEndpoint string = "https://management.core.windows.net/" ADBResourceID string = "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d" ) +// AzureAuth is a struct that contains information about the azure sp authentication type AzureAuth struct { TokenPayload *TokenPayload ManagementToken string @@ -20,21 +22,24 @@ type AzureAuth struct { AdbPlatformToken string } +// TokenPayload contains all the auth information for azure sp authentication type TokenPayload struct { ManagedResourceGroup string AzureRegion string WorkspaceName string ResourceGroup string - SubscriptionId string + SubscriptionID string ClientSecret string ClientID string TenantID string } +// WsProps contains information about the workspace properties type WsProps struct { ManagedResourceGroupID string `json:"managedResourceGroupId"` } +// WorkspaceRequest contains the request information for getting workspace information type WorkspaceRequest struct { Properties *WsProps `json:"properties"` Name string `json:"name"` @@ -63,13 +68,13 @@ func (a *AzureAuth) getManagementToken(config *service.DBApiClientConfig) error return nil } -func (a *AzureAuth) getWorkspaceId(config *service.DBApiClientConfig) error { +func (a *AzureAuth) getWorkspaceID(config *service.DBApiClientConfig) error { log.Println("[DEBUG] Getting Workspace ID via management token.") - url := "https://management.azure.com/subscriptions/" + a.TokenPayload.SubscriptionId + "/resourceGroups/" + a.TokenPayload.ResourceGroup + "/providers/Microsoft.Databricks/workspaces/" + a.TokenPayload.WorkspaceName + "" + + url := "https://management.azure.com/subscriptions/" + a.TokenPayload.SubscriptionID + "/resourceGroups/" + a.TokenPayload.ResourceGroup + "/providers/Microsoft.Databricks/workspaces/" + a.TokenPayload.WorkspaceName + "" + "?api-version=2018-04-01" payload := &WorkspaceRequest{ - Properties: &WsProps{ManagedResourceGroupID: "/subscriptions/" + a.TokenPayload.SubscriptionId + "/resourceGroups/" + a.TokenPayload.ManagedResourceGroup}, + Properties: &WsProps{ManagedResourceGroupID: "/subscriptions/" + a.TokenPayload.SubscriptionID + "/resourceGroups/" + a.TokenPayload.ManagedResourceGroup}, Name: a.TokenPayload.WorkspaceName, Location: a.TokenPayload.AzureRegion, } @@ -157,7 +162,7 @@ func (a *AzureAuth) initWorkspaceAndGetClient(config *service.DBApiClientConfig) return dbClient, err } - err = a.getWorkspaceId(config) + err = a.getWorkspaceID(config) if err != nil { return dbClient, err } diff --git a/databricks/azure_ws_init_test.go b/databricks/azure_ws_init_test.go index 9ebcd2713..e7c406be5 100644 --- a/databricks/azure_ws_init_test.go +++ b/databricks/azure_ws_init_test.go @@ -33,7 +33,7 @@ func TestAzureAuthCreateApiToken(t *testing.T) { AdbAccessToken: "", AdbPlatformToken: "", } - azureAuth.TokenPayload.SubscriptionId = os.Getenv("ARM_SUBSCRIPTION_ID") + azureAuth.TokenPayload.SubscriptionID = os.Getenv("ARM_SUBSCRIPTION_ID") azureAuth.TokenPayload.TenantID = os.Getenv("ARM_TENANT_ID") azureAuth.TokenPayload.ClientID = os.Getenv("ARM_CLIENT_ID") azureAuth.TokenPayload.ClientSecret = os.Getenv("ARM_CLIENT_SECRET") diff --git a/databricks/mounts.go b/databricks/mounts.go index 483ef5265..2293d7d5b 100644 --- a/databricks/mounts.go +++ b/databricks/mounts.go @@ -9,29 +9,33 @@ import ( "strings" ) +// Mount interface describes the functionality of any mount which is create, read and delete type Mount interface { - Create(client service.DBApiClient, clusterId string) error - Delete(client service.DBApiClient, clusterId string) error - Read(client service.DBApiClient, clusterId string) (string, error) + Create(client service.DBApiClient, clusterID string) error + Delete(client service.DBApiClient, clusterID string) error + Read(client service.DBApiClient, clusterID string) (string, error) } +// AWSIamMount describes the object for a aws mount using iam role type AWSIamMount struct { Mount S3BucketName string MountName string } +// NewAWSIamMount constructor for AWSIamMount func NewAWSIamMount(s3BucketName string, mountName string) *AWSIamMount { return &AWSIamMount{S3BucketName: s3BucketName, MountName: mountName} } -func (m AWSIamMount) Create(client service.DBApiClient, clusterId string) error { +// Create creates an aws iam mount given a cluster ID +func (m AWSIamMount) Create(client service.DBApiClient, clusterID string) error { iamMountCommand := fmt.Sprintf(` dbutils.fs.mount("s3a://%s", "/mnt/%s") dbutils.fs.ls("/mnt/%s") dbutils.notebook.exit("success") `, m.S3BucketName, m.MountName, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -42,13 +46,14 @@ dbutils.notebook.exit("success") return nil } -func (m AWSIamMount) Delete(client service.DBApiClient, clusterId string) error { +// Delete deletes an aws iam mount given a cluster ID +func (m AWSIamMount) Delete(client service.DBApiClient, clusterID string) error { iamMountCommand := fmt.Sprintf(` dbutils.fs.unmount("/mnt/%s") dbutils.fs.refreshMounts() dbutils.notebook.exit("success") `, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -59,14 +64,15 @@ dbutils.notebook.exit("success") return nil } -func (m AWSIamMount) Read(client service.DBApiClient, clusterId string) (string, error) { +// Read verifies an aws iam mount given a cluster ID +func (m AWSIamMount) Read(client service.DBApiClient, clusterID string) (string, error) { iamMountCommand := fmt.Sprintf(` dbutils.fs.ls("/mnt/%s") for mount in dbutils.fs.mounts(): if mount.mountPoint == "/mnt/%s": dbutils.notebook.exit(mount.source) `, m.MountName, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return "", err } @@ -75,15 +81,16 @@ for mount in dbutils.fs.mounts(): return "", errors.New(resp.Results.Summary) } if resp.Results.ResultType == "text" && resp.Results.Data.(string) == "" { - return "", errors.New("Unable to find mount point!") + return "", errors.New("unable to find mount point") } respBucket := strings.Replace(resp.Results.Data.(string), "s3a://", "", 1) if resp.Results.ResultType == "text" && respBucket != m.S3BucketName { - return "", errors.New(fmt.Sprintf("Does not match bucket value! %s != %s!", resp.Results.Data.(string), m.S3BucketName)) + return "", fmt.Errorf("does not match bucket value! %s != %s", resp.Results.Data.(string), m.S3BucketName) } return respBucket, nil } +// AzureBlobMount describes the object for a azure blob storage mount type AzureBlobMount struct { Mount ContainerName string @@ -95,11 +102,13 @@ type AzureBlobMount struct { SecretKey string } +// NewAzureBlobMount constructor for AzureBlobMount func NewAzureBlobMount(containerName string, storageAccountName string, directory string, mountName string, authType string, secretScope string, secretKey string) *AzureBlobMount { return &AzureBlobMount{ContainerName: containerName, StorageAccountName: storageAccountName, Directory: directory, MountName: mountName, AuthType: authType, SecretScope: secretScope, SecretKey: secretKey} } -func (m AzureBlobMount) Create(client service.DBApiClient, clusterId string) error { +// Create creates a azure blob storage mount given a cluster id +func (m AzureBlobMount) Create(client service.DBApiClient, clusterID string) error { var confKey string if m.AuthType == "SAS" { @@ -118,7 +127,7 @@ except Exception as e: raise e dbutils.notebook.exit("success") `, m.ContainerName, m.StorageAccountName, m.Directory, m.MountName, confKey, m.SecretScope, m.SecretKey, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -129,13 +138,14 @@ dbutils.notebook.exit("success") return nil } -func (m AzureBlobMount) Delete(client service.DBApiClient, clusterId string) error { +// Delete deletes a azure blob storage mount given a cluster id +func (m AzureBlobMount) Delete(client service.DBApiClient, clusterID string) error { iamMountCommand := fmt.Sprintf(` dbutils.fs.unmount("/mnt/%s") dbutils.fs.refreshMounts() dbutils.notebook.exit("success") `, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -146,14 +156,15 @@ dbutils.notebook.exit("success") return nil } -func (m AzureBlobMount) Read(client service.DBApiClient, clusterId string) (string, error) { +// Read verifies a azure blob storage mount given a cluster id +func (m AzureBlobMount) Read(client service.DBApiClient, clusterID string) (string, error) { iamMountCommand := fmt.Sprintf(` dbutils.fs.ls("/mnt/%s") for mount in dbutils.fs.mounts(): if mount.mountPoint == "/mnt/%s": dbutils.notebook.exit(mount.source) `, m.MountName, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return "", err } @@ -162,7 +173,7 @@ for mount in dbutils.fs.mounts(): return "", errors.New(resp.Results.Summary) } if resp.Results.ResultType == "text" && resp.Results.Data.(string) == "" { - return "", errors.New("Unable to find mount point!") + return "", errors.New("unable to find mount point") } container, storageAccount, directory, err := ProcessAzureWasbAbfssUris(resp.Results.Data.(string)) @@ -172,29 +183,32 @@ for mount in dbutils.fs.mounts(): if resp.Results.ResultType == "text" && container != m.ContainerName && storageAccount != m.StorageAccountName && m.Directory != directory { - return "", errors.New(fmt.Sprintf("Does not match uri with storage account and container values!"+ - " %s@%s != %s!", m.ContainerName, m.StorageAccountName, resp.Results.Data.(string))) + return "", fmt.Errorf("does not match uri with storage account and container values"+ + " %s@%s != %s!", m.ContainerName, m.StorageAccountName, resp.Results.Data.(string)) } return resp.Results.Data.(string), nil } +// AzureADLSGen1Mount describes the object for a azure datalake gen 1 storage mount type AzureADLSGen1Mount struct { Mount StorageResource string Directory string MountName string PrefixType string - ClientId string - TenantId string + ClientID string + TenantID string SecretScope string SecretKey string } -func NewAzureADLSGen1Mount(storageResource string, directory string, mountName string, prefixType string, clientId string, tenantId string, secretScope string, secretKey string) *AzureADLSGen1Mount { - return &AzureADLSGen1Mount{StorageResource: storageResource, Directory: directory, MountName: mountName, PrefixType: prefixType, ClientId: clientId, TenantId: tenantId, SecretScope: secretScope, SecretKey: secretKey} +// NewAzureADLSGen1Mount constructor for AzureADLSGen1Mount +func NewAzureADLSGen1Mount(storageResource string, directory string, mountName string, prefixType string, clientID string, tenantID string, secretScope string, secretKey string) *AzureADLSGen1Mount { + return &AzureADLSGen1Mount{StorageResource: storageResource, Directory: directory, MountName: mountName, PrefixType: prefixType, ClientID: clientID, TenantID: tenantID, SecretScope: secretScope, SecretKey: secretKey} } -func (m AzureADLSGen1Mount) Create(client service.DBApiClient, clusterId string) error { +// Create creates a azure datalake gen 1 storage mount given a cluster id +func (m AzureADLSGen1Mount) Create(client service.DBApiClient, clusterID string) error { iamMountCommand := fmt.Sprintf(` try: configs = {"%s.oauth2.access.token.provider.type": "ClientCredential", @@ -209,9 +223,9 @@ except Exception as e: dbutils.fs.unmount("/mnt/%s") raise e dbutils.notebook.exit("success") -`, m.PrefixType, m.PrefixType, m.ClientId, m.PrefixType, m.SecretScope, m.SecretKey, m.PrefixType, m.TenantId, +`, m.PrefixType, m.PrefixType, m.ClientID, m.PrefixType, m.SecretScope, m.SecretKey, m.PrefixType, m.TenantID, m.StorageResource, m.Directory, m.MountName, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -222,13 +236,14 @@ dbutils.notebook.exit("success") return nil } -func (m AzureADLSGen1Mount) Delete(client service.DBApiClient, clusterId string) error { +// Delete deletes a azure datalake gen 1 storage mount given a cluster id +func (m AzureADLSGen1Mount) Delete(client service.DBApiClient, clusterID string) error { iamMountCommand := fmt.Sprintf(` dbutils.fs.unmount("/mnt/%s") dbutils.fs.refreshMounts() dbutils.notebook.exit("success") `, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -239,14 +254,15 @@ dbutils.notebook.exit("success") return nil } -func (m AzureADLSGen1Mount) Read(client service.DBApiClient, clusterId string) (string, error) { +// Read verifies the azure datalake gen 1 storage mount given a cluster id +func (m AzureADLSGen1Mount) Read(client service.DBApiClient, clusterID string) (string, error) { iamMountCommand := fmt.Sprintf(` dbutils.fs.ls("/mnt/%s") for mount in dbutils.fs.mounts(): if mount.mountPoint == "/mnt/%s": dbutils.notebook.exit(mount.source) `, m.MountName, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return "", err } @@ -255,7 +271,7 @@ for mount in dbutils.fs.mounts(): return "", errors.New(resp.Results.Summary) } if resp.Results.ResultType == "text" && resp.Results.Data.(string) == "" { - return "", errors.New("Unable to find mount point!") + return "", errors.New("unable to find mount point") } storageResource, directory, err := ProcessAzureAdlsGen1Uri(resp.Results.Data.(string)) @@ -264,29 +280,32 @@ for mount in dbutils.fs.mounts(): } if resp.Results.ResultType == "text" && storageResource != m.StorageResource && m.Directory != directory { - return "", errors.New(fmt.Sprintf("Does not match uri with storage account and container values!"+ - " %s@%s != %s!", m.StorageResource, m.Directory, resp.Results.Data.(string))) + return "", fmt.Errorf("does not match uri with storage account and container values"+ + " %s@%s != %s!", m.StorageResource, m.Directory, resp.Results.Data.(string)) } return resp.Results.Data.(string), nil } +// AzureADLSGen2Mount describes the object for a azure datalake gen 2 storage mount type AzureADLSGen2Mount struct { Mount ContainerName string StorageAccountName string Directory string MountName string - ClientId string - TenantId string + ClientID string + TenantID string SecretScope string SecretKey string } -func NewAzureADLSGen2Mount(containerName string, storageAccountName string, directory string, mountName string, clientId string, tenantId string, secretScope string, secretKey string) *AzureADLSGen2Mount { - return &AzureADLSGen2Mount{ContainerName: containerName, StorageAccountName: storageAccountName, Directory: directory, MountName: mountName, ClientId: clientId, TenantId: tenantId, SecretScope: secretScope, SecretKey: secretKey} +// NewAzureADLSGen2Mount is a constructor for AzureADLSGen2Mount +func NewAzureADLSGen2Mount(containerName string, storageAccountName string, directory string, mountName string, clientID string, tenantID string, secretScope string, secretKey string) *AzureADLSGen2Mount { + return &AzureADLSGen2Mount{ContainerName: containerName, StorageAccountName: storageAccountName, Directory: directory, MountName: mountName, ClientID: clientID, TenantID: tenantID, SecretScope: secretScope, SecretKey: secretKey} } -func (m AzureADLSGen2Mount) Create(client service.DBApiClient, clusterId string) error { +// Create creates a azure datalake gen 2 storage mount +func (m AzureADLSGen2Mount) Create(client service.DBApiClient, clusterID string) error { iamMountCommand := fmt.Sprintf(` try: configs = {"fs.azure.account.auth.type": "OAuth", @@ -302,8 +321,8 @@ except Exception as e: dbutils.fs.unmount("/mnt/%s") raise e dbutils.notebook.exit("success") -`, m.ClientId, m.SecretScope, m.SecretKey, m.TenantId, m.ContainerName, m.StorageAccountName, m.Directory, m.MountName, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) +`, m.ClientID, m.SecretScope, m.SecretKey, m.TenantID, m.ContainerName, m.StorageAccountName, m.Directory, m.MountName, m.MountName) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -314,13 +333,14 @@ dbutils.notebook.exit("success") return nil } -func (m AzureADLSGen2Mount) Delete(client service.DBApiClient, clusterId string) error { +// Delete deletes a azure datalake gen 2 storage mount +func (m AzureADLSGen2Mount) Delete(client service.DBApiClient, clusterID string) error { iamMountCommand := fmt.Sprintf(` dbutils.fs.unmount("/mnt/%s") dbutils.fs.refreshMounts() dbutils.notebook.exit("success") `, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return err } @@ -331,14 +351,15 @@ dbutils.notebook.exit("success") return nil } -func (m AzureADLSGen2Mount) Read(client service.DBApiClient, clusterId string) (string, error) { +// Read verifies the azure datalake gen 2 storage mount +func (m AzureADLSGen2Mount) Read(client service.DBApiClient, clusterID string) (string, error) { iamMountCommand := fmt.Sprintf(` dbutils.fs.ls("/mnt/%s") for mount in dbutils.fs.mounts(): if mount.mountPoint == "/mnt/%s": dbutils.notebook.exit(mount.source) `, m.MountName, m.MountName) - resp, err := client.Commands().Execute(clusterId, "python", iamMountCommand) + resp, err := client.Commands().Execute(clusterID, "python", iamMountCommand) if err != nil { return "", err } @@ -347,7 +368,7 @@ for mount in dbutils.fs.mounts(): return "", errors.New(resp.Results.Summary) } if resp.Results.ResultType == "text" && resp.Results.Data.(string) == "" { - return "", errors.New("Unable to find mount point!") + return "", errors.New("unable to find mount point") } containerName, storageAccountName, directory, err := ProcessAzureWasbAbfssUris(resp.Results.Data.(string)) @@ -356,12 +377,13 @@ for mount in dbutils.fs.mounts(): } if resp.Results.ResultType == "text" && containerName != m.ContainerName && m.StorageAccountName != storageAccountName && m.Directory != directory { - return "", errors.New(fmt.Sprintf("Does not match uri with storage account and container values!"+ - " %s@%s != %s!", m.ContainerName, m.StorageAccountName, resp.Results.Data.(string))) + return "", fmt.Errorf("does not match uri with storage account and container values"+ + " %s@%s != %s!", m.ContainerName, m.StorageAccountName, resp.Results.Data.(string)) } return resp.Results.Data.(string), nil } +// ProcessAzureAdlsGen1Uri will return given a adls gen 1 URI the storage account name and the directory if it exists func ProcessAzureAdlsGen1Uri(uri string) (string, string, error) { u, err := url.Parse(uri) if err != nil { @@ -377,6 +399,8 @@ func ProcessAzureAdlsGen1Uri(uri string) (string, string, error) { return storageAccount, directory, nil } +// ProcessAzureWasbAbfssUris will return given a WASBS or ABFSS URI the +// containerName, storageAccount and the directory if it exists func ProcessAzureWasbAbfssUris(uri string) (string, string, string, error) { u, err := url.Parse(uri) if err != nil { diff --git a/databricks/provider.go b/databricks/provider.go index b0bfb3791..0406a35e2 100644 --- a/databricks/provider.go +++ b/databricks/provider.go @@ -8,6 +8,7 @@ import ( "os" ) +// Provider returns the entire terraform provider object func Provider() terraform.ResourceProvider { provider := &schema.Provider{ DataSourcesMap: map[string]*schema.Resource{ @@ -18,19 +19,19 @@ func Provider() terraform.ResourceProvider { "databricks_zones": dataSourceClusterZones(), }, ResourcesMap: map[string]*schema.Resource{ - "databricks_token": resourceToken(), - "databricks_secret_scope": resourceSecretScope(), - "databricks_secret": resourceSecret(), - "databricks_secret_acl": resourceSecretAcl(), - "databricks_instance_pool": resourceInstancePool(), - "databricks_scim_user": resourceScimUser(), - "databricks_scim_group": resourceScimGroup(), - "databricks_notebook": resourceNotebook(), - "databricks_cluster": resourceCluster(), - "databricks_job": resourceJob(), - "databricks_dbfs_file": resourceDBFSFile(), - "databricks_dbfs_file_sync": resourceDBFSFileSync(), - "databricks_instance_profile": resourceInstanceProfile(), + "databricks_token": resourceToken(), + "databricks_secret_scope": resourceSecretScope(), + "databricks_secret": resourceSecret(), + "databricks_secret_acl": resourceSecretACL(), + "databricks_instance_pool": resourceInstancePool(), + "databricks_scim_user": resourceScimUser(), + "databricks_scim_group": resourceScimGroup(), + "databricks_notebook": resourceNotebook(), + "databricks_cluster": resourceCluster(), + "databricks_job": resourceJob(), + "databricks_dbfs_file": resourceDBFSFile(), + "databricks_dbfs_file_sync": resourceDBFSFileSync(), + "databricks_instance_profile": resourceInstanceProfile(), "databricks_aws_s3_mount": resourceAWSS3Mount(), "databricks_azure_blob_mount": resourceAzureBlobMount(), "databricks_azure_adls_gen1_mount": resourceAzureAdlsGen1Mount(), @@ -132,24 +133,24 @@ func providerConfigure(d *schema.ResourceData, s string) (interface{}, error) { tokenPayload.WorkspaceName = workspaceName } if subscriptionID, ok := azureAuthMap["subscription_id"].(string); ok { - tokenPayload.SubscriptionId = subscriptionID + tokenPayload.SubscriptionID = subscriptionID } else { - tokenPayload.SubscriptionId = os.Getenv("ARM_SUBSCRIPTION_ID") + tokenPayload.SubscriptionID = os.Getenv("ARM_SUBSCRIPTION_ID") } if clientSecret, ok := azureAuthMap["client_secret"].(string); ok { tokenPayload.ClientSecret = clientSecret } else { - tokenPayload.SubscriptionId = os.Getenv("ARM_CLIENT_SECRET") + tokenPayload.SubscriptionID = os.Getenv("ARM_CLIENT_SECRET") } if clientID, ok := azureAuthMap["client_id"].(string); ok { tokenPayload.ClientID = clientID } else { - tokenPayload.SubscriptionId = os.Getenv("ARM_CLIENT_ID") + tokenPayload.SubscriptionID = os.Getenv("ARM_CLIENT_ID") } if tenantID, ok := azureAuthMap["tenant_id"].(string); ok { tokenPayload.TenantID = tenantID } else { - tokenPayload.SubscriptionId = os.Getenv("ARM_TENANT_ID") + tokenPayload.SubscriptionID = os.Getenv("ARM_TENANT_ID") } azureAuthSetup := AzureAuth{ diff --git a/databricks/resource_databricks_aws_s3_mount.go b/databricks/resource_databricks_aws_s3_mount.go index f5e1f0cd1..fd330ac62 100644 --- a/databricks/resource_databricks_aws_s3_mount.go +++ b/databricks/resource_databricks_aws_s3_mount.go @@ -33,8 +33,8 @@ func resourceAWSS3Mount() *schema.Resource { func resourceAWSS3Create(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -43,14 +43,14 @@ func resourceAWSS3Create(d *schema.ResourceData, m interface{}) error { s3BucketMount := NewAWSIamMount(s3BucketName, mountName) - err = s3BucketMount.Create(client, clusterId) + err = s3BucketMount.Create(client, clusterID) if err != nil { return err } d.SetId(mountName) - err = d.Set("cluster_id", clusterId) + err = d.Set("cluster_id", clusterID) if err != nil { return err } @@ -64,8 +64,8 @@ func resourceAWSS3Create(d *schema.ResourceData, m interface{}) error { func resourceAWSS3Read(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -74,7 +74,7 @@ func resourceAWSS3Read(d *schema.ResourceData, m interface{}) error { s3BucketMount := NewAWSIamMount(s3BucketName, mountName) - s3BucketNameMounted, err := s3BucketMount.Read(client, clusterId) + s3BucketNameMounted, err := s3BucketMount.Read(client, clusterID) if err != nil { return err } @@ -85,13 +85,13 @@ func resourceAWSS3Read(d *schema.ResourceData, m interface{}) error { func resourceAWSS3Delete(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } s3BucketName := d.Get("s3_bucket_name").(string) mountName := d.Get("mount_name").(string) s3BucketMount := NewAWSIamMount(s3BucketName, mountName) - return s3BucketMount.Delete(client, clusterId) + return s3BucketMount.Delete(client, clusterID) } diff --git a/databricks/resource_databricks_azure_adls_gen1_mount.go b/databricks/resource_databricks_azure_adls_gen1_mount.go index 4b55736df..71021f2e1 100644 --- a/databricks/resource_databricks_azure_adls_gen1_mount.go +++ b/databricks/resource_databricks_azure_adls_gen1_mount.go @@ -42,9 +42,8 @@ func resourceAzureAdlsGen1Mount() *schema.Resource { directory := val.(string) if strings.HasPrefix(directory, "/") { return - } else { - errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val)) } + errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val)) return }, }, @@ -79,8 +78,8 @@ func resourceAzureAdlsGen1Mount() *schema.Resource { func resourceAzureAdlsGen1Create(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -88,21 +87,21 @@ func resourceAzureAdlsGen1Create(d *schema.ResourceData, m interface{}) error { sparkConfPrefix := d.Get("spark_conf_prefix").(string) directory := d.Get("directory").(string) mountName := d.Get("mount_name").(string) - tenantId := d.Get("tenant_id").(string) - clientId := d.Get("client_id").(string) + tenantID := d.Get("tenant_id").(string) + clientID := d.Get("client_id").(string) clientSecretScope := d.Get("client_secret_scope").(string) clientSecretKey := d.Get("client_secret_key").(string) adlsGen1Mount := NewAzureADLSGen1Mount(storageResourceName, directory, mountName, - sparkConfPrefix, clientId, tenantId, clientSecretScope, clientSecretKey) + sparkConfPrefix, clientID, tenantID, clientSecretScope, clientSecretKey) - err = adlsGen1Mount.Create(client, clusterId) + err = adlsGen1Mount.Create(client, clusterID) if err != nil { return err } d.SetId(mountName) - err = d.Set("cluster_id", clusterId) + err = d.Set("cluster_id", clusterID) if err != nil { return err } @@ -110,11 +109,11 @@ func resourceAzureAdlsGen1Create(d *schema.ResourceData, m interface{}) error { if err != nil { return err } - err = d.Set("tenant_id", tenantId) + err = d.Set("tenant_id", tenantID) if err != nil { return err } - err = d.Set("client_id", clientId) + err = d.Set("client_id", clientID) if err != nil { return err } @@ -135,8 +134,8 @@ func resourceAzureAdlsGen1Create(d *schema.ResourceData, m interface{}) error { } func resourceAzureAdlsGen1Read(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -144,15 +143,15 @@ func resourceAzureAdlsGen1Read(d *schema.ResourceData, m interface{}) error { sparkConfPrefix := d.Get("spark_conf_prefix").(string) directory := d.Get("directory").(string) mountName := d.Get("mount_name").(string) - tenantId := d.Get("tenant_id").(string) - clientId := d.Get("client_id").(string) + tenantID := d.Get("tenant_id").(string) + clientID := d.Get("client_id").(string) clientSecretScope := d.Get("client_secret_scope").(string) clientSecretKey := d.Get("client_secret_key").(string) adlsGen1Mount := NewAzureADLSGen1Mount(storageResourceName, directory, mountName, - sparkConfPrefix, clientId, tenantId, clientSecretScope, clientSecretKey) + sparkConfPrefix, clientID, tenantID, clientSecretScope, clientSecretKey) - url, err := adlsGen1Mount.Read(client, clusterId) + url, err := adlsGen1Mount.Read(client, clusterID) if err != nil { //Reset id in case of inability to find mount if strings.Contains(err.Error(), "Unable to find mount point!") || @@ -173,8 +172,8 @@ func resourceAzureAdlsGen1Read(d *schema.ResourceData, m interface{}) error { func resourceAzureAdlsGen1Delete(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -182,12 +181,12 @@ func resourceAzureAdlsGen1Delete(d *schema.ResourceData, m interface{}) error { sparkConfPrefix := d.Get("spark_conf_prefix").(string) directory := d.Get("directory").(string) mountName := d.Get("mount_name").(string) - tenantId := d.Get("tenant_id").(string) - clientId := d.Get("client_id").(string) + tenantID := d.Get("tenant_id").(string) + clientID := d.Get("client_id").(string) clientSecretScope := d.Get("client_secret_scope").(string) clientSecretKey := d.Get("client_secret_key").(string) adlsGen1Mount := NewAzureADLSGen1Mount(storageResourceName, directory, mountName, - sparkConfPrefix, clientId, tenantId, clientSecretScope, clientSecretKey) - return adlsGen1Mount.Delete(client, clusterId) + sparkConfPrefix, clientID, tenantID, clientSecretScope, clientSecretKey) + return adlsGen1Mount.Delete(client, clusterID) } diff --git a/databricks/resource_databricks_azure_adls_gen2_mount.go b/databricks/resource_databricks_azure_adls_gen2_mount.go index f4a80ff29..1cd017e7f 100644 --- a/databricks/resource_databricks_azure_adls_gen2_mount.go +++ b/databricks/resource_databricks_azure_adls_gen2_mount.go @@ -39,9 +39,8 @@ func resourceAzureAdlsGen2Mount() *schema.Resource { directory := val.(string) if strings.HasPrefix(directory, "/") { return - } else { - errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val)) } + errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val)) return }, }, @@ -76,8 +75,8 @@ func resourceAzureAdlsGen2Mount() *schema.Resource { func resourceAzureAdlsGen2Create(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -85,21 +84,21 @@ func resourceAzureAdlsGen2Create(d *schema.ResourceData, m interface{}) error { storageAccountName := d.Get("storage_account_name").(string) directory := d.Get("directory").(string) mountName := d.Get("mount_name").(string) - tenantId := d.Get("tenant_id").(string) - clientId := d.Get("client_id").(string) + tenantID := d.Get("tenant_id").(string) + clientID := d.Get("client_id").(string) clientSecretScope := d.Get("client_secret_scope").(string) clientSecretKey := d.Get("client_secret_key").(string) - adlsGen2Mount := NewAzureADLSGen2Mount(containerName, storageAccountName, directory, mountName, clientId, tenantId, + adlsGen2Mount := NewAzureADLSGen2Mount(containerName, storageAccountName, directory, mountName, clientID, tenantID, clientSecretScope, clientSecretKey) - err = adlsGen2Mount.Create(client, clusterId) + err = adlsGen2Mount.Create(client, clusterID) if err != nil { return err } d.SetId(mountName) - err = d.Set("cluster_id", clusterId) + err = d.Set("cluster_id", clusterID) if err != nil { return err } @@ -107,11 +106,11 @@ func resourceAzureAdlsGen2Create(d *schema.ResourceData, m interface{}) error { if err != nil { return err } - err = d.Set("tenant_id", tenantId) + err = d.Set("tenant_id", tenantID) if err != nil { return err } - err = d.Set("client_id", clientId) + err = d.Set("client_id", clientID) if err != nil { return err } @@ -128,8 +127,8 @@ func resourceAzureAdlsGen2Create(d *schema.ResourceData, m interface{}) error { } func resourceAzureAdlsGen2Read(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -137,15 +136,15 @@ func resourceAzureAdlsGen2Read(d *schema.ResourceData, m interface{}) error { storageAccountName := d.Get("storage_account_name").(string) directory := d.Get("directory").(string) mountName := d.Get("mount_name").(string) - tenantId := d.Get("tenant_id").(string) - clientId := d.Get("client_id").(string) + tenantID := d.Get("tenant_id").(string) + clientID := d.Get("client_id").(string) clientSecretScope := d.Get("client_secret_scope").(string) clientSecretKey := d.Get("client_secret_key").(string) - adlsGen2Mount := NewAzureADLSGen2Mount(containerName, storageAccountName, directory, mountName, clientId, tenantId, + adlsGen2Mount := NewAzureADLSGen2Mount(containerName, storageAccountName, directory, mountName, clientID, tenantID, clientSecretScope, clientSecretKey) - url, err := adlsGen2Mount.Read(client, clusterId) + url, err := adlsGen2Mount.Read(client, clusterID) if err != nil { //Reset id in case of inability to find mount if strings.Contains(err.Error(), "Unable to find mount point!") || @@ -170,8 +169,8 @@ func resourceAzureAdlsGen2Read(d *schema.ResourceData, m interface{}) error { func resourceAzureAdlsGen2Delete(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -179,12 +178,12 @@ func resourceAzureAdlsGen2Delete(d *schema.ResourceData, m interface{}) error { storageAccountName := d.Get("storage_account_name").(string) directory := d.Get("directory").(string) mountName := d.Get("mount_name").(string) - tenantId := d.Get("tenant_id").(string) - clientId := d.Get("client_id").(string) + tenantID := d.Get("tenant_id").(string) + clientID := d.Get("client_id").(string) clientSecretScope := d.Get("client_secret_scope").(string) clientSecretKey := d.Get("client_secret_key").(string) - adlsGen2Mount := NewAzureADLSGen2Mount(containerName, storageAccountName, directory, mountName, clientId, tenantId, + adlsGen2Mount := NewAzureADLSGen2Mount(containerName, storageAccountName, directory, mountName, clientID, tenantID, clientSecretScope, clientSecretKey) - return adlsGen2Mount.Delete(client, clusterId) + return adlsGen2Mount.Delete(client, clusterID) } diff --git a/databricks/resource_databricks_azure_blob_mount.go b/databricks/resource_databricks_azure_blob_mount.go index a68ff1547..5915e441e 100644 --- a/databricks/resource_databricks_azure_blob_mount.go +++ b/databricks/resource_databricks_azure_blob_mount.go @@ -40,9 +40,8 @@ func resourceAzureBlobMount() *schema.Resource { directory := val.(string) if strings.HasPrefix(directory, "/") { return - } else { - errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val)) } + errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val)) return }, }, @@ -73,8 +72,8 @@ func resourceAzureBlobMount() *schema.Resource { func resourceAzureBlobMountCreate(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -89,11 +88,11 @@ func resourceAzureBlobMountCreate(d *schema.ResourceData, m interface{}) error { blobMount := NewAzureBlobMount(containerName, storageAccountName, directory, mountName, authType, tokenSecretScope, tokenSecretKey) - err = blobMount.Create(client, clusterId) + err = blobMount.Create(client, clusterID) d.SetId(mountName) - err = d.Set("cluster_id", clusterId) + err = d.Set("cluster_id", clusterID) if err != nil { return err } @@ -118,8 +117,8 @@ func resourceAzureBlobMountCreate(d *schema.ResourceData, m interface{}) error { } func resourceAzureBlobMountRead(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -134,7 +133,7 @@ func resourceAzureBlobMountRead(d *schema.ResourceData, m interface{}) error { blobMount := NewAzureBlobMount(containerName, storageAccountName, directory, mountName, authType, tokenSecretScope, tokenSecretKey) - url, err := blobMount.Read(client, clusterId) + url, err := blobMount.Read(client, clusterID) if err != nil { //Reset id in case of inability to find mount if strings.Contains(err.Error(), "Unable to find mount point!") { @@ -158,8 +157,8 @@ func resourceAzureBlobMountRead(d *schema.ResourceData, m interface{}) error { func resourceAzureBlobMountDelete(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) - clusterId := d.Get("cluster_id").(string) - err := changeClusterIntoRunningState(clusterId, client) + clusterID := d.Get("cluster_id").(string) + err := changeClusterIntoRunningState(clusterID, client) if err != nil { return err } @@ -173,5 +172,5 @@ func resourceAzureBlobMountDelete(d *schema.ResourceData, m interface{}) error { blobMount := NewAzureBlobMount(containerName, storageAccountName, directory, mountName, authType, tokenSecretScope, tokenSecretKey) - return blobMount.Delete(client, clusterId) + return blobMount.Delete(client, clusterID) } diff --git a/databricks/resource_databricks_cluster.go b/databricks/resource_databricks_cluster.go index 7811694af..e9bfee317 100644 --- a/databricks/resource_databricks_cluster.go +++ b/databricks/resource_databricks_cluster.go @@ -1047,7 +1047,7 @@ func resourceClusterUpdate(d *schema.ResourceData, m interface{}) error { return resourceClusterRead(d, m) } - return errors.New("Unable to edit cluster due to cluster state not being in a runnable/terminated state.") + return errors.New("unable to edit cluster due to cluster state not being in a runnable/terminated state") } func resourceClusterDelete(d *schema.ResourceData, m interface{}) error { @@ -1107,8 +1107,8 @@ func parseSchemaToCluster(d *schema.ResourceData, schemaAttPrefix string) model. if availability, ok := awsAttributesMap["availability"]; ok { awsAttributes.Availability = model.AwsAvailability(availability.(string)) } - if zoneId, ok := awsAttributesMap["zone_id"]; ok { - awsAttributes.ZoneID = zoneId.(string) + if zoneID, ok := awsAttributesMap["zone_id"]; ok { + awsAttributes.ZoneID = zoneID.(string) } if spotBidPricePercent, ok := awsAttributesMap["spot_bid_price_percent"]; ok { //val, _ := strconv.ParseInt(spotBidPricePercent.(string), 10, 32) @@ -1136,13 +1136,13 @@ func parseSchemaToCluster(d *schema.ResourceData, schemaAttPrefix string) model. } //Deal with driver node type id - if driverNodeTypeId, ok := d.GetOk(schemaAttPrefix + "driver_node_type_id"); ok { - cluster.DriverNodeTypeID = driverNodeTypeId.(string) + if driverNodeTypeID, ok := d.GetOk(schemaAttPrefix + "driver_node_type_id"); ok { + cluster.DriverNodeTypeID = driverNodeTypeID.(string) } //Deal with worker node type id - if nodeTypeId, ok := d.GetOk(schemaAttPrefix + "node_type_id"); ok { - cluster.NodeTypeID = nodeTypeId.(string) + if nodeTypeID, ok := d.GetOk(schemaAttPrefix + "node_type_id"); ok { + cluster.NodeTypeID = nodeTypeID.(string) } //Deal with worker ssh public keys @@ -1337,7 +1337,7 @@ func getMapFromOneItemSet(input interface{}) map[string]interface{} { return nil } -func isClusterMissing(errorMsg, resourceId string) bool { +func isClusterMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, "INVALID_PARAMETER_VALUE") && - strings.Contains(errorMsg, fmt.Sprintf("Cluster %s does not exist", resourceId)) + strings.Contains(errorMsg, fmt.Sprintf("Cluster %s does not exist", resourceID)) } diff --git a/databricks/resource_databricks_dbfs_file.go b/databricks/resource_databricks_dbfs_file.go index 93d0347a2..a2dc4501c 100644 --- a/databricks/resource_databricks_dbfs_file.go +++ b/databricks/resource_databricks_dbfs_file.go @@ -144,7 +144,7 @@ func resourceDBFSFileDelete(d *schema.ResourceData, m interface{}) error { return err } -func isDBFSFileMissing(errorMsg, resourceId string) bool { +func isDBFSFileMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, "RESOURCE_DOES_NOT_EXIST") && - strings.Contains(errorMsg, fmt.Sprintf("No file or directory exists on path %s.", resourceId)) + strings.Contains(errorMsg, fmt.Sprintf("No file or directory exists on path %s.", resourceID)) } diff --git a/databricks/resource_databricks_instance_pool.go b/databricks/resource_databricks_instance_pool.go index cac26a0fb..6d916fb88 100644 --- a/databricks/resource_databricks_instance_pool.go +++ b/databricks/resource_databricks_instance_pool.go @@ -163,8 +163,8 @@ func resourceInstancePoolCreate(d *schema.ResourceData, m interface{}) error { if availability, ok := awsAttributesMap["availability"]; ok { instancePoolAwsAttributes.Availability = model.AwsAvailability(availability.(string)) } - if zoneId, ok := awsAttributesMap["zone_id"]; ok { - instancePoolAwsAttributes.ZoneID = zoneId.(string) + if zoneID, ok := awsAttributesMap["zone_id"]; ok { + instancePoolAwsAttributes.ZoneID = zoneID.(string) } if spotBidPricePercent, ok := awsAttributesMap["spot_bid_price_percent"]; ok { //val, _ := strconv.ParseInt(spotBidPricePercent.(string), 10, 32) @@ -173,8 +173,8 @@ func resourceInstancePoolCreate(d *schema.ResourceData, m interface{}) error { instancePool.AwsAttributes = &instancePoolAwsAttributes } - if nodeTypeId, ok := d.GetOk("node_type_id"); ok { - instancePool.NodeTypeID = nodeTypeId.(string) + if nodeTypeID, ok := d.GetOk("node_type_id"); ok { + instancePool.NodeTypeID = nodeTypeID.(string) } if customTags, ok := d.GetOk("custom_tags"); ok { @@ -345,7 +345,7 @@ func resourceInstancePoolDelete(d *schema.ResourceData, m interface{}) error { return err } -func isInstancePoolMissing(errorMsg, resourceId string) bool { +func isInstancePoolMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, "RESOURCE_DOES_NOT_EXIST") && - strings.Contains(errorMsg, fmt.Sprintf("Can't find an instance pool with id: %s", resourceId)) + strings.Contains(errorMsg, fmt.Sprintf("Can't find an instance pool with id: %s", resourceID)) } diff --git a/databricks/resource_databricks_instance_profile.go b/databricks/resource_databricks_instance_profile.go index 9dbab02b7..f9b178c2e 100644 --- a/databricks/resource_databricks_instance_profile.go +++ b/databricks/resource_databricks_instance_profile.go @@ -69,7 +69,7 @@ func resourceInstanceProfileDelete(d *schema.ResourceData, m interface{}) error return err } -func isInstanceProfileMissing(errorMsg, resourceId string) bool { +func isInstanceProfileMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, fmt.Sprintf("Instance profile with name: %s not found in "+ - "list of instance profiles in the workspace!", resourceId)) + "list of instance profiles in the workspace!", resourceID)) } diff --git a/databricks/resource_databricks_job.go b/databricks/resource_databricks_job.go index bd0f81416..e065ab6b2 100644 --- a/databricks/resource_databricks_job.go +++ b/databricks/resource_databricks_job.go @@ -869,8 +869,8 @@ func parseSchemaToJobSettings(d *schema.ResourceData) model.JobSettings { var jobSettings model.JobSettings - if existingClusterId, ok := d.GetOk("existing_cluster_id"); ok { - jobSettings.ExistingClusterID = existingClusterId.(string) + if existingClusterID, ok := d.GetOk("existing_cluster_id"); ok { + jobSettings.ExistingClusterID = existingClusterID.(string) } cluster := parseSchemaToCluster(d, "new_cluster.0.") @@ -1096,7 +1096,7 @@ func parseSchemaToLibraries(d *schema.ResourceData) []model.Library { return libraryList } -func isJobMissing(errorMsg, resourceId string) bool { +func isJobMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, "INVALID_PARAMETER_VALUE") && - strings.Contains(errorMsg, fmt.Sprintf("Job %s does not exist.", resourceId)) + strings.Contains(errorMsg, fmt.Sprintf("Job %s does not exist.", resourceID)) } diff --git a/databricks/resource_databricks_notebook.go b/databricks/resource_databricks_notebook.go index 94d69f8ed..becc8d0aa 100644 --- a/databricks/resource_databricks_notebook.go +++ b/databricks/resource_databricks_notebook.go @@ -248,7 +248,7 @@ func getDBCCheckSumForCommands(fileIO io.ReadCloser) (int, error) { return int(crc32.ChecksumIEEE(commandsBuffer.Bytes())), nil } -func isNotebookMissing(errorMsg, resourceId string) bool { +func isNotebookMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, "RESOURCE_DOES_NOT_EXIST") && - strings.Contains(errorMsg, fmt.Sprintf("Path (%s) doesn't exist.", resourceId)) + strings.Contains(errorMsg, fmt.Sprintf("Path (%s) doesn't exist.", resourceID)) } diff --git a/databricks/resource_databricks_scim_group.go b/databricks/resource_databricks_scim_group.go index b7de842ce..0060b035e 100644 --- a/databricks/resource_databricks_scim_group.go +++ b/databricks/resource_databricks_scim_group.go @@ -232,8 +232,8 @@ func resourceScimGroupDelete(d *schema.ResourceData, m interface{}) error { return err } -func isScimGroupMissing(errorMsg, resourceId string) bool { +func isScimGroupMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, "urn:ietf:params:scim:api:messages:2.0:Error") && - strings.Contains(errorMsg, fmt.Sprintf("Group with id %s not found.", resourceId)) && + strings.Contains(errorMsg, fmt.Sprintf("Group with id %s not found.", resourceID)) && strings.Contains(errorMsg, "404") } diff --git a/databricks/resource_databricks_scim_user.go b/databricks/resource_databricks_scim_user.go index 71dd7e404..902527294 100644 --- a/databricks/resource_databricks_scim_user.go +++ b/databricks/resource_databricks_scim_user.go @@ -245,8 +245,8 @@ func resourceScimUserDelete(d *schema.ResourceData, m interface{}) error { return err } -func isScimUserMissing(errorMsg, resourceId string) bool { +func isScimUserMissing(errorMsg, resourceID string) bool { return strings.Contains(errorMsg, "urn:ietf:params:scim:api:messages:2.0:Error") && - strings.Contains(errorMsg, fmt.Sprintf("User with id %s not found.", resourceId)) && + strings.Contains(errorMsg, fmt.Sprintf("User with id %s not found.", resourceID)) && strings.Contains(errorMsg, "404") } diff --git a/databricks/resource_databricks_scim_user_test.go b/databricks/resource_databricks_scim_user_test.go index eb2976f23..c091cc8c6 100644 --- a/databricks/resource_databricks_scim_user_test.go +++ b/databricks/resource_databricks_scim_user_test.go @@ -56,7 +56,7 @@ func testScimUserResourceDestroy(s *terraform.State) error { if err != nil { return nil } - return errors.New("Resource Scim User is not cleaned up!") + return errors.New("resource Scim User is not cleaned up") } return nil } diff --git a/databricks/resource_databricks_secret.go b/databricks/resource_databricks_secret.go index bb00a3894..fb3e3c9f1 100644 --- a/databricks/resource_databricks_secret.go +++ b/databricks/resource_databricks_secret.go @@ -39,12 +39,12 @@ func resourceSecret() *schema.Resource { } } -func getSecretId(scope string, key string) (string, error) { +func getSecretID(scope string, key string) (string, error) { return scope + "|||" + key, nil } -func getScopeAndKeyFromSecretId(secretIdString string) (string, string, error) { - return strings.Split(secretIdString, "|||")[0], strings.Split(secretIdString, "|||")[1], nil +func getScopeAndKeyFromSecretID(secretIDString string) (string, string, error) { + return strings.Split(secretIDString, "|||")[0], strings.Split(secretIDString, "|||")[1], nil } func resourceSecretCreate(d *schema.ResourceData, m interface{}) error { @@ -56,7 +56,7 @@ func resourceSecretCreate(d *schema.ResourceData, m interface{}) error { if err != nil { return err } - id, err := getSecretId(scopeName, key) + id, err := getSecretID(scopeName, key) if err != nil { return err } @@ -67,7 +67,7 @@ func resourceSecretCreate(d *schema.ResourceData, m interface{}) error { func resourceSecretRead(d *schema.ResourceData, m interface{}) error { id := d.Id() client := m.(service.DBApiClient) - scope, key, err := getScopeAndKeyFromSecretId(id) + scope, key, err := getScopeAndKeyFromSecretID(id) if err != nil { return err } @@ -101,7 +101,7 @@ func resourceSecretRead(d *schema.ResourceData, m interface{}) error { func resourceSecretDelete(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) id := d.Id() - scope, key, err := getScopeAndKeyFromSecretId(id) + scope, key, err := getScopeAndKeyFromSecretID(id) if err != nil { return err } diff --git a/databricks/resource_databricks_secret_acl.go b/databricks/resource_databricks_secret_acl.go index 4a7530d4d..d95c7b7c1 100644 --- a/databricks/resource_databricks_secret_acl.go +++ b/databricks/resource_databricks_secret_acl.go @@ -9,11 +9,11 @@ import ( "strings" ) -func resourceSecretAcl() *schema.Resource { +func resourceSecretACL() *schema.Resource { return &schema.Resource{ - Create: resourceSecretAclCreate, - Read: resourceSecretAclRead, - Delete: resourceSecretAclDelete, + Create: resourceSecretACLCreate, + Read: resourceSecretACLRead, + Delete: resourceSecretACLDelete, Schema: map[string]*schema.Schema{ "scope": &schema.Schema{ @@ -35,17 +35,15 @@ func resourceSecretAcl() *schema.Resource { } } -type SecretAclId map[string]string - -func getSecretAclId(scope string, key string) (string, error) { +func getSecretACLID(scope string, key string) (string, error) { return scope + "|||" + key, nil } -func getScopeAndKeyFromSecretAclId(SecretAclIdString string) (string, string, error) { - return strings.Split(SecretAclIdString, "|||")[0], strings.Split(SecretAclIdString, "|||")[1], nil +func getScopeAndKeyFromSecretACLID(SecretACLIDString string) (string, string, error) { + return strings.Split(SecretACLIDString, "|||")[0], strings.Split(SecretACLIDString, "|||")[1], nil } -func resourceSecretAclCreate(d *schema.ResourceData, m interface{}) error { +func resourceSecretACLCreate(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) scopeName := d.Get("scope").(string) principal := d.Get("principal").(string) @@ -54,24 +52,24 @@ func resourceSecretAclCreate(d *schema.ResourceData, m interface{}) error { if err != nil { return err } - id, err := getSecretAclId(scopeName, principal) + id, err := getSecretACLID(scopeName, principal) if err != nil { return err } d.SetId(id) - return resourceSecretAclRead(d, m) + return resourceSecretACLRead(d, m) } -func resourceSecretAclRead(d *schema.ResourceData, m interface{}) error { +func resourceSecretACLRead(d *schema.ResourceData, m interface{}) error { id := d.Id() - scope, principal, err := getScopeAndKeyFromSecretAclId(id) + scope, principal, err := getScopeAndKeyFromSecretACLID(id) if err != nil { return err } client := m.(service.DBApiClient) - secretAcl, err := client.SecretAcls().Read(scope, principal) + secretACL, err := client.SecretAcls().Read(scope, principal) if err != nil { - if isSecretAclMissing(err.Error(), scope, principal) { + if isSecretACLMissing(err.Error(), scope, principal) { log.Printf("Missing secret acl in scope with id: %s and principal: %s.", scope, principal) d.SetId("") return nil @@ -86,14 +84,14 @@ func resourceSecretAclRead(d *schema.ResourceData, m interface{}) error { if err != nil { return err } - err = d.Set("permission", secretAcl.Permission) + err = d.Set("permission", secretACL.Permission) return err } -func resourceSecretAclDelete(d *schema.ResourceData, m interface{}) error { +func resourceSecretACLDelete(d *schema.ResourceData, m interface{}) error { client := m.(service.DBApiClient) id := d.Id() - scope, key, err := getScopeAndKeyFromSecretAclId(id) + scope, key, err := getScopeAndKeyFromSecretACLID(id) if err != nil { return err } @@ -101,7 +99,7 @@ func resourceSecretAclDelete(d *schema.ResourceData, m interface{}) error { return err } -func isSecretAclMissing(errorMsg, scope string, principal string) bool { +func isSecretACLMissing(errorMsg, scope string, principal string) bool { return strings.Contains(errorMsg, "RESOURCE_DOES_NOT_EXIST") && strings.Contains(errorMsg, fmt.Sprintf("Failed to get secret acl for principal %s for scope %s.", principal, scope)) } diff --git a/databricks/resource_databricks_secret_acl_test.go b/databricks/resource_databricks_secret_acl_test.go index 991c41158..100660ed7 100644 --- a/databricks/resource_databricks_secret_acl_test.go +++ b/databricks/resource_databricks_secret_acl_test.go @@ -13,7 +13,7 @@ import ( func TestAccSecretAclResource(t *testing.T) { //var secretScope model.Secre - var secretAcl model.ACLItem + var secretACL model.ACLItem // generate a random name for each tokenInfo test run, to avoid // collisions from multiple concurrent tests. // the acctest package includes many helpers such as RandStringFromCharSet @@ -26,17 +26,17 @@ func TestAccSecretAclResource(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, - CheckDestroy: testSecretAclResourceDestroy, + CheckDestroy: testSecretACLResourceDestroy, Steps: []resource.TestStep{ { // use a dynamic configuration with the random name from above - Config: testSecretAclResource(scope, principal, permission), + Config: testSecretACLResource(scope, principal, permission), // compose a basic test, checking both remote and local values Check: resource.ComposeTestCheckFunc( // query the API to retrieve the tokenInfo object - testSecretAclResourceExists("databricks_secret_acl.my_secret_acl", &secretAcl, t), + testSecretACLResourceExists("databricks_secret_acl.my_secret_acl", &secretACL, t), // verify remote values - testSecretAclValues(t, &secretAcl, permission, principal), + testSecretACLValues(t, &secretACL, permission, principal), // verify local values resource.TestCheckResourceAttr("databricks_secret_acl.my_secret_acl", "scope", scope), resource.TestCheckResourceAttr("databricks_secret_acl.my_secret_acl", "principal", principal), @@ -47,7 +47,7 @@ func TestAccSecretAclResource(t *testing.T) { }) } -func testSecretAclResourceDestroy(s *terraform.State) error { +func testSecretACLResourceDestroy(s *terraform.State) error { client := testAccProvider.Meta().(service.DBApiClient) for _, rs := range s.RootModule().Resources { if rs.Type != "databricks_secret_acl" { @@ -57,16 +57,16 @@ func testSecretAclResourceDestroy(s *terraform.State) error { if err != nil { return nil } - return errors.New("Resource secret acl is not cleaned up!") + return errors.New("resource secret acl is not cleaned up") } return nil } -func testSecretAclPreCheck(t *testing.T) { +func testSecretACLPreCheck(t *testing.T) { return } -func testSecretAclValues(t *testing.T, acl *model.ACLItem, permission, principal string) resource.TestCheckFunc { +func testSecretACLValues(t *testing.T, acl *model.ACLItem, permission, principal string) resource.TestCheckFunc { return func(s *terraform.State) error { assert.True(t, acl.Permission == model.ACLPermissionRead) assert.True(t, acl.Principal == principal) @@ -75,7 +75,7 @@ func testSecretAclValues(t *testing.T, acl *model.ACLItem, permission, principal } // testAccCheckTokenResourceExists queries the API and retrieves the matching Widget. -func testSecretAclResourceExists(n string, aclItem *model.ACLItem, t *testing.T) resource.TestCheckFunc { +func testSecretACLResourceExists(n string, aclItem *model.ACLItem, t *testing.T) resource.TestCheckFunc { return func(s *terraform.State) error { // find the corresponding state object rs, ok := s.RootModule().Resources[n] @@ -99,7 +99,7 @@ func testSecretAclResourceExists(n string, aclItem *model.ACLItem, t *testing.T) } // testAccTokenResource returns an configuration for an Example Widget with the provided name -func testSecretAclResource(scopeName, principal, permission string) string { +func testSecretACLResource(scopeName, principal, permission string) string { return fmt.Sprintf(` resource "databricks_secret_scope" "my_scope" { name = "%s" diff --git a/databricks/resource_databricks_secret_scope.go b/databricks/resource_databricks_secret_scope.go index 45046bc18..b3ddfdd0b 100644 --- a/databricks/resource_databricks_secret_scope.go +++ b/databricks/resource_databricks_secret_scope.go @@ -74,6 +74,6 @@ func resourceSecretScopeDelete(d *schema.ResourceData, m interface{}) error { return err } -func isSecretScopeMissing(errorMsg, resourceId string) bool { - return strings.Contains(errorMsg, fmt.Sprintf("No Secret Scope found with scope name %s.", resourceId)) +func isSecretScopeMissing(errorMsg, resourceID string) bool { + return strings.Contains(errorMsg, fmt.Sprintf("no Secret Scope found with scope name %s", resourceID)) } diff --git a/databricks/resource_databricks_secret_scope_test.go b/databricks/resource_databricks_secret_scope_test.go index 4d2d085e0..1bbda725e 100644 --- a/databricks/resource_databricks_secret_scope_test.go +++ b/databricks/resource_databricks_secret_scope_test.go @@ -54,7 +54,7 @@ func testSecretScopeResourceDestroy(s *terraform.State) error { if err != nil { return nil } - return errors.New("Resource token is not cleaned up!") + return errors.New("resource token is not cleaned up") } return nil } diff --git a/databricks/resource_databricks_secret_test.go b/databricks/resource_databricks_secret_test.go index 9d91990ab..2750a883c 100644 --- a/databricks/resource_databricks_secret_test.go +++ b/databricks/resource_databricks_secret_test.go @@ -57,7 +57,7 @@ func testSecretResourceDestroy(s *terraform.State) error { if err != nil { return nil } - return errors.New("Resource secret is not cleaned up!") + return errors.New("resource secret is not cleaned up") } return nil } diff --git a/databricks/resource_databricks_token.go b/databricks/resource_databricks_token.go index 26e8706e7..fc3094176 100644 --- a/databricks/resource_databricks_token.go +++ b/databricks/resource_databricks_token.go @@ -83,12 +83,12 @@ func resourceTokenRead(d *schema.ResourceData, m interface{}) error { } func resourceTokenDelete(d *schema.ResourceData, m interface{}) error { - tokenId := d.Id() + tokenID := d.Id() client := m.(service.DBApiClient) - err := client.Tokens().Delete(tokenId) + err := client.Tokens().Delete(tokenID) return err } -func isTokenMissing(errorMsg, resourceId string) bool { - return strings.Contains(errorMsg, fmt.Sprintf("Unable to locate token: %s", resourceId)) +func isTokenMissing(errorMsg, resourceID string) bool { + return strings.Contains(errorMsg, fmt.Sprintf("Unable to locate token: %s", resourceID)) } diff --git a/databricks/resource_databricks_token_test.go b/databricks/resource_databricks_token_test.go index a47df2b31..e25890984 100644 --- a/databricks/resource_databricks_token_test.go +++ b/databricks/resource_databricks_token_test.go @@ -53,7 +53,7 @@ func testAccCheckTokenResourceDestroy(s *terraform.State) error { if err != nil { return nil } - return errors.New("Resource token is not cleaned up!") + return errors.New("resource token is not cleaned up") } return nil } @@ -65,7 +65,7 @@ func testAccPreCheck(t *testing.T) { func testAccCheckTokenValues(tokenInfo *model.TokenInfo, comment string) resource.TestCheckFunc { return func(s *terraform.State) error { if tokenInfo.Comment != comment { - return errors.New("The comment for the token created does not equal the value passed in!") + return errors.New("the comment for the token created does not equal the value passed in") } return nil } diff --git a/databricks/utils.go b/databricks/utils.go index 95d7df6a9..ed7f9b0d9 100644 --- a/databricks/utils.go +++ b/databricks/utils.go @@ -19,51 +19,49 @@ type typeCheckerReturnString interface { setNext(typeCheckerReturnString) } -type StringChecker struct { +type stringChecker struct { next typeCheckerReturnString } -func (r *StringChecker) execute(p interface{}) string { +func (r *stringChecker) execute(p interface{}) string { stringVal, ok := p.(string) if ok { if len(stringVal) > 0 { return stringVal - } else { - return "" } + return "" } return r.next.execute(p) } -func (r *StringChecker) setNext(next typeCheckerReturnString) { +func (r *stringChecker) setNext(next typeCheckerReturnString) { r.next = next } -type IntChecker struct { +type intChecker struct { next typeCheckerReturnString } -func (r *IntChecker) execute(p interface{}) string { +func (r *intChecker) execute(p interface{}) string { intVal, ok := p.(int) if ok { if intVal > 0 { return strconv.Itoa(intVal) - } else { - return "" } + return "" } return r.next.execute(p) } -func (r *IntChecker) setNext(next typeCheckerReturnString) { +func (r *intChecker) setNext(next typeCheckerReturnString) { r.next = next } -type BoolChecker struct { +type boolChecker struct { next typeCheckerReturnString } -func (r *BoolChecker) execute(p interface{}) string { +func (r *boolChecker) execute(p interface{}) string { boolVal, ok := p.(bool) if ok { return strconv.FormatBool(boolVal) @@ -71,15 +69,15 @@ func (r *BoolChecker) execute(p interface{}) string { return r.next.execute(p) } -func (r *BoolChecker) setNext(next typeCheckerReturnString) { +func (r *boolChecker) setNext(next typeCheckerReturnString) { r.next = next } -type StringSliceChecker struct { +type stringSliceChecker struct { next typeCheckerReturnString } -func (r *StringSliceChecker) execute(p interface{}) string { +func (r *stringSliceChecker) execute(p interface{}) string { sliceVal, ok := p.([]string) if ok { var stringSlice []string @@ -88,20 +86,19 @@ func (r *StringSliceChecker) execute(p interface{}) string { } sort.Strings(stringSlice) return strings.Join(stringSlice, "") - } else { - return "" } + return "" } -func (r *StringSliceChecker) setNext(next typeCheckerReturnString) { +func (r *stringSliceChecker) setNext(next typeCheckerReturnString) { r.next = next } func fetchStringFromCheckers(strVal interface{}) string { - stringChecker := &StringChecker{} - intChecker := &IntChecker{} - boolChecker := &BoolChecker{} - sliceChecker := &StringSliceChecker{} + stringChecker := &stringChecker{} + intChecker := &intChecker{} + boolChecker := &boolChecker{} + sliceChecker := &stringSliceChecker{} stringChecker.setNext(intChecker) intChecker.setNext(boolChecker) boolChecker.setNext(sliceChecker) @@ -114,7 +111,7 @@ func mapHash(v interface{}) int { m := v.(map[string]interface{}) var keys []string - for k, _ := range m { + for k := range m { keys = append(keys, k) } sort.Strings(keys) @@ -181,9 +178,9 @@ func determineAwsAttributesDiff(diff *schema.ResourceDiff, m interface{}) error return err } -func changeClusterIntoRunningState(clusterId string, client service.DBApiClient) error { +func changeClusterIntoRunningState(clusterID string, client service.DBApiClient) error { //return nil - clusterInfo, err := client.Clusters().Get(clusterId) + clusterInfo, err := client.Clusters().Get(clusterID) if err != nil { return err } @@ -195,7 +192,7 @@ func changeClusterIntoRunningState(clusterId string, client service.DBApiClient) } if model.ContainsClusterState([]model.ClusterState{model.ClusterStatePending, model.ClusterStateResizing, model.ClusterStateRestarting}, currentState) { - err := client.Clusters().WaitForClusterRunning(clusterId, 5, 180) + err := client.Clusters().WaitForClusterRunning(clusterID, 5, 180) if err != nil { return err } @@ -204,17 +201,17 @@ func changeClusterIntoRunningState(clusterId string, client service.DBApiClient) } if model.ContainsClusterState([]model.ClusterState{model.ClusterStateTerminating}, currentState) { - err := client.Clusters().WaitForClusterTerminated(clusterId, 5, 180) + err := client.Clusters().WaitForClusterTerminated(clusterID, 5, 180) if err != nil { return err } - err = client.Clusters().Start(clusterId) + err = client.Clusters().Start(clusterID) if err != nil { - if !strings.Contains(err.Error(), fmt.Sprintf("Cluster %s is in unexpected state Pending.", clusterId)) { + if !strings.Contains(err.Error(), fmt.Sprintf("Cluster %s is in unexpected state Pending.", clusterID)) { return err } } - err = client.Clusters().WaitForClusterRunning(clusterId, 5, 180) + err = client.Clusters().WaitForClusterRunning(clusterID, 5, 180) if err != nil { return err } @@ -223,14 +220,14 @@ func changeClusterIntoRunningState(clusterId string, client service.DBApiClient) } if model.ContainsClusterState([]model.ClusterState{model.ClusterStateTerminated}, currentState) { - err = client.Clusters().Start(clusterId) + err = client.Clusters().Start(clusterID) if err != nil { - if !strings.Contains(err.Error(), fmt.Sprintf("Cluster %s is in unexpected state Pending.", clusterId)) { + if !strings.Contains(err.Error(), fmt.Sprintf("Cluster %s is in unexpected state Pending.", clusterID)) { return err } } - err = client.Clusters().WaitForClusterRunning(clusterId, 5, 180) + err = client.Clusters().WaitForClusterRunning(clusterID, 5, 180) if err != nil { return err } @@ -238,6 +235,6 @@ func changeClusterIntoRunningState(clusterId string, client service.DBApiClient) return nil } - return errors.New(fmt.Sprintf("Cluster is in a non recoverable state: %s!", currentState)) + return fmt.Errorf("cluster is in a non recoverable state: %s", currentState) }