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

[New Resource:] azurerm_databricks_virtual_network_peering #20728

Merged
merged 25 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b8e3272
Update go-azure-sdk v0.20230228.1160358 => v0.20230301.1141943
WodansSon Mar 2, 2023
54c4add
Check-in progress...
WodansSon Mar 2, 2023
9bfdd46
Check-in progress...
WodansSon Mar 2, 2023
37dd29f
pull changes from main
WodansSon Mar 2, 2023
7dd41e2
Check-in progress...
WodansSon Mar 2, 2023
d25ed01
Checking-in progress...
WodansSon Mar 4, 2023
a7edac1
terrafmt docs...
WodansSon Mar 4, 2023
cffd531
update test case to use sku parameter...
WodansSon Mar 4, 2023
7ddaec2
Check-in progress...
WodansSon Mar 4, 2023
99fff59
Remove test case...
WodansSon Mar 4, 2023
05838f0
Check-in progress...
WodansSon Mar 4, 2023
c2cef32
match field names with network resource
WodansSon Mar 6, 2023
4d9c7e4
add comment about delete SDK issue...
WodansSon Mar 7, 2023
93d5d18
Per PR review moved resource mutex from sync to the terraform interna…
WodansSon Mar 15, 2023
361abde
Checking-in PR changes progress...
WodansSon Mar 18, 2023
51dd98a
Merge branch 'main' of https://github.com/hashicorp/terraform-provide…
WodansSon Mar 18, 2023
b833626
go mod vendor
WodansSon Mar 18, 2023
42dab33
Update client name to match SDK...
WodansSon Mar 18, 2023
ad7868d
Check-in progress...
WodansSon Mar 20, 2023
4073635
Remove workaround for SDK issue...
WodansSon Mar 20, 2023
390cbf1
Update delete func to be just DeleteThenPoll...
WodansSon Mar 22, 2023
ff03612
Address additional PR comments...
WodansSon Mar 22, 2023
d5a2ee6
Merge branch 'main' of https://github.com/hashicorp/terraform-provide…
WodansSon Mar 22, 2023
31efc4d
Add test workaround for AzSecPack...
WodansSon Mar 22, 2023
c42e391
Remove parse directory...
WodansSon Mar 22, 2023
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
9 changes: 9 additions & 0 deletions internal/services/databricks/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"fmt"

"github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2022-04-01-preview/accessconnector"
"github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering"
"github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/workspaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

type Client struct {
AccessConnectorClient *accessconnector.AccessConnectorClient
WorkspacesClient *workspaces.WorkspacesClient
VnetPeeringClient *vnetpeering.VNetPeeringClient
}

func NewClient(o *common.ClientOptions) (*Client, error) {
Expand All @@ -26,8 +28,15 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
}
o.Configure(workspacesClient.Client, o.Authorizers.ResourceManager)

vnetPeeringClient, err := vnetpeering.NewVNetPeeringClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building VNetPeering client: %+v", err)
}
o.Configure(vnetPeeringClient.Client, o.Authorizers.ResourceManager)

return &Client{
AccessConnectorClient: accessConnectorClient,
WorkspacesClient: workspacesClient,
VnetPeeringClient: vnetPeeringClient,
}, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,356 @@
package databricks

import (
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering"
"github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/workspaces"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/databricks/validate"
networkParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse"
networkValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

const databricksVnetPeeringsResourceType string = "azurerm_databricks_virtual_network_peering"

func resourceDatabricksVirtualNetworkPeering() *pluginsdk.Resource {
return &pluginsdk.Resource{
Create: resourceDatabricksVirtualNetworkPeeringCreate,
Read: resourceDatabricksVirtualNetworkPeeringRead,
Update: resourceDatabricksVirtualNetworkPeeringUpdate,
Delete: resourceDatabricksVirtualNetworkPeeringDelete,
Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := vnetpeering.ParseVirtualNetworkPeeringID(id)
return err
}),

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

Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.DatabricksVirtualNetworkPeeringName,
},

"resource_group_name": commonschema.ResourceGroupName(),

"workspace_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: workspaces.ValidateWorkspaceID,
},

"remote_address_space_prefixes": {
Type: pluginsdk.TypeList,
Required: true,
ForceNew: true,

Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validate.CIDRIsIPv4OrIPv6,
},
},

"remote_virtual_network_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: networkValidate.VirtualNetworkID,
},

"address_space_prefixes": {
Type: pluginsdk.TypeList,
Computed: true,

Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},

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

"allow_virtual_network_access": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},

"allow_forwarded_traffic": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"allow_gateway_transit": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},

"use_remote_gateways": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
},
},
}
}

func resourceDatabricksVirtualNetworkPeeringCreate(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DataBricks.VnetPeeringClient
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

log.Printf("[INFO] preparing arguments for Azure ARM databricks virtual network peering creation.")
var id vnetpeering.VirtualNetworkPeeringId

// I need to include the workspace ID in the properties because I need the name
// of the workspace to create the peerings ID
workspaceId, err := vnetpeering.ParseWorkspaceID(d.Get("workspace_id").(string))
if err != nil {
return fmt.Errorf("unable to parse 'workspace_id': %+v", err)
}

id = vnetpeering.NewVirtualNetworkPeeringID(subscriptionId, d.Get("resource_group_name").(string), workspaceId.WorkspaceName, d.Get("name").(string))

existing, err := client.Get(ctx, id)
if err != nil {
if !response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("checking for presence of existing Databricks %s: %s", id, err)
}
}

if !response.WasNotFound(existing.HttpResponse) {
return tf.ImportAsExistsError("azurerm_databricks_virtual_network_peering", id.ID())
}

allowForwardedTraffic := d.Get("allow_forwarded_traffic").(bool)
allowGatewayTransit := d.Get("allow_gateway_transit").(bool)
allowVirtualNetworkAccess := d.Get("allow_virtual_network_access").(bool)
useRemoteGateways := d.Get("use_remote_gateways").(bool)
remoteVirtualNetwork := d.Get("remote_virtual_network_id").(string)
databricksAddressSpace := utils.ExpandStringSlice(d.Get("address_space_prefixes").([]interface{}))
remoteAddressSpace := utils.ExpandStringSlice(d.Get("remote_address_space_prefixes").([]interface{}))

props := vnetpeering.VirtualNetworkPeeringPropertiesFormat{
DatabricksAddressSpace: &vnetpeering.AddressSpace{
AddressPrefixes: databricksAddressSpace,
},
// The RP always creates the same vNet ID for the Databricks internal vNet in the below format:
// '/subscriptions/{subscription}/resourceGroups/{group1}/providers/Microsoft.Network/virtualNetworks/workers-vnet'
DatabricksVirtualNetwork: &vnetpeering.VirtualNetworkPeeringPropertiesFormatDatabricksVirtualNetwork{
Id: utils.String(networkParse.NewVirtualNetworkID(id.SubscriptionId, id.ResourceGroupName, "workers-vnet").ID()),
},
RemoteAddressSpace: &vnetpeering.AddressSpace{
AddressPrefixes: remoteAddressSpace,
},
RemoteVirtualNetwork: vnetpeering.VirtualNetworkPeeringPropertiesFormatRemoteVirtualNetwork{
Id: utils.String(remoteVirtualNetwork),
},
AllowForwardedTraffic: &allowForwardedTraffic,
AllowGatewayTransit: &allowGatewayTransit,
AllowVirtualNetworkAccess: &allowVirtualNetworkAccess,
UseRemoteGateways: &useRemoteGateways,
}

peer := vnetpeering.VirtualNetworkPeering{
Name: &id.VirtualNetworkPeeringName,
Properties: props,
}

locks.ByID(databricksVnetPeeringsResourceType)
defer locks.UnlockByID(databricksVnetPeeringsResourceType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

presumably the lock wants moving up to the top?

Also, per ARM we don't need to set Name btw, the API should be ignoring/rejecting it per the ARM Spec:

Suggested change
existing, err := client.Get(ctx, id)
if err != nil {
if !response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("checking for presence of existing Databricks %s: %s", id, err)
}
}
if !response.WasNotFound(existing.HttpResponse) {
return tf.ImportAsExistsError("azurerm_databricks_virtual_network_peering", id.ID())
}
allowForwardedTraffic := d.Get("allow_forwarded_traffic").(bool)
allowGatewayTransit := d.Get("allow_gateway_transit").(bool)
allowVirtualNetworkAccess := d.Get("allow_virtual_network_access").(bool)
useRemoteGateways := d.Get("use_remote_gateways").(bool)
remoteVirtualNetwork := d.Get("remote_virtual_network_id").(string)
databricksAddressSpace := utils.ExpandStringSlice(d.Get("address_space_prefixes").([]interface{}))
remoteAddressSpace := utils.ExpandStringSlice(d.Get("remote_address_space_prefixes").([]interface{}))
props := vnetpeering.VirtualNetworkPeeringPropertiesFormat{
DatabricksAddressSpace: &vnetpeering.AddressSpace{
AddressPrefixes: databricksAddressSpace,
},
// The RP always creates the same vNet ID for the Databricks internal vNet in the below format:
// '/subscriptions/{subscription}/resourceGroups/{group1}/providers/Microsoft.Network/virtualNetworks/workers-vnet'
DatabricksVirtualNetwork: &vnetpeering.VirtualNetworkPeeringPropertiesFormatDatabricksVirtualNetwork{
Id: utils.String(networkParse.NewVirtualNetworkID(id.SubscriptionId, id.ResourceGroupName, "workers-vnet").ID()),
},
RemoteAddressSpace: &vnetpeering.AddressSpace{
AddressPrefixes: remoteAddressSpace,
},
RemoteVirtualNetwork: vnetpeering.VirtualNetworkPeeringPropertiesFormatRemoteVirtualNetwork{
Id: utils.String(remoteVirtualNetwork),
},
AllowForwardedTraffic: &allowForwardedTraffic,
AllowGatewayTransit: &allowGatewayTransit,
AllowVirtualNetworkAccess: &allowVirtualNetworkAccess,
UseRemoteGateways: &useRemoteGateways,
}
peer := vnetpeering.VirtualNetworkPeering{
Name: &id.VirtualNetworkPeeringName,
Properties: props,
}
locks.ByID(databricksVnetPeeringsResourceType)
defer locks.UnlockByID(databricksVnetPeeringsResourceType)
locks.ByID(databricksVnetPeeringsResourceType)
defer locks.UnlockByID(databricksVnetPeeringsResourceType)
existing, err := client.Get(ctx, id)
if err != nil {
if !response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("checking for presence of existing Databricks %s: %s", id, err)
}
}
if !response.WasNotFound(existing.HttpResponse) {
return tf.ImportAsExistsError("azurerm_databricks_virtual_network_peering", id.ID())
}
allowForwardedTraffic := d.Get("allow_forwarded_traffic").(bool)
allowGatewayTransit := d.Get("allow_gateway_transit").(bool)
allowVirtualNetworkAccess := d.Get("allow_virtual_network_access").(bool)
useRemoteGateways := d.Get("use_remote_gateways").(bool)
remoteVirtualNetwork := d.Get("remote_virtual_network_id").(string)
databricksAddressSpace := utils.ExpandStringSlice(d.Get("address_space_prefixes").([]interface{}))
remoteAddressSpace := utils.ExpandStringSlice(d.Get("remote_address_space_prefixes").([]interface{}))
props := vnetpeering.VirtualNetworkPeeringPropertiesFormat{
DatabricksAddressSpace: &vnetpeering.AddressSpace{
AddressPrefixes: databricksAddressSpace,
},
// The RP always creates the same vNet ID for the Databricks internal vNet in the below format:
// '/subscriptions/{subscription}/resourceGroups/{group1}/providers/Microsoft.Network/virtualNetworks/workers-vnet'
DatabricksVirtualNetwork: &vnetpeering.VirtualNetworkPeeringPropertiesFormatDatabricksVirtualNetwork{
Id: utils.String(networkParse.NewVirtualNetworkID(id.SubscriptionId, id.ResourceGroupName, "workers-vnet").ID()),
},
RemoteAddressSpace: &vnetpeering.AddressSpace{
AddressPrefixes: remoteAddressSpace,
},
RemoteVirtualNetwork: vnetpeering.VirtualNetworkPeeringPropertiesFormatRemoteVirtualNetwork{
Id: utils.String(remoteVirtualNetwork),
},
AllowForwardedTraffic: &allowForwardedTraffic,
AllowGatewayTransit: &allowGatewayTransit,
AllowVirtualNetworkAccess: &allowVirtualNetworkAccess,
UseRemoteGateways: &useRemoteGateways,
}
peer := vnetpeering.VirtualNetworkPeering{
Properties: props,
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


deadline, ok := ctx.Deadline()
if !ok {
return fmt.Errorf("internal-error: context had no deadline")
}

stateConf := &pluginsdk.StateChangeConf{
Pending: []string{"Pending"},
Target: []string{"Created"},
Timeout: time.Until(deadline),
Delay: 15 * time.Second,
Refresh: func() (interface{}, string, error) {
future, err := client.CreateOrUpdate(ctx, id, peer)
if err != nil {
if utils.ResponseErrorIsRetryable(err) {
return future.HttpResponse, "Pending", err
} else {
if resp := future.HttpResponse; resp != nil && response.WasBadRequest(resp) && strings.Contains(err.Error(), "ReferencedResourceNotProvisioned") {
// Resource is not yet ready, this may be the case if the Vnet was just created or another peering was just initiated.
return future.HttpResponse, "Pending", err
}
}

return future.HttpResponse, "", err
}

if err = future.Poller.PollUntilDone(ctx); err != nil {
return future.HttpResponse, "", err
}

return future.HttpResponse, "Created", nil
},
}

if _, err := stateConf.WaitForStateContext(ctx); err != nil {
return fmt.Errorf("waiting for Databricks %s to be created: %+v", id, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we're locking on the creation and we wait for the dependent resources to be created (since we won't return either the Virtual Network or the DataBricks Cluster until it's marked as fully provisioned) - I don't believe this is still needed - so I'm wondering if we can switch to using the regular LRO directly and remove the WaitForState func entirely?

Suggested change
deadline, ok := ctx.Deadline()
if !ok {
return fmt.Errorf("internal-error: context had no deadline")
}
stateConf := &pluginsdk.StateChangeConf{
Pending: []string{"Pending"},
Target: []string{"Created"},
Timeout: time.Until(deadline),
Delay: 15 * time.Second,
Refresh: func() (interface{}, string, error) {
future, err := client.CreateOrUpdate(ctx, id, peer)
if err != nil {
if utils.ResponseErrorIsRetryable(err) {
return future.HttpResponse, "Pending", err
} else {
if resp := future.HttpResponse; resp != nil && response.WasBadRequest(resp) && strings.Contains(err.Error(), "ReferencedResourceNotProvisioned") {
// Resource is not yet ready, this may be the case if the Vnet was just created or another peering was just initiated.
return future.HttpResponse, "Pending", err
}
}
return future.HttpResponse, "", err
}
if err = future.Poller.PollUntilDone(ctx); err != nil {
return future.HttpResponse, "", err
}
return future.HttpResponse, "Created", nil
},
}
if _, err := stateConf.WaitForStateContext(ctx); err != nil {
return fmt.Errorf("waiting for Databricks %s to be created: %+v", id, err)
}
if err := client.CreateOrUpdateThenPoll(ctx, id, peer); err != nil {
return fmt.Errorf("creating Databricks %s: %+v", id, err)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


d.SetId(id.ID())

return resourceDatabricksVirtualNetworkPeeringRead(d, meta)
}

func resourceDatabricksVirtualNetworkPeeringRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DataBricks.VnetPeeringClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := vnetpeering.ParseVirtualNetworkPeeringID(d.Id())
if err != nil {
return err
}

resp, err := client.Get(ctx, *id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
d.SetId("")
return nil
}

return fmt.Errorf("retrieving Databricks %s: %+v", *id, err)
}

d.Set("resource_group_name", id.ResourceGroupName)
d.Set("name", id.VirtualNetworkPeeringName)
d.Set("workspace_id", vnetpeering.NewWorkspaceID(id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName).ID())

if model := resp.Model; model != nil {
d.Set("allow_virtual_network_access", model.Properties.AllowVirtualNetworkAccess)
d.Set("allow_forwarded_traffic", model.Properties.AllowForwardedTraffic)
d.Set("allow_gateway_transit", model.Properties.AllowGatewayTransit)
d.Set("use_remote_gateways", model.Properties.UseRemoteGateways)

addressSpacePrefixes := make([]string, 0)
if model.Properties.DatabricksAddressSpace != nil && model.Properties.DatabricksAddressSpace.AddressPrefixes != nil {
addressSpacePrefixes = *model.Properties.DatabricksAddressSpace.AddressPrefixes
}
d.Set("address_space_prefixes", addressSpacePrefixes)

remoteAddressSpacePrefixes := make([]string, 0)
if model.Properties.RemoteAddressSpace != nil && model.Properties.RemoteAddressSpace.AddressPrefixes != nil {
remoteAddressSpacePrefixes = *model.Properties.RemoteAddressSpace.AddressPrefixes
}
d.Set("remote_address_space_prefixes", remoteAddressSpacePrefixes)

databricksVirtualNetworkId := ""
if model.Properties.DatabricksVirtualNetwork != nil && model.Properties.DatabricksVirtualNetwork.Id != nil {
databricksVirtualNetworkId = *model.Properties.DatabricksVirtualNetwork.Id
}
d.Set("virtual_network_id", databricksVirtualNetworkId)

remoteVirtualNetworkId := ""
if model.Properties.RemoteVirtualNetwork.Id != nil {
remoteVirtualNetworkId = *model.Properties.RemoteVirtualNetwork.Id
}
d.Set("remote_virtual_network_id", remoteVirtualNetworkId)
}

return nil
}

func resourceDatabricksVirtualNetworkPeeringUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DataBricks.VnetPeeringClient
ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

log.Printf("[INFO] preparing arguments for Azure ARM databricks virtual network peering update.")

id, err := vnetpeering.ParseVirtualNetworkPeeringID(d.Id())
if err != nil {
return err
}

existing, err := client.Get(ctx, *id)
if err != nil {
return fmt.Errorf("retrieving Databricks %s: %+v", *id, err)
}

// these are the only updatable values, so everything else in the existing.Model should still be unchanged...
if d.HasChange("allow_forwarded_traffic") {
existing.Model.Properties.AllowForwardedTraffic = pointer.To(d.Get("allow_forwarded_traffic").(bool))
}

if d.HasChange("allow_gateway_transit") {
existing.Model.Properties.AllowGatewayTransit = pointer.To(d.Get("allow_gateway_transit").(bool))
}

if d.HasChange("allow_virtual_network_access") {
existing.Model.Properties.AllowVirtualNetworkAccess = pointer.To(d.Get("allow_virtual_network_access").(bool))
}

if d.HasChange("use_remote_gateways") {
existing.Model.Properties.UseRemoteGateways = pointer.To(d.Get("use_remote_gateways").(bool))
}

locks.ByID(databricksVnetPeeringsResourceType)
defer locks.UnlockByID(databricksVnetPeeringsResourceType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two lines needs to be moved up to before we make the Get call, else if another Resource modifies the DataBricks cluster we could be undoing that change?

Suggested change
existing, err := client.Get(ctx, *id)
if err != nil {
return fmt.Errorf("retrieving Databricks %s: %+v", *id, err)
}
// these are the only updatable values, so everything else in the existing.Model should still be unchanged...
if d.HasChange("allow_forwarded_traffic") {
existing.Model.Properties.AllowForwardedTraffic = pointer.To(d.Get("allow_forwarded_traffic").(bool))
}
if d.HasChange("allow_gateway_transit") {
existing.Model.Properties.AllowGatewayTransit = pointer.To(d.Get("allow_gateway_transit").(bool))
}
if d.HasChange("allow_virtual_network_access") {
existing.Model.Properties.AllowVirtualNetworkAccess = pointer.To(d.Get("allow_virtual_network_access").(bool))
}
if d.HasChange("use_remote_gateways") {
existing.Model.Properties.UseRemoteGateways = pointer.To(d.Get("use_remote_gateways").(bool))
}
locks.ByID(databricksVnetPeeringsResourceType)
defer locks.UnlockByID(databricksVnetPeeringsResourceType)
locks.ByID(databricksVnetPeeringsResourceType)
defer locks.UnlockByID(databricksVnetPeeringsResourceType)
existing, err := client.Get(ctx, *id)
if err != nil {
return fmt.Errorf("retrieving Databricks %s: %+v", *id, err)
}
// these are the only updatable values, so everything else in the existing.Model should still be unchanged...
if d.HasChange("allow_forwarded_traffic") {
existing.Model.Properties.AllowForwardedTraffic = pointer.To(d.Get("allow_forwarded_traffic").(bool))
}
if d.HasChange("allow_gateway_transit") {
existing.Model.Properties.AllowGatewayTransit = pointer.To(d.Get("allow_gateway_transit").(bool))
}
if d.HasChange("allow_virtual_network_access") {
existing.Model.Properties.AllowVirtualNetworkAccess = pointer.To(d.Get("allow_virtual_network_access").(bool))
}
if d.HasChange("use_remote_gateways") {
existing.Model.Properties.UseRemoteGateways = pointer.To(d.Get("use_remote_gateways").(bool))
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


future, err := client.CreateOrUpdate(ctx, *id, *existing.Model)
if err != nil {
return fmt.Errorf("updating Databricks %s: %+v", *id, err)
}

if err := future.Poller.PollUntilDone(ctx); err != nil {
return fmt.Errorf("waiting for update of Databricks %s: %+v", *id, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor but FYI this can be reduced too:

Suggested change
future, err := client.CreateOrUpdate(ctx, *id, *existing.Model)
if err != nil {
return fmt.Errorf("updating Databricks %s: %+v", *id, err)
}
if err := future.Poller.PollUntilDone(ctx); err != nil {
return fmt.Errorf("waiting for update of Databricks %s: %+v", *id, err)
}
if err := client.CreateOrUpdateThenPoll(ctx, *id, *existing.Model); err != nil {
return fmt.Errorf("updating Databricks %s: %+v", *id, err)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


return resourceDatabricksVirtualNetworkPeeringRead(d, meta)
}

func resourceDatabricksVirtualNetworkPeeringDelete(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DataBricks.VnetPeeringClient
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := vnetpeering.ParseVirtualNetworkPeeringID(d.Id())
if err != nil {
return err
}

// Block all changes to any resource of this type...
locks.ByID(databricksVnetPeeringsResourceType)
defer locks.UnlockByID(databricksVnetPeeringsResourceType)

err = client.DeleteThenPoll(ctx, *id)
if err != nil {
return fmt.Errorf("deleting Databricks %s: %+v", *id, err)
}

return nil
}
Loading