diff --git a/databricks/mounts_test.go b/databricks/mounts_test.go index ac6c2d7f0..a8dd4f7eb 100644 --- a/databricks/mounts_test.go +++ b/databricks/mounts_test.go @@ -8,16 +8,16 @@ import ( func TestValidateMountDirectory(t *testing.T) { testCases := []struct { - directory string - errorCount int - }{ - {"", 0}, - {"/directory", 0}, - {"directory", 1}, - } - for _, tc := range testCases { - _, errs := ValidateMountDirectory(tc.directory, "key") - - assert.Lenf(t, errs, tc.errorCount, "directory '%s' does not generate the expected error count", tc.directory) - } + directory string + errorCount int + }{ + {"", 0}, + {"/directory", 0}, + {"directory", 1}, + } + for _, tc := range testCases { + _, errs := ValidateMountDirectory(tc.directory, "key") + + assert.Lenf(t, errs, tc.errorCount, "directory '%s' does not generate the expected error count", tc.directory) + } } diff --git a/databricks/provider.go b/databricks/provider.go index f4ab5c66d..5bf2a20b1 100644 --- a/databricks/provider.go +++ b/databricks/provider.go @@ -26,15 +26,15 @@ func Provider(version string) 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_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(), // Scim Group is split into multiple components for flexibility to pick and choose - "databricks_group": resourceGroup(), + "databricks_group": resourceGroup(), "databricks_group_role": resourceGroupRole(), "databricks_group_member": resourceGroupMember(), "databricks_notebook": resourceNotebook(), diff --git a/databricks/resource_databricks_azure_adls_gen1_mount.go b/databricks/resource_databricks_azure_adls_gen1_mount.go index 4d6d28bd6..ee798a46f 100644 --- a/databricks/resource_databricks_azure_adls_gen1_mount.go +++ b/databricks/resource_databricks_azure_adls_gen1_mount.go @@ -39,7 +39,7 @@ func resourceAzureAdlsGen1Mount() *schema.Resource { Optional: true, Computed: true, //Default: "/", - ForceNew: true, + ForceNew: true, ValidateFunc: ValidateMountDirectory, }, "mount_name": { diff --git a/databricks/resource_databricks_azure_adls_gen2_mount.go b/databricks/resource_databricks_azure_adls_gen2_mount.go index 36388f7e7..4991dc836 100644 --- a/databricks/resource_databricks_azure_adls_gen2_mount.go +++ b/databricks/resource_databricks_azure_adls_gen2_mount.go @@ -32,10 +32,10 @@ func resourceAzureAdlsGen2Mount() *schema.Resource { ForceNew: true, }, "directory": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, ValidateFunc: ValidateMountDirectory, }, "mount_name": { diff --git a/databricks/resource_databricks_azure_blob_mount.go b/databricks/resource_databricks_azure_blob_mount.go index d9b6e9ba7..ac4143390 100644 --- a/databricks/resource_databricks_azure_blob_mount.go +++ b/databricks/resource_databricks_azure_blob_mount.go @@ -37,7 +37,7 @@ func resourceAzureBlobMount() *schema.Resource { Optional: true, Computed: true, //Default: "/", - ForceNew: true, + ForceNew: true, ValidateFunc: ValidateMountDirectory, }, "mount_name": { diff --git a/databricks/resource_databricks_group.go b/databricks/resource_databricks_group.go index 8992adbdd..b8d502619 100644 --- a/databricks/resource_databricks_group.go +++ b/databricks/resource_databricks_group.go @@ -22,13 +22,13 @@ func resourceGroup() *schema.Resource { }, "allow_cluster_create": { Deprecated: "Will be deprecated in a future release for general permissions api", - Type: schema.TypeBool, - Optional: true, + Type: schema.TypeBool, + Optional: true, }, "allow_instance_pool_create": { Deprecated: "Will be deprecated in a future release for general permissions api", - Type: schema.TypeBool, - Optional: true, + Type: schema.TypeBool, + Optional: true, }, }, Importer: &schema.ResourceImporter{ @@ -37,7 +37,6 @@ func resourceGroup() *schema.Resource { } } - func resourceGroupCreate(d *schema.ResourceData, m interface{}) error { client := m.(*service.DBApiClient) groupName := d.Get("display_name").(string) @@ -79,7 +78,7 @@ func resourceGroupRead(d *schema.ResourceData, m interface{}) error { return err } - err = d.Set("allow_cluster_create",isGroupClusterCreateEntitled(&group)) + err = d.Set("allow_cluster_create", isGroupClusterCreateEntitled(&group)) if err != nil { return err } @@ -134,7 +133,7 @@ func resourceGroupDelete(d *schema.ResourceData, m interface{}) error { } func isGroupClusterCreateEntitled(group *model.Group) bool { - for _, entitlement := range(group.Entitlements) { + for _, entitlement := range group.Entitlements { if entitlement.Value == model.AllowClusterCreateEntitlement { return true } @@ -143,10 +142,10 @@ func isGroupClusterCreateEntitled(group *model.Group) bool { } func isGroupInstancePoolCreateEntitled(group *model.Group) bool { - for _, entitlement := range(group.Entitlements) { + for _, entitlement := range group.Entitlements { if entitlement.Value == model.AllowClusterCreateEntitlement { return true } } return false -} \ No newline at end of file +} diff --git a/databricks/resource_databricks_group_aws_test.go b/databricks/resource_databricks_group_aws_test.go index b20ad6e35..675f3b3d1 100644 --- a/databricks/resource_databricks_group_aws_test.go +++ b/databricks/resource_databricks_group_aws_test.go @@ -22,7 +22,7 @@ func TestAccAWSGroupResource(t *testing.T) { randomStr := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum) displayName := fmt.Sprintf("tf group test %s", randomStr) newDisplayName := fmt.Sprintf("new tf group test %s", randomStr) - resource.Test(t, resource.TestCase{ + resource.Test(t, resource.TestCase{ Providers: testAccProviders, CheckDestroy: testAWSGroupResourceDestroy, Steps: []resource.TestStep{ @@ -34,7 +34,7 @@ func TestAccAWSGroupResource(t *testing.T) { // query the API to retrieve the tokenInfo object testAWSGroupResourceExists("databricks_group.my_group", &Group, t), // verify remote values - testAWSGroupValues(t, &Group, displayName,), + testAWSGroupValues(t, &Group, displayName), // verify local values resource.TestCheckResourceAttr("databricks_group.my_group", "display_name", displayName), ), @@ -44,9 +44,9 @@ func TestAccAWSGroupResource(t *testing.T) { // use a dynamic configuration with the random name from above Config: testAWSDatabricksGroup(newDisplayName), // test to see if new resource is attempted to be planned - PlanOnly: true, + PlanOnly: true, ExpectNonEmptyPlan: true, - Destroy: false, + Destroy: false, }, { ResourceName: "databricks_group.my_group", @@ -79,7 +79,7 @@ func TestAccAWSGroupResource_verify_entitlements(t *testing.T) { // query the API to retrieve the tokenInfo object testAWSGroupResourceExists("databricks_group.my_group", &Group, t), // verify remote values - testAWSGroupValues(t, &Group, displayName,), + testAWSGroupValues(t, &Group, displayName), // verify local values resource.TestCheckResourceAttr("databricks_group.my_group", "allow_cluster_create", "true"), resource.TestCheckResourceAttr("databricks_group.my_group", "allow_instance_pool_create", "true"), @@ -91,9 +91,9 @@ func TestAccAWSGroupResource_verify_entitlements(t *testing.T) { // use a dynamic configuration with the random name from above Config: testAWSDatabricksGroup(newDisplayName), // test to see if new resource is attempted to be planned - PlanOnly: true, + PlanOnly: true, ExpectNonEmptyPlan: true, - Destroy: false, + Destroy: false, }, }, }) diff --git a/databricks/resource_databricks_group_azure_test.go b/databricks/resource_databricks_group_azure_test.go index 489447693..984fb666d 100644 --- a/databricks/resource_databricks_group_azure_test.go +++ b/databricks/resource_databricks_group_azure_test.go @@ -34,7 +34,7 @@ func TestAccAzureGroupResource(t *testing.T) { // query the API to retrieve the tokenInfo object testAzureGroupResourceExists("databricks_group.my_group", &Group, t), // verify remote values - testAzureGroupValues(t, &Group, displayName,), + testAzureGroupValues(t, &Group, displayName), // verify local values resource.TestCheckResourceAttr("databricks_group.my_group", "display_name", displayName), ), @@ -44,9 +44,9 @@ func TestAccAzureGroupResource(t *testing.T) { // use a dynamic configuration with the random name from above Config: testAzureDatabricksGroup(newDisplayName), // test to see if new resource is attempted to be planned - PlanOnly: true, + PlanOnly: true, ExpectNonEmptyPlan: true, - Destroy: false, + Destroy: false, }, }, }) @@ -75,7 +75,7 @@ func TestAccAzureGroupResource_verify_entitlements(t *testing.T) { // query the API to retrieve the tokenInfo object testAzureGroupResourceExists("databricks_group.my_group", &Group, t), // verify remote values - testAzureGroupValues(t, &Group, displayName,), + testAzureGroupValues(t, &Group, displayName), // verify local values resource.TestCheckResourceAttr("databricks_group.my_group", "allow_cluster_create", "true"), resource.TestCheckResourceAttr("databricks_group.my_group", "allow_instance_pool_create", "true"), @@ -87,9 +87,9 @@ func TestAccAzureGroupResource_verify_entitlements(t *testing.T) { // use a dynamic configuration with the random name from above Config: testAzureDatabricksGroup(newDisplayName), // test to see if new resource is attempted to be planned - PlanOnly: true, + PlanOnly: true, ExpectNonEmptyPlan: true, - Destroy: false, + Destroy: false, }, }, }) diff --git a/databricks/resource_databricks_group_member.go b/databricks/resource_databricks_group_member.go index 37d20b762..33fbfbdd7 100644 --- a/databricks/resource_databricks_group_member.go +++ b/databricks/resource_databricks_group_member.go @@ -31,15 +31,13 @@ func resourceGroupMember() *schema.Resource { } } - - func resourceGroupMemberCreate(d *schema.ResourceData, m interface{}) error { client := m.(*service.DBApiClient) groupID := d.Get("group_id").(string) memberID := d.Get("member_id").(string) groupMemberID := &GroupMemberID{ - GroupID: groupID, + GroupID: groupID, MemberID: memberID, } @@ -85,8 +83,6 @@ func resourceGroupMemberRead(d *schema.ResourceData, m interface{}) error { return err } - - func resourceGroupMemberDelete(d *schema.ResourceData, m interface{}) error { id := d.Id() client := m.(*service.DBApiClient) @@ -98,9 +94,8 @@ func resourceGroupMemberDelete(d *schema.ResourceData, m interface{}) error { return err } - type GroupMemberID struct { - GroupID string + GroupID string MemberID string } @@ -111,16 +106,16 @@ func (g GroupMemberID) String() string { func parseGroupMemberID(id string) *GroupMemberID { parts := strings.Split(id, "|") return &GroupMemberID{ - GroupID:parts[0], - MemberID:parts[1], + GroupID: parts[0], + MemberID: parts[1], } } func iMemberInGroup(member string, group *model.Group) bool { - for _, groupMember := range(group.Members) { + for _, groupMember := range group.Members { if groupMember.Value == member { return true } } return false -} \ No newline at end of file +} diff --git a/databricks/resource_databricks_group_member_aws_test.go b/databricks/resource_databricks_group_member_aws_test.go index b2748a51e..8f1b9e699 100644 --- a/databricks/resource_databricks_group_member_aws_test.go +++ b/databricks/resource_databricks_group_member_aws_test.go @@ -23,7 +23,8 @@ func TestAccAWSGroupMemberResource(t *testing.T) { defer func() { client := testAccProvider.Meta().(*service.DBApiClient) if client != nil && manuallyCreatedGroup != nil { - client.Groups().Delete(manuallyCreatedGroup.ID) + err := client.Groups().Delete(manuallyCreatedGroup.ID) + assert.NoError(t, err, err) } }() @@ -49,12 +50,13 @@ func TestAccAWSGroupMemberResource(t *testing.T) { }, { PreConfig: func() { - // manually create subgroup c + // manually create subgroup c client := testAccProvider.Meta().(*service.DBApiClient) subGroupC, _ := client.Groups().Create("manually-created-group", nil, nil, nil) manuallyCreatedGroup = &subGroupC - // Add new subgroup to current group - client.Groups().Patch(group.ID, []string{manuallyCreatedGroup.ID}, nil, model.GroupMembersPath) + // Add new subgroup to current group + err := client.Groups().Patch(group.ID, []string{manuallyCreatedGroup.ID}, nil, model.GroupMembersPath) + assert.NoError(t, err, err) }, Config: testAWSGroupMemberResource(groupName), // compose a basic test, checking both remote and local values @@ -89,11 +91,12 @@ func TestAccAWSGroupMemberResource(t *testing.T) { // Test behavior to expect to attempt to create new role mapping because role is gone PreConfig: func() { client := testAccProvider.Meta().(*service.DBApiClient) - client.Groups().Delete(group.ID) + err := client.Groups().Delete(group.ID) + assert.NoError(t, err, err) }, - PlanOnly: true, + PlanOnly: true, ExpectNonEmptyPlan: true, - Destroy: false, + Destroy: false, }, { // use a dynamic configuration with the random name from above @@ -102,7 +105,8 @@ func TestAccAWSGroupMemberResource(t *testing.T) { // Lets delete the manually created group PreConfig: func() { client := testAccProvider.Meta().(*service.DBApiClient) - client.Groups().Delete(manuallyCreatedGroup.ID) + err := client.Groups().Delete(manuallyCreatedGroup.ID) + assert.NoError(t, err, err) manuallyCreatedGroup = nil }, // compose a basic test, checking both remote and local values @@ -138,7 +142,7 @@ func testAWSGroupMemberResourceDestroy(s *terraform.State) error { func testAWSGroupMemberValues(t *testing.T, group *model.Group, displayName string, memberCount int) resource.TestCheckFunc { return func(s *terraform.State) error { assert.True(t, group.DisplayName == displayName) - assert.Equal(t, memberCount,len(group.Members), "member count is not matching") + assert.Equal(t, memberCount, len(group.Members), "member count is not matching") return nil } } diff --git a/databricks/resource_databricks_group_member_azure_test.go b/databricks/resource_databricks_group_member_azure_test.go index ec0d3fded..8b8b355df 100644 --- a/databricks/resource_databricks_group_member_azure_test.go +++ b/databricks/resource_databricks_group_member_azure_test.go @@ -23,7 +23,8 @@ func TestAccAzureGroupMemberResource(t *testing.T) { defer func() { client := testAccProvider.Meta().(*service.DBApiClient) if client != nil && manuallyCreatedGroup != nil { - client.Groups().Delete(manuallyCreatedGroup.ID) + err := client.Groups().Delete(manuallyCreatedGroup.ID) + assert.NoError(t, err, err) } }() @@ -54,7 +55,8 @@ func TestAccAzureGroupMemberResource(t *testing.T) { subGroupC, _ := client.Groups().Create("manually-created-group", nil, nil, nil) manuallyCreatedGroup = &subGroupC // Add new subgroup to current group - client.Groups().Patch(group.ID, []string{manuallyCreatedGroup.ID}, nil, model.GroupMembersPath) + err := client.Groups().Patch(group.ID, []string{manuallyCreatedGroup.ID}, nil, model.GroupMembersPath) + assert.NoError(t, err, err) }, Config: testAzureGroupMemberResource(groupName), // compose a basic test, checking both remote and local values @@ -89,11 +91,12 @@ func TestAccAzureGroupMemberResource(t *testing.T) { // Test behavior to expect to attempt to create new role mapping because role is gone PreConfig: func() { client := testAccProvider.Meta().(*service.DBApiClient) - client.Groups().Delete(group.ID) + err := client.Groups().Delete(group.ID) + assert.NoError(t, err, err) }, - PlanOnly: true, + PlanOnly: true, ExpectNonEmptyPlan: true, - Destroy: false, + Destroy: false, }, { // use a dynamic configuration with the random name from above @@ -102,7 +105,8 @@ func TestAccAzureGroupMemberResource(t *testing.T) { // Lets delete the manually created group PreConfig: func() { client := testAccProvider.Meta().(*service.DBApiClient) - client.Groups().Delete(manuallyCreatedGroup.ID) + err := client.Groups().Delete(manuallyCreatedGroup.ID) + assert.NoError(t, err, err) manuallyCreatedGroup = nil }, // compose a basic test, checking both remote and local values @@ -138,7 +142,7 @@ func testAzureGroupMemberResourceDestroy(s *terraform.State) error { func testAzureGroupMemberValues(t *testing.T, group *model.Group, displayName string, memberCount int) resource.TestCheckFunc { return func(s *terraform.State) error { assert.True(t, group.DisplayName == displayName) - assert.Equal(t, memberCount,len(group.Members), "member count is not matching") + assert.Equal(t, memberCount, len(group.Members), "member count is not matching") return nil } } diff --git a/databricks/resource_databricks_group_role.go b/databricks/resource_databricks_group_role.go index 0cff9f3a3..34931547f 100644 --- a/databricks/resource_databricks_group_role.go +++ b/databricks/resource_databricks_group_role.go @@ -31,14 +31,12 @@ func resourceGroupRole() *schema.Resource { } } - - func resourceGroupRoleCreate(d *schema.ResourceData, m interface{}) error { client := m.(*service.DBApiClient) groupID := d.Get("group_id").(string) instanceProfileID := d.Get("instance_profile_id").(string) groupRoleID := &GroupRoleID{ - GroupID: groupID, + GroupID: groupID, InstanceProfileID: instanceProfileID, } @@ -95,9 +93,8 @@ func resourceGroupRoleDelete(d *schema.ResourceData, m interface{}) error { return err } - type GroupRoleID struct { - GroupID string + GroupID string InstanceProfileID string } @@ -108,16 +105,16 @@ func (g GroupRoleID) String() string { func parseGroupRoleID(id string) *GroupRoleID { parts := strings.Split(id, "|") return &GroupRoleID{ - GroupID:parts[0], - InstanceProfileID:parts[1], + GroupID: parts[0], + InstanceProfileID: parts[1], } } func iRoleInGroup(role string, group *model.Group) bool { - for _, groupRole := range(group.Roles) { + for _, groupRole := range group.Roles { if groupRole.Value == role { return true } } return false -} \ No newline at end of file +} diff --git a/databricks/resource_databricks_group_role_aws_test.go b/databricks/resource_databricks_group_role_aws_test.go index 5e06d73e1..d7c9b9d9d 100644 --- a/databricks/resource_databricks_group_role_aws_test.go +++ b/databricks/resource_databricks_group_role_aws_test.go @@ -38,7 +38,6 @@ func TestAccAWSGroupRoleResource(t *testing.T) { // verify local values resource.TestCheckResourceAttr("databricks_group.my_group", "display_name", groupName), resource.TestCheckResourceAttr("databricks_group_role.my_group_role", "instance_profile_id", role), - ), Destroy: false, }, @@ -49,11 +48,12 @@ func TestAccAWSGroupRoleResource(t *testing.T) { // Test behavior to expect to attempt to create new role mapping because role is gone PreConfig: func() { client := testAccProvider.Meta().(*service.DBApiClient) - client.InstanceProfiles().Delete(role) + err := client.InstanceProfiles().Delete(role) + assert.NoError(t, err, err) }, - PlanOnly: true, + PlanOnly: true, ExpectNonEmptyPlan: true, - Destroy: false, + Destroy: false, }, { // use a dynamic configuration with the random name from above @@ -62,11 +62,12 @@ func TestAccAWSGroupRoleResource(t *testing.T) { // Test behavior to expect to attempt to create new role mapping because role is gone PreConfig: func() { client := testAccProvider.Meta().(*service.DBApiClient) - client.Groups().Delete(group.ID) + err := client.Groups().Delete(group.ID) + assert.NoError(t, err, err) }, - PlanOnly: true, + PlanOnly: true, ExpectNonEmptyPlan: true, - Destroy: false, + Destroy: false, }, }, }) diff --git a/databricks/utils.go b/databricks/utils.go index 5e7f67f3c..2fa06ac35 100644 --- a/databricks/utils.go +++ b/databricks/utils.go @@ -105,7 +105,7 @@ func ValidateInstanceProfileARN(val interface{}, key string) (warns []string, er v := val.(string) if v == "" { - return nil, []error{fmt.Errorf("%s is empty got: %s, must be an aws instance profile arn", key, v, )} + return nil, []error{fmt.Errorf("%s is empty got: %s, must be an aws instance profile arn", key, v)} } // Parse and verify instance profiles @@ -116,7 +116,7 @@ func ValidateInstanceProfileARN(val interface{}, key string) (warns []string, er // Verify instance profile resource type, Resource gets parsed as instance-profile/ if !strings.HasPrefix(instanceProfileArn.Resource, "instance-profile") { return nil, []error{fmt.Errorf("%s must be an instance profile resource, got: %s in %s", - key, instanceProfileArn.Resource , v)} + key, instanceProfileArn.Resource, v)} } return nil, nil } diff --git a/databricks/utils_test.go b/databricks/utils_test.go index d92a01d47..5ef49ca30 100644 --- a/databricks/utils_test.go +++ b/databricks/utils_test.go @@ -32,8 +32,8 @@ func TestIsClusterMissingFalseWhenErrorNotInCorrectFormat(t *testing.T) { func TestValidateInstanceProfileARN(t *testing.T) { testCases := []struct { - instanceProfileARN string - errorCount int + instanceProfileARN string + errorCount int }{ {"arn:aws:iam::999999999999:instance-profile/my-fake-instance-profile", 0}, {"arn:aws:iam::999999999999:role/not-an-instance-profile", 1}, @@ -46,5 +46,3 @@ func TestValidateInstanceProfileARN(t *testing.T) { assert.Lenf(t, errs, tc.errorCount, "directory '%s' does not generate the expected error count", tc.instanceProfileARN) } } - -