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

databricks - regenerate embedded sdk #14157

Merged
merged 1 commit into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func DatabricksWorkspaceCustomerManagedKeyCreateUpdate(d *pluginsdk.ResourceData

// Not sure if I should also lock the key vault here too
// or at the very least the key?
locks.ByName(id.Name, "azurerm_databricks_workspace")
defer locks.UnlockByName(id.Name, "azurerm_databricks_workspace")
locks.ByName(id.WorkspaceName, "azurerm_databricks_workspace")
defer locks.UnlockByName(id.WorkspaceName, "azurerm_databricks_workspace")
var encryptionEnabled, infrastructureEnabled bool

workspace, err := workspaceClient.Get(ctx, *id)
Expand Down Expand Up @@ -130,7 +130,7 @@ func DatabricksWorkspaceCustomerManagedKeyCreateUpdate(d *pluginsdk.ResourceData
return fmt.Errorf("retrieving the Resource ID for the Key Vault at URL %q: %+v", key.KeyVaultBaseUrl, err)
}

resourceID := parse.NewCustomerManagedKeyID(subscriptionId, id.ResourceGroup, id.Name)
resourceID := parse.NewCustomerManagedKeyID(subscriptionId, id.ResourceGroupName, id.WorkspaceName)

if d.IsNewResource() {
if workspace.Model != nil && workspace.Model.Properties.Parameters != nil && workspace.Model.Properties.Parameters.Encryption != nil {
Expand Down Expand Up @@ -242,8 +242,8 @@ func DatabricksWorkspaceCustomerManagedKeyDelete(d *pluginsdk.ResourceData, meta
workspaceID := workspaces.NewWorkspaceID(id.SubscriptionId, id.ResourceGroup, id.CustomerMangagedKeyName)

// Not sure if I should also lock the key vault here too
locks.ByName(workspaceID.Name, "azurerm_databricks_workspace")
defer locks.UnlockByName(workspaceID.Name, "azurerm_databricks_workspace")
locks.ByName(workspaceID.WorkspaceName, "azurerm_databricks_workspace")
defer locks.UnlockByName(workspaceID.WorkspaceName, "azurerm_databricks_workspace")

workspace, err := client.Get(ctx, workspaceID)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (DatabricksWorkspaceCustomerManagedKeyResource) Exists(ctx context.Context,

resp, err := clients.DataBricks.WorkspacesClient.Get(ctx, *id)
if err != nil {
return nil, fmt.Errorf("retrieving Databricks Workspace Customer Mangaged Key %q (resource group: %q): %+v", id.Name, id.ResourceGroup, err)
return nil, fmt.Errorf("retrieving %s: %+v", id, err)
}

// This is the only way we can tell if the CMK has actually been provisioned or not...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func dataSourceDatabricksWorkspaceRead(d *pluginsdk.ResourceData, meta interface

d.SetId(id.ID())

d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("name", id.WorkspaceName)
d.Set("resource_group_name", id.ResourceGroupName)
d.Set("sku", resp.Model.Sku.Name)
if model := resp.Model; model != nil {
d.Set("workspace_id", model.Properties.WorkspaceId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func resourceDatabricksWorkspaceCreateUpdate(d *pluginsdk.ResourceData, meta int
if managedResourceGroupName == "" {
// no managed resource group name was provided, we use the default pattern
log.Printf("[DEBUG][azurerm_databricks_workspace] no managed resource group id was provided, we use the default pattern.")
managedResourceGroupName = fmt.Sprintf("databricks-rg-%s", id.ResourceGroup)
managedResourceGroupName = fmt.Sprintf("databricks-rg-%s", id.ResourceGroupName)
}

managedResourceGroupID := resourcesParse.NewResourceGroupID(subscriptionId, managedResourceGroupName).ID()
Expand Down Expand Up @@ -515,8 +515,8 @@ func resourceDatabricksWorkspaceRead(d *pluginsdk.ResourceData, meta interface{}
return fmt.Errorf("retrieving %s: %+v", *id, err)
}

d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("name", id.WorkspaceName)
d.Set("resource_group_name", id.ResourceGroupName)

if model := resp.Model; model != nil {
d.Set("location", azure.NormalizeLocation(model.Location))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (DatabricksWorkspaceResource) Exists(ctx context.Context, clients *clients.

resp, err := clients.DataBricks.WorkspacesClient.Get(ctx, *id)
if err != nil {
return nil, fmt.Errorf("retrieving Analysis Services Server %q (resource group: %q): %+v", id.Name, id.ResourceGroup, err)
return nil, fmt.Errorf("retrieving Analysis Services Server %q (resource group: %q): %+v", id.WorkspaceName, id.ResourceGroupName, err)
}

return utils.Bool(resp.Model != nil), nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,120 +7,131 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

var _ resourceids.ResourceId = PrivateEndpointConnectionId{}

// PrivateEndpointConnectionId is a struct representing the Resource ID for a Private Endpoint Connection
type PrivateEndpointConnectionId struct {
SubscriptionId string
ResourceGroup string
WorkspaceName string
Name string
SubscriptionId string
ResourceGroupName string
WorkspaceName string
PrivateEndpointConnectionName string
}

func NewPrivateEndpointConnectionID(subscriptionId, resourceGroup, workspaceName, name string) PrivateEndpointConnectionId {
// NewPrivateEndpointConnectionID returns a new PrivateEndpointConnectionId struct
func NewPrivateEndpointConnectionID(subscriptionId string, resourceGroupName string, workspaceName string, privateEndpointConnectionName string) PrivateEndpointConnectionId {
return PrivateEndpointConnectionId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
WorkspaceName: workspaceName,
Name: name,
SubscriptionId: subscriptionId,
ResourceGroupName: resourceGroupName,
WorkspaceName: workspaceName,
PrivateEndpointConnectionName: privateEndpointConnectionName,
}
}

func (id PrivateEndpointConnectionId) String() string {
segments := []string{
fmt.Sprintf("Name %q", id.Name),
fmt.Sprintf("Workspace Name %q", id.WorkspaceName),
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Private Endpoint Connection", segmentsStr)
}

func (id PrivateEndpointConnectionId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Databricks/workspaces/%s/privateEndpointConnections/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.WorkspaceName, id.Name)
}

// ParsePrivateEndpointConnectionID parses a PrivateEndpointConnection ID into an PrivateEndpointConnectionId struct
// ParsePrivateEndpointConnectionID parses 'input' into a PrivateEndpointConnectionId
func ParsePrivateEndpointConnectionID(input string) (*PrivateEndpointConnectionId, error) {
id, err := resourceids.ParseAzureResourceID(input)
parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{})
parsed, err := parser.Parse(input, false)
if err != nil {
return nil, err
return nil, fmt.Errorf("parsing %q: %+v", input, err)
}

resourceId := PrivateEndpointConnectionId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}
var ok bool
id := PrivateEndpointConnectionId{}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok {
return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input)
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok {
return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input)
}

if resourceId.WorkspaceName, err = id.PopSegment("workspaces"); err != nil {
return nil, err
}
if resourceId.Name, err = id.PopSegment("privateEndpointConnections"); err != nil {
return nil, err
if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok {
return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input)
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok {
return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input)
}

return &resourceId, nil
return &id, nil
}

// ParsePrivateEndpointConnectionIDInsensitively parses an PrivateEndpointConnection ID into an PrivateEndpointConnectionId struct, insensitively
// This should only be used to parse an ID for rewriting to a consistent casing,
// the ParsePrivateEndpointConnectionID method should be used instead for validation etc.
// ParsePrivateEndpointConnectionIDInsensitively parses 'input' case-insensitively into a PrivateEndpointConnectionId
// note: this method should only be used for API response data and not user input
func ParsePrivateEndpointConnectionIDInsensitively(input string) (*PrivateEndpointConnectionId, error) {
id, err := resourceids.ParseAzureResourceID(input)
parser := resourceids.NewParserFromResourceIdType(PrivateEndpointConnectionId{})
parsed, err := parser.Parse(input, true)
if err != nil {
return nil, err
return nil, fmt.Errorf("parsing %q: %+v", input, err)
}

resourceId := PrivateEndpointConnectionId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}
var ok bool
id := PrivateEndpointConnectionId{}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok {
return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input)
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok {
return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input)
}

// find the correct casing for the 'workspaces' segment
workspacesKey := "workspaces"
for key := range id.Path {
if strings.EqualFold(key, workspacesKey) {
workspacesKey = key
break
}
if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok {
return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input)
}
if resourceId.WorkspaceName, err = id.PopSegment(workspacesKey); err != nil {
return nil, err

if id.PrivateEndpointConnectionName, ok = parsed.Parsed["privateEndpointConnectionName"]; !ok {
return nil, fmt.Errorf("the segment 'privateEndpointConnectionName' was not found in the resource id %q", input)
}

// find the correct casing for the 'privateEndpointConnections' segment
privateEndpointConnectionsKey := "privateEndpointConnections"
for key := range id.Path {
if strings.EqualFold(key, privateEndpointConnectionsKey) {
privateEndpointConnectionsKey = key
break
}
return &id, nil
}

// ValidatePrivateEndpointConnectionID checks that 'input' can be parsed as a Private Endpoint Connection ID
func ValidatePrivateEndpointConnectionID(input interface{}, key string) (warnings []string, errors []error) {
v, ok := input.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected %q to be a string", key))
return
}
if resourceId.Name, err = id.PopSegment(privateEndpointConnectionsKey); err != nil {
return nil, err

if _, err := ParsePrivateEndpointConnectionID(v); err != nil {
errors = append(errors, err)
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
return
}

// ID returns the formatted Private Endpoint Connection ID
func (id PrivateEndpointConnectionId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Databricks/workspaces/%s/privateEndpointConnections/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.PrivateEndpointConnectionName)
}

// Segments returns a slice of Resource ID Segments which comprise this Private Endpoint Connection ID
func (id PrivateEndpointConnectionId) Segments() []resourceids.Segment {
return []resourceids.Segment{
resourceids.StaticSegment("subscriptions", "subscriptions", "subscriptions"),
resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"),
resourceids.StaticSegment("resourceGroups", "resourceGroups", "resourceGroups"),
resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"),
resourceids.StaticSegment("providers", "providers", "providers"),
resourceids.ResourceProviderSegment("microsoftDatabricks", "Microsoft.Databricks", "Microsoft.Databricks"),
resourceids.StaticSegment("workspaces", "workspaces", "workspaces"),
resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"),
resourceids.StaticSegment("privateEndpointConnections", "privateEndpointConnections", "privateEndpointConnections"),
resourceids.UserSpecifiedSegment("privateEndpointConnectionName", "privateEndpointConnectionValue"),
}
}

return &resourceId, nil
// String returns a human-readable description of this Private Endpoint Connection ID
func (id PrivateEndpointConnectionId) String() string {
components := []string{
fmt.Sprintf("Subscription: %q", id.SubscriptionId),
fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName),
fmt.Sprintf("Workspace Name: %q", id.WorkspaceName),
fmt.Sprintf("Private Endpoint Connection Name: %q", id.PrivateEndpointConnectionName),
}
return fmt.Sprintf("Private Endpoint Connection (%s)", strings.Join(components, "\n"))
}
Loading