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

azurerm_databricks_workspace - Upgrade Databricks API to the 2021-04-01-preview version #12543

Merged
merged 21 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
83e89be
Upgrade databricks API to 2021-04-01-preview
WodansSon Jul 10, 2021
6ef7d2b
Fix documentation lint error
WodansSon Jul 10, 2021
71cf895
Expose new fields in API
WodansSon Jul 12, 2021
c57dd87
Fix lint error
WodansSon Jul 12, 2021
e3b5948
Fix new line lint error...
WodansSon Jul 12, 2021
d5cc1f6
Stable removes depends_on requirement
WodansSon Jul 13, 2021
463ebd1
add nil checks incase resource is in failed state
WodansSon Jul 13, 2021
4f5e0f7
Stable new validation checks
WodansSon Jul 14, 2021
4d63970
Update azurerm/internal/services/databricks/databricks_workspace_reso…
WodansSon Jul 16, 2021
649d63a
Update azurerm/internal/services/databricks/databricks_workspace_reso…
WodansSon Jul 16, 2021
e4cfa27
Fully working private link
WodansSon Jul 16, 2021
d857180
Merge branch 'e-databricks-upgrade-private' of https://github.com/ter…
WodansSon Jul 16, 2021
e879cfe
Add datasource, example, and documentation
WodansSon Jul 17, 2021
45fe834
Ignore custom params not returned by the ARM GET
WodansSon Jul 17, 2021
6a9f729
Update names in example
WodansSon Jul 18, 2021
d77bea6
Update require_network_security_group_rules name
WodansSon Jul 21, 2021
ef62428
Update name in example
WodansSon Jul 21, 2021
4dbba4a
PR feedback, added examples and updated docs
WodansSon Jul 22, 2021
e21492b
rename test to remove test case ambiguity
WodansSon Jul 22, 2021
b6a0027
Update tests and documentation
WodansSon Jul 30, 2021
4e4d52f
Fix misspelling in documentation
WodansSon Jul 30, 2021
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 azurerm/internal/services/databricks/client/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/databricks/mgmt/2018-04-01/databricks"
"github.com/Azure/azure-sdk-for-go/services/preview/databricks/mgmt/2021-04-01-preview/databricks"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/databricks/mgmt/2018-04-01/databricks"
"github.com/Azure/azure-sdk-for-go/services/preview/databricks/mgmt/2021-04-01-preview/databricks"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks"
Expand Down Expand Up @@ -148,22 +148,14 @@ func DatabricksWorkspaceCustomerManagedKeyCreateUpdate(d *pluginsdk.ResourceData
params := workspace.Parameters
params.Encryption = &databricks.WorkspaceEncryptionParameter{
Value: &databricks.Encryption{
KeySource: databricks.MicrosoftKeyvault,
KeySource: databricks.KeySourceMicrosoftKeyvault,
KeyName: &key.Name,
KeyVersion: &key.Version,
KeyVaultURI: &key.KeyVaultBaseUrl,
},
}

props := databricks.Workspace{
Location: workspace.Location,
Sku: workspace.Sku,
WorkspaceProperties: &databricks.WorkspaceProperties{
ManagedResourceGroupID: workspace.WorkspaceProperties.ManagedResourceGroupID,
Parameters: params,
},
Tags: workspace.Tags,
}
props := getProps(workspace, params)

future, err := workspaceClient.CreateOrUpdate(ctx, props, resourceID.ResourceGroup, resourceID.CustomerMangagedKeyName)
if err != nil {
Expand Down Expand Up @@ -229,7 +221,7 @@ func DatabricksWorkspaceCustomerManagedKeyRead(d *pluginsdk.ResourceData, meta i
// return fmt.Errorf("retrieving Databricks Workspace %q (Resource Group %q): `Workspace.WorkspaceProperties.Encryption.Value.KeySource` was expected to be %q, got %q", id.CustomerMangagedKeyName, id.ResourceGroup, string(databricks.MicrosoftKeyvault), keySource)
// }

if strings.EqualFold(keySource, string(databricks.MicrosoftKeyvault)) && (keyName == "" || keyVersion == "" || keyVaultURI == "") {
if strings.EqualFold(keySource, string(databricks.KeySourceMicrosoftKeyvault)) && (keyName == "" || keyVersion == "" || keyVaultURI == "") {
return fmt.Errorf("Databricks Workspace %q (Resource Group %q): `Workspace.WorkspaceProperties.Encryption.Value(s)` were nil", id.CustomerMangagedKeyName, id.ResourceGroup)
}

Expand Down Expand Up @@ -282,28 +274,40 @@ func DatabricksWorkspaceCustomerManagedKeyDelete(d *pluginsdk.ResourceData, meta
params := workspace.Parameters
params.Encryption = &databricks.WorkspaceEncryptionParameter{
Value: &databricks.Encryption{
KeySource: databricks.Default,
KeySource: databricks.KeySourceDefault,
},
}

props := getProps(workspace, params)

future, err := client.CreateOrUpdate(ctx, props, workspaceID.ResourceGroup, workspaceID.Name)
if err != nil {
return fmt.Errorf("creating/updating %s: %+v", workspaceID, err)
}

if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for create/update of %s: %+v", workspaceID, err)
}

return nil
}

func getProps(workspace databricks.Workspace, params *databricks.WorkspaceCustomParameters) databricks.Workspace {
props := databricks.Workspace{
Location: workspace.Location,
Sku: workspace.Sku,
WorkspaceProperties: &databricks.WorkspaceProperties{
PublicNetworkAccess: workspace.PublicNetworkAccess,
ManagedResourceGroupID: workspace.WorkspaceProperties.ManagedResourceGroupID,
Parameters: params,
},
Tags: workspace.Tags,
}

future, err := client.CreateOrUpdate(ctx, props, workspaceID.ResourceGroup, workspaceID.Name)
if err != nil {
return fmt.Errorf("creating/updating %s: %+v", workspaceID, err)
// This is only valid if Private Link only is set
if workspace.PublicNetworkAccess == databricks.PublicNetworkAccessDisabled {
props.WorkspaceProperties.RequiredNsgRules = workspace.WorkspaceProperties.RequiredNsgRules
}

if err = future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for create/update of %s: %+v", workspaceID, err)
}

return nil
return props
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"testing"

"github.com/Azure/azure-sdk-for-go/services/databricks/mgmt/2018-04-01/databricks"
"github.com/Azure/azure-sdk-for-go/services/preview/databricks/mgmt/2021-04-01-preview/databricks"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance/check"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
Expand Down Expand Up @@ -117,7 +117,7 @@ func (DatabricksWorkspaceCustomerManagedKeyResource) Exists(ctx context.Context,

// This is the only way we can tell if the CMK has actually been provisioned or not...
if resp.WorkspaceProperties.Parameters != nil && resp.WorkspaceProperties.Parameters.Encryption != nil {
if resp.WorkspaceProperties.Parameters.Encryption.Value.KeySource == databricks.MicrosoftKeyvault {
if resp.WorkspaceProperties.Parameters.Encryption.Value.KeySource == databricks.KeySourceMicrosoftKeyvault {
return utils.Bool(true), nil
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package databricks

import (
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/databricks/mgmt/2021-04-01-preview/databricks"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databricks/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceDatabricksWorkspacePrivateEndpointConnection() *pluginsdk.Resource {
return &pluginsdk.Resource{
Read: dataSourceDatabricksWorkspacePrivateEndpointConnectionRead,

Timeouts: &pluginsdk.ResourceTimeout{
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*pluginsdk.Schema{
"workspace_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: azure.ValidateResourceID,
},

"private_endpoint_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: azure.ValidateResourceID,
},

"connections": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"workspace_private_endpoint_id": {
Type: pluginsdk.TypeString,
Computed: true,
},

"name": {
Type: pluginsdk.TypeString,
Computed: true,
},

"status": {
Type: pluginsdk.TypeString,
Computed: true,
},

"description": {
Type: pluginsdk.TypeString,
Computed: true,
},

"action_required": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},
},
}
}

func dataSourceDatabricksWorkspacePrivateEndpointConnectionRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DataBricks.WorkspacesClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()
workspace := d.Get("workspace_id").(string)
endpointId := d.Get("private_endpoint_id").(string)

id, err := parse.WorkspaceID(workspace)
if err != nil {
return err
}

resp, err := client.Get(ctx, id.ResourceGroup, id.Name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("%s was not found", id)
}

return fmt.Errorf("making Read request on %s: %+v", id, err)
}

d.SetId(id.ID())

d.Set("workspace_id", workspace)
d.Set("private_endpoint_id", endpointId)

if props := resp.WorkspaceProperties; props != nil {
if err := d.Set("connections", flattenPrivateEndpointConnections(props.PrivateEndpointConnections)); err != nil {
return fmt.Errorf("setting `connections`: %+v", err)
}
}

return nil
}

func flattenPrivateEndpointConnections(input *[]databricks.PrivateEndpointConnection) []interface{} {
results := make([]interface{}, 0)
if input == nil {
return results
}

for _, v := range *input {
result := make(map[string]interface{})

if name := v.Name; name != nil {
result["name"] = *name
}

if id := v.ID; id != nil {
result["workspace_private_endpoint_id"] = *id
}

if props := v.Properties; props != nil {
if connState := props.PrivateLinkServiceConnectionState; connState != nil {
if description := connState.Description; description != nil {
result["description"] = *description
}
if status := connState.Status; status != "" {
result["status"] = status
}
if actionReq := connState.ActionRequired; actionReq != nil {
result["action_required"] = *actionReq
}
}
}

results = append(results, result)
}

return results
}
Loading