From 98ed5955d758e1a875cbd98ef6d6c30a5d5a1366 Mon Sep 17 00:00:00 2001 From: Wodans Son <20408400+WodansSon@users.noreply.github.com> Date: Thu, 23 Mar 2023 18:17:59 -0600 Subject: [PATCH] [New Resource:] `azurerm_databricks_virtual_network_peering` (#20728) --- internal/services/databricks/client/client.go | 9 + ...bricks_virtual_network_peering_resource.go | 316 ++++++++++++++++++ ...s_virtual_network_peering_resource_test.go | 301 +++++++++++++++++ internal/services/databricks/registration.go | 1 + internal/services/databricks/validate/cidr.go | 21 ++ .../services/databricks/validate/cidr_test.go | 146 ++++++++ ...databricks_virtual_network_peering_name.go | 21 ++ ...ricks_virtual_network_peering_name_test.go | 111 ++++++ .../2023-02-01/vnetpeering/README.md | 82 +++++ .../2023-02-01/vnetpeering/client.go | 26 ++ .../2023-02-01/vnetpeering/constants.go | 71 ++++ .../vnetpeering/id_virtualnetworkpeering.go | 140 ++++++++ .../2023-02-01/vnetpeering/id_workspace.go | 127 +++++++ .../vnetpeering/method_createorupdate.go | 74 ++++ .../2023-02-01/vnetpeering/method_delete.go | 71 ++++ .../2023-02-01/vnetpeering/method_get.go | 52 +++ .../vnetpeering/method_listbyworkspace.go | 89 +++++ .../vnetpeering/model_addressspace.go | 8 + .../model_virtualnetworkpeering.go | 11 + ...l_virtualnetworkpeeringpropertiesformat.go | 17 + ...ropertiesformatdatabricksvirtualnetwork.go | 8 + ...ingpropertiesformatremotevirtualnetwork.go | 8 + .../2023-02-01/vnetpeering/predicates.go | 27 ++ .../2023-02-01/vnetpeering/version.go | 12 + vendor/modules.txt | 1 + ...icks_virtual_network_peering.html.markdown | 107 ++++++ 26 files changed, 1857 insertions(+) create mode 100644 internal/services/databricks/databricks_virtual_network_peering_resource.go create mode 100644 internal/services/databricks/databricks_virtual_network_peering_resource_test.go create mode 100644 internal/services/databricks/validate/cidr.go create mode 100644 internal/services/databricks/validate/cidr_test.go create mode 100644 internal/services/databricks/validate/databricks_virtual_network_peering_name.go create mode 100644 internal/services/databricks/validate/databricks_virtual_network_peering_name_test.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/id_virtualnetworkpeering.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/id_workspace.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_createorupdate.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_delete.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_get.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_listbyworkspace.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_addressspace.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeering.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeeringpropertiesformat.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeeringpropertiesformatdatabricksvirtualnetwork.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeeringpropertiesformatremotevirtualnetwork.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/version.go create mode 100644 website/docs/r/databricks_virtual_network_peering.html.markdown diff --git a/internal/services/databricks/client/client.go b/internal/services/databricks/client/client.go index c613919aac1b..de20f2a89636 100644 --- a/internal/services/databricks/client/client.go +++ b/internal/services/databricks/client/client.go @@ -4,6 +4,7 @@ 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" ) @@ -11,6 +12,7 @@ import ( type Client struct { AccessConnectorClient *accessconnector.AccessConnectorClient WorkspacesClient *workspaces.WorkspacesClient + VnetPeeringClient *vnetpeering.VNetPeeringClient } func NewClient(o *common.ClientOptions) (*Client, error) { @@ -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 } diff --git a/internal/services/databricks/databricks_virtual_network_peering_resource.go b/internal/services/databricks/databricks_virtual_network_peering_resource.go new file mode 100644 index 000000000000..fc8e92f3f791 --- /dev/null +++ b/internal/services/databricks/databricks_virtual_network_peering_resource.go @@ -0,0 +1,316 @@ +package databricks + +import ( + "fmt" + "log" + "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)) + + 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{ + Name: &id.VirtualNetworkPeeringName, + Properties: props, + } + + if err := client.CreateOrUpdateThenPoll(ctx, id, peer); err != nil { + return fmt.Errorf("creating Databricks %s: %+v", id, err) + } + + 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 + } + + 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)) + } + + if err := client.CreateOrUpdateThenPoll(ctx, *id, *existing.Model); err != nil { + return fmt.Errorf("updating Databricks %s: %+v", *id, err) + } + + 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) + + if err := client.DeleteThenPoll(ctx, *id); err != nil { + return fmt.Errorf("deleting Databricks %s: %+v", *id, err) + } + + return nil +} diff --git a/internal/services/databricks/databricks_virtual_network_peering_resource_test.go b/internal/services/databricks/databricks_virtual_network_peering_resource_test.go new file mode 100644 index 000000000000..4e426147f48e --- /dev/null +++ b/internal/services/databricks/databricks_virtual_network_peering_resource_test.go @@ -0,0 +1,301 @@ +package databricks_test + +import ( + "context" + "fmt" + "os" + "testing" + + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type DatabricksVirtualNetworkPeeringResource struct{} + +func TestAccDatabricksVirtualNetworkPeering_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_databricks_virtual_network_peering", "test") + r := DatabricksVirtualNetworkPeeringResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccDatabricksVirtualNetworkPeering_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_databricks_virtual_network_peering", "test") + r := DatabricksVirtualNetworkPeeringResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func TestAccDatabricksVirtualNetworkPeering_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_databricks_virtual_network_peering", "test") + r := DatabricksVirtualNetworkPeeringResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.update(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccDatabricksVirtualNetworkPeering_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_databricks_virtual_network_peering", "test") + r := DatabricksVirtualNetworkPeeringResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccDatabricksVirtualNetworkPeering_completeUpdate(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_databricks_virtual_network_peering", "test") + r := DatabricksVirtualNetworkPeeringResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.completeUpdate(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +// This is needed for subscriptions that have AzSecPack applied on them by policy, +// tests will fail due to NSG's being automatically created for the resources +// without the tests knowledge causing the delete to fail... +func checkAzSecPackOverride() string { + if os.Getenv("ARM_TEST_AZSECPACK_OVERRIDE") != "" { + return (` + resource_group { + prevent_deletion_if_contains_resources = false + } + `) + } + + return "" +} + +func (DatabricksVirtualNetworkPeeringResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := vnetpeering.ParseVirtualNetworkPeeringID(state.ID) + if err != nil { + return nil, err + } + + resp, err := clients.DataBricks.VnetPeeringClient.Get(ctx, *id) + + if response.WasNotFound(resp.HttpResponse) { + return pointer.To(false), nil + } + + if err != nil { + return nil, fmt.Errorf("making Read request on Databricks %s: %+v", *id, err) + } + + return utils.Bool(resp.Model != nil), nil +} + +func (DatabricksVirtualNetworkPeeringResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-databricks-%[1]d" + location = "%[2]s" +} + +resource "azurerm_virtual_network" "remote" { + name = "acctest-vnet-%[1]d" + resource_group_name = azurerm_resource_group.test.name + address_space = ["10.0.1.0/24"] + location = azurerm_resource_group.test.location +} + +resource "azurerm_databricks_workspace" "test" { + name = "acctest-ws-%[1]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + sku = "standard" +} +`, data.RandomInteger, data.Locations.Primary) +} + +func (r DatabricksVirtualNetworkPeeringResource) update(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` +provider "azurerm" { + features {%[3]s} +} + +%[2]s + +resource "azurerm_databricks_virtual_network_peering" "test" { + name = "acctest-%[1]d" + resource_group_name = azurerm_resource_group.test.name + workspace_id = azurerm_databricks_workspace.test.id + + remote_address_space_prefixes = azurerm_virtual_network.remote.address_space + remote_virtual_network_id = azurerm_virtual_network.remote.id + + allow_virtual_network_access = false +} + +resource "azurerm_virtual_network_peering" "remote" { + name = "to-acctest-%[1]d" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.remote.name + remote_virtual_network_id = azurerm_databricks_virtual_network_peering.test.virtual_network_id +} +`, data.RandomInteger, template, checkAzSecPackOverride()) +} + +func (r DatabricksVirtualNetworkPeeringResource) requiresImport(data acceptance.TestData) string { + template := r.basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_databricks_virtual_network_peering" "import" { + name = "acctest-%d" + resource_group_name = azurerm_resource_group.test.name + workspace_id = azurerm_databricks_workspace.test.id + + remote_address_space_prefixes = azurerm_virtual_network.remote.address_space + remote_virtual_network_id = azurerm_virtual_network.remote.id +} +`, template, data.RandomInteger) +} + +func (r DatabricksVirtualNetworkPeeringResource) basic(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` +provider "azurerm" { + features {%[3]s} +} + +%[2]s + +resource "azurerm_databricks_virtual_network_peering" "test" { + name = "acctest-%[1]d" + resource_group_name = azurerm_resource_group.test.name + workspace_id = azurerm_databricks_workspace.test.id + + remote_address_space_prefixes = azurerm_virtual_network.remote.address_space + remote_virtual_network_id = azurerm_virtual_network.remote.id +} + +resource "azurerm_virtual_network_peering" "remote" { + name = "to-acctest-%[1]d" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.remote.name + remote_virtual_network_id = azurerm_databricks_virtual_network_peering.test.virtual_network_id +} +`, data.RandomInteger, template, checkAzSecPackOverride()) +} + +func (r DatabricksVirtualNetworkPeeringResource) complete(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` +provider "azurerm" { + features {%[3]s} +} + +%[2]s + +resource "azurerm_databricks_virtual_network_peering" "test" { + name = "acctest-%[1]d" + resource_group_name = azurerm_resource_group.test.name + workspace_id = azurerm_databricks_workspace.test.id + + remote_address_space_prefixes = azurerm_virtual_network.remote.address_space + remote_virtual_network_id = azurerm_virtual_network.remote.id + + allow_virtual_network_access = true + allow_forwarded_traffic = true + allow_gateway_transit = false + use_remote_gateways = false +} + +resource "azurerm_virtual_network_peering" "remote" { + name = "to-acctest-%[1]d" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.remote.name + remote_virtual_network_id = azurerm_databricks_virtual_network_peering.test.virtual_network_id +} +`, data.RandomInteger, template, checkAzSecPackOverride()) +} + +func (r DatabricksVirtualNetworkPeeringResource) completeUpdate(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` +provider "azurerm" { + features {%[3]s} +} + +%[2]s + +resource "azurerm_databricks_virtual_network_peering" "test" { + name = "acctest-%[1]d" + resource_group_name = azurerm_resource_group.test.name + workspace_id = azurerm_databricks_workspace.test.id + + remote_address_space_prefixes = azurerm_virtual_network.remote.address_space + remote_virtual_network_id = azurerm_virtual_network.remote.id + + allow_virtual_network_access = false + allow_forwarded_traffic = false + allow_gateway_transit = false + use_remote_gateways = false +} + +resource "azurerm_virtual_network_peering" "remote" { + name = "to-acctest-%[1]d" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.remote.name + remote_virtual_network_id = azurerm_databricks_virtual_network_peering.test.virtual_network_id +} +`, data.RandomInteger, template, checkAzSecPackOverride()) +} diff --git a/internal/services/databricks/registration.go b/internal/services/databricks/registration.go index 8be6e6e5f50c..28afe251c366 100644 --- a/internal/services/databricks/registration.go +++ b/internal/services/databricks/registration.go @@ -41,6 +41,7 @@ func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { return map[string]*pluginsdk.Resource{ "azurerm_databricks_workspace": resourceDatabricksWorkspace(), "azurerm_databricks_workspace_customer_managed_key": resourceDatabricksWorkspaceCustomerManagedKey(), + "azurerm_databricks_virtual_network_peering": resourceDatabricksVirtualNetworkPeering(), } } diff --git a/internal/services/databricks/validate/cidr.go b/internal/services/databricks/validate/cidr.go new file mode 100644 index 000000000000..9ff55395948a --- /dev/null +++ b/internal/services/databricks/validate/cidr.go @@ -0,0 +1,21 @@ +package validate + +import ( + "fmt" + "net" +) + +// Evaluates if the passed CIDR is a valid IPv4 or IPv6 CIDR. +func CIDRIsIPv4OrIPv6(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 _, _, err := net.ParseCIDR(v); err != nil { + errors = append(errors, err) + } + + return +} diff --git a/internal/services/databricks/validate/cidr_test.go b/internal/services/databricks/validate/cidr_test.go new file mode 100644 index 000000000000..e465dffd1104 --- /dev/null +++ b/internal/services/databricks/validate/cidr_test.go @@ -0,0 +1,146 @@ +package validate + +import "testing" + +func TestCIDRIsIPv4OrIPv6(t *testing.T) { + cases := []struct { + Input interface{} + Valid bool + }{ + + { + // IPv6 IPv4 literal + Input: "::FFFF:192.168.0.1/24", + Valid: true, + }, + + { + // IPv4 Basic + Input: "192.168.0.1/24", + Valid: true, + }, + + { + // IPv6 basic + Input: "::FFFF:C0A8:1/24", + Valid: true, + }, + + { + // IPv6 compressed + Input: "::FFFF:C0A8:0001/24", + Valid: true, + }, + + { + // IPv6 shortened + Input: "0:0:0:0:0:FFFF:C0A8:1/24", + Valid: true, + }, + + { + // IPv6 shortened lower case + Input: "0:0:0:0:0:ffff:c0a8:1/24", + Valid: true, + }, + + { + // IPv6 expanded + Input: "0000:0000:0000:0000:0000:FFFF:C0A8:1/24", + Valid: true, + }, + + { + // empty + Input: "", + Valid: false, + }, + + { + // not expected type + Input: 192, + Valid: false, + }, + + { + // IPv4 with Port + Input: "192.168.0.1:80/24", + Valid: false, + }, + + { + // IPV4 with missing Port with Port delimiter + Input: "192.168.0.1:/24", + Valid: false, + }, + + { + // IPv4 with invalid port + Input: "192.168.0.1:foo/24", + Valid: false, + }, + + { + // IPv6 basic too many compressed zero octets + Input: ":::FFFF:C0A8:1/24", + Valid: false, + }, + + { + // IPv6 with zone info + Input: "::FFFF:C0A8:1%1/24", + Valid: false, + }, + + { + // IPv6 with invalid zone info + Input: "::FFFF:C0A8:foo%bar/24", + Valid: false, + }, + + { + // IPv6 invalid IPv4 literal + Input: "::FFFF:192.168.0.256/24", + Valid: false, + }, + + { + // IPv6 with port info + Input: "[::FFFF:C0A8:1]:80/24", + Valid: false, + }, + + { + // IPv6 missing port info + Input: "[::FFFF:C0A8:1]:/24", + Valid: false, + }, + + { + // IPv6 with invalid port info + Input: "[::FFFF:C0A8:1]:foo/24", + Valid: false, + }, + + { + // IPv6 with zone and port info + Input: "[::FFFF:C0A8:1%1]:80/24", + Valid: false, + }, + } + + for _, tc := range cases { + _, errors := CIDRIsIPv4OrIPv6(tc.Input, "match_values") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("[DEBUG] Testing Value %s, Expected %t but got %t, Error: %+v", tc.Input, tc.Valid, valid, errors) + } else { + if !valid { + t.Logf("[DEBUG] Testing Value %s, Error: %+v", tc.Input, errors) + } else { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + } + } + } +} diff --git a/internal/services/databricks/validate/databricks_virtual_network_peering_name.go b/internal/services/databricks/validate/databricks_virtual_network_peering_name.go new file mode 100644 index 000000000000..fc5deea50082 --- /dev/null +++ b/internal/services/databricks/validate/databricks_virtual_network_peering_name.go @@ -0,0 +1,21 @@ +package validate + +import ( + "fmt" + + "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" +) + +func DatabricksVirtualNetworkPeeringName(i interface{}, k string) (_ []string, errors []error) { + v, ok := i.(string) + if !ok { + return nil, []error{fmt.Errorf("expected type of %q to be string", k)} + } + + // and must be between 1 and 80 characters in length + if m, _ := validate.RegExHelper(i, k, `^[a-zA-Z\d][a-zA-Z\d._-]{0,78}[a-zA-Z\d_]$`); !m { + return nil, []error{fmt.Errorf(`%q must be between 2 and 80 characters in length, begin with a letter or number, end with a letter, number or underscore, and may contain only letters, numbers, underscores, periods, or hyphens, got %q`, k, v)} + } + + return nil, nil +} diff --git a/internal/services/databricks/validate/databricks_virtual_network_peering_name_test.go b/internal/services/databricks/validate/databricks_virtual_network_peering_name_test.go new file mode 100644 index 000000000000..a541acd665b8 --- /dev/null +++ b/internal/services/databricks/validate/databricks_virtual_network_peering_name_test.go @@ -0,0 +1,111 @@ +package validate + +import "testing" + +func TestDatabricksVirtualNetworkPeeringName(t *testing.T) { + cases := []struct { + Input string + Valid bool + }{ + + { + // empty + Input: "", + Valid: false, + }, + + { + // minimum length + Input: "AA", + Valid: true, + }, + + { + // Valid ending + Input: "Aa", + Valid: true, + }, + + { + // Valid ending + Input: "A9", + Valid: true, + }, + + { + // Valid ending + Input: "A_", + Valid: true, + }, + + { + // maximum length + Input: "AAAAAAAAHHHHHHIIIIIIIIEEEEEEEEAAAAAAAHHHHHHHHHHIIIIIEEEEEEEEEEEEEEEEEEEEEEEEEEEE", + Valid: true, + }, + + { + // too short + Input: "A", + Valid: false, + }, + + { + // too long + Input: "AAAAAAAAHHHHHHIIIIIIIIEEEEEEEEAAAAAAAHHHHHHHHHHIIIIIEEEEEEEEEEEEEEEEEEEEEEEEEEEE_", + Valid: false, + }, + + { + // invalid prefix character + Input: "-AA", + Valid: false, + }, + + { + // invalid prefix character + Input: "_AA", + Valid: false, + }, + + { + // invalid suffix character + Input: "A-", + Valid: false, + }, + + { + // valid prefix character + Input: "1A", + Valid: true, + }, + + { + // valid suffix character + Input: "A1", + Valid: true, + }, + + { + // invalid substring character + Input: "1A*A1", + Valid: false, + }, + + { + // valid substring characters + Input: "1A.-_A1", + Valid: true, + }, + } + + for _, tc := range cases { + t.Logf("[DEBUG] Testing Value %s", tc.Input) + _, errors := DatabricksVirtualNetworkPeeringName(tc.Input, "test") + valid := len(errors) == 0 + + if tc.Valid != valid { + t.Fatalf("Expected %t but got %t", tc.Valid, valid) + } + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/README.md new file mode 100644 index 000000000000..2a781f0e3e5d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/README.md @@ -0,0 +1,82 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering` Documentation + +The `vnetpeering` SDK allows for interaction with the Azure Resource Manager Service `databricks` (API Version `2023-02-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering" +``` + + +### Client Initialization + +```go +client := vnetpeering.NewVNetPeeringClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `VNetPeeringClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := vnetpeering.NewVirtualNetworkPeeringID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "virtualNetworkPeeringValue") + +payload := vnetpeering.VirtualNetworkPeering{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `VNetPeeringClient.Delete` + +```go +ctx := context.TODO() +id := vnetpeering.NewVirtualNetworkPeeringID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "virtualNetworkPeeringValue") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `VNetPeeringClient.Get` + +```go +ctx := context.TODO() +id := vnetpeering.NewVirtualNetworkPeeringID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue", "virtualNetworkPeeringValue") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `VNetPeeringClient.ListByWorkspace` + +```go +ctx := context.TODO() +id := vnetpeering.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "workspaceValue") + +// alternatively `client.ListByWorkspace(ctx, id)` can be used to do batched pagination +items, err := client.ListByWorkspaceComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/client.go new file mode 100644 index 000000000000..3a58116b74f0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/client.go @@ -0,0 +1,26 @@ +package vnetpeering + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VNetPeeringClient struct { + Client *resourcemanager.Client +} + +func NewVNetPeeringClientWithBaseURI(api environments.Api) (*VNetPeeringClient, error) { + client, err := resourcemanager.NewResourceManagerClient(api, "vnetpeering", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating VNetPeeringClient: %+v", err) + } + + return &VNetPeeringClient{ + Client: client, + }, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/constants.go new file mode 100644 index 000000000000..f9d08c31aed4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/constants.go @@ -0,0 +1,71 @@ +package vnetpeering + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PeeringProvisioningState string + +const ( + PeeringProvisioningStateDeleting PeeringProvisioningState = "Deleting" + PeeringProvisioningStateFailed PeeringProvisioningState = "Failed" + PeeringProvisioningStateSucceeded PeeringProvisioningState = "Succeeded" + PeeringProvisioningStateUpdating PeeringProvisioningState = "Updating" +) + +func PossibleValuesForPeeringProvisioningState() []string { + return []string{ + string(PeeringProvisioningStateDeleting), + string(PeeringProvisioningStateFailed), + string(PeeringProvisioningStateSucceeded), + string(PeeringProvisioningStateUpdating), + } +} + +func parsePeeringProvisioningState(input string) (*PeeringProvisioningState, error) { + vals := map[string]PeeringProvisioningState{ + "deleting": PeeringProvisioningStateDeleting, + "failed": PeeringProvisioningStateFailed, + "succeeded": PeeringProvisioningStateSucceeded, + "updating": PeeringProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PeeringProvisioningState(input) + return &out, nil +} + +type PeeringState string + +const ( + PeeringStateConnected PeeringState = "Connected" + PeeringStateDisconnected PeeringState = "Disconnected" + PeeringStateInitiated PeeringState = "Initiated" +) + +func PossibleValuesForPeeringState() []string { + return []string{ + string(PeeringStateConnected), + string(PeeringStateDisconnected), + string(PeeringStateInitiated), + } +} + +func parsePeeringState(input string) (*PeeringState, error) { + vals := map[string]PeeringState{ + "connected": PeeringStateConnected, + "disconnected": PeeringStateDisconnected, + "initiated": PeeringStateInitiated, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PeeringState(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/id_virtualnetworkpeering.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/id_virtualnetworkpeering.go new file mode 100644 index 000000000000..4784a9d21c42 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/id_virtualnetworkpeering.go @@ -0,0 +1,140 @@ +package vnetpeering + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = VirtualNetworkPeeringId{} + +// VirtualNetworkPeeringId is a struct representing the Resource ID for a Virtual Network Peering +type VirtualNetworkPeeringId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string + VirtualNetworkPeeringName string +} + +// NewVirtualNetworkPeeringID returns a new VirtualNetworkPeeringId struct +func NewVirtualNetworkPeeringID(subscriptionId string, resourceGroupName string, workspaceName string, virtualNetworkPeeringName string) VirtualNetworkPeeringId { + return VirtualNetworkPeeringId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + VirtualNetworkPeeringName: virtualNetworkPeeringName, + } +} + +// ParseVirtualNetworkPeeringID parses 'input' into a VirtualNetworkPeeringId +func ParseVirtualNetworkPeeringID(input string) (*VirtualNetworkPeeringId, error) { + parser := resourceids.NewParserFromResourceIdType(VirtualNetworkPeeringId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VirtualNetworkPeeringId{} + + 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 id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + 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 id.VirtualNetworkPeeringName, ok = parsed.Parsed["virtualNetworkPeeringName"]; !ok { + return nil, fmt.Errorf("the segment 'virtualNetworkPeeringName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseVirtualNetworkPeeringIDInsensitively parses 'input' case-insensitively into a VirtualNetworkPeeringId +// note: this method should only be used for API response data and not user input +func ParseVirtualNetworkPeeringIDInsensitively(input string) (*VirtualNetworkPeeringId, error) { + parser := resourceids.NewParserFromResourceIdType(VirtualNetworkPeeringId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := VirtualNetworkPeeringId{} + + 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 id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + 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 id.VirtualNetworkPeeringName, ok = parsed.Parsed["virtualNetworkPeeringName"]; !ok { + return nil, fmt.Errorf("the segment 'virtualNetworkPeeringName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateVirtualNetworkPeeringID checks that 'input' can be parsed as a Virtual Network Peering ID +func ValidateVirtualNetworkPeeringID(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 _, err := ParseVirtualNetworkPeeringID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Virtual Network Peering ID +func (id VirtualNetworkPeeringId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Databricks/workspaces/%s/virtualNetworkPeerings/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName, id.VirtualNetworkPeeringName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Virtual Network Peering ID +func (id VirtualNetworkPeeringId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDatabricks", "Microsoft.Databricks", "Microsoft.Databricks"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + resourceids.StaticSegment("staticVirtualNetworkPeerings", "virtualNetworkPeerings", "virtualNetworkPeerings"), + resourceids.UserSpecifiedSegment("virtualNetworkPeeringName", "virtualNetworkPeeringValue"), + } +} + +// String returns a human-readable description of this Virtual Network Peering ID +func (id VirtualNetworkPeeringId) 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("Virtual Network Peering Name: %q", id.VirtualNetworkPeeringName), + } + return fmt.Sprintf("Virtual Network Peering (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/id_workspace.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/id_workspace.go new file mode 100644 index 000000000000..34114b25b6dd --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/id_workspace.go @@ -0,0 +1,127 @@ +package vnetpeering + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + WorkspaceName string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, workspaceName string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + WorkspaceName: workspaceName, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + 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 id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := WorkspaceId{} + + 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 id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.WorkspaceName, ok = parsed.Parsed["workspaceName"]; !ok { + return nil, fmt.Errorf("the segment 'workspaceName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(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 _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Databricks/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.WorkspaceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDatabricks", "Microsoft.Databricks", "Microsoft.Databricks"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceName", "workspaceValue"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) 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), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_createorupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_createorupdate.go new file mode 100644 index 000000000000..532d5469fa55 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_createorupdate.go @@ -0,0 +1,74 @@ +package vnetpeering + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// CreateOrUpdate ... +func (c VNetPeeringClient) CreateOrUpdate(ctx context.Context, id VirtualNetworkPeeringId, input VirtualNetworkPeering) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c VNetPeeringClient) CreateOrUpdateThenPoll(ctx context.Context, id VirtualNetworkPeeringId, input VirtualNetworkPeering) error { + result, err := c.CreateOrUpdate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_delete.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_delete.go new file mode 100644 index 000000000000..124cc98969c2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_delete.go @@ -0,0 +1,71 @@ +package vnetpeering + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c VNetPeeringClient) Delete(ctx context.Context, id VirtualNetworkPeeringId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c VNetPeeringClient) DeleteThenPoll(ctx context.Context, id VirtualNetworkPeeringId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_get.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_get.go new file mode 100644 index 000000000000..eee2b53bbfa1 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_get.go @@ -0,0 +1,52 @@ +package vnetpeering + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *VirtualNetworkPeering +} + +// Get ... +func (c VNetPeeringClient) Get(ctx context.Context, id VirtualNetworkPeeringId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_listbyworkspace.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_listbyworkspace.go new file mode 100644 index 000000000000..82e7b5a20b67 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/method_listbyworkspace.go @@ -0,0 +1,89 @@ +package vnetpeering + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByWorkspaceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]VirtualNetworkPeering +} + +type ListByWorkspaceCompleteResult struct { + Items []VirtualNetworkPeering +} + +// ListByWorkspace ... +func (c VNetPeeringClient) ListByWorkspace(ctx context.Context, id WorkspaceId) (result ListByWorkspaceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/virtualNetworkPeerings", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]VirtualNetworkPeering `json:"values"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByWorkspaceComplete retrieves all the results into a single object +func (c VNetPeeringClient) ListByWorkspaceComplete(ctx context.Context, id WorkspaceId) (ListByWorkspaceCompleteResult, error) { + return c.ListByWorkspaceCompleteMatchingPredicate(ctx, id, VirtualNetworkPeeringOperationPredicate{}) +} + +// ListByWorkspaceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c VNetPeeringClient) ListByWorkspaceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, predicate VirtualNetworkPeeringOperationPredicate) (result ListByWorkspaceCompleteResult, err error) { + items := make([]VirtualNetworkPeering, 0) + + resp, err := c.ListByWorkspace(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByWorkspaceCompleteResult{ + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_addressspace.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_addressspace.go new file mode 100644 index 000000000000..a0274d74e9ca --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_addressspace.go @@ -0,0 +1,8 @@ +package vnetpeering + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AddressSpace struct { + AddressPrefixes *[]string `json:"addressPrefixes,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeering.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeering.go new file mode 100644 index 000000000000..dfb944877713 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeering.go @@ -0,0 +1,11 @@ +package vnetpeering + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkPeering struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties VirtualNetworkPeeringPropertiesFormat `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeeringpropertiesformat.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeeringpropertiesformat.go new file mode 100644 index 000000000000..3be4e60e0be6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeeringpropertiesformat.go @@ -0,0 +1,17 @@ +package vnetpeering + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkPeeringPropertiesFormat struct { + AllowForwardedTraffic *bool `json:"allowForwardedTraffic,omitempty"` + AllowGatewayTransit *bool `json:"allowGatewayTransit,omitempty"` + AllowVirtualNetworkAccess *bool `json:"allowVirtualNetworkAccess,omitempty"` + DatabricksAddressSpace *AddressSpace `json:"databricksAddressSpace,omitempty"` + DatabricksVirtualNetwork *VirtualNetworkPeeringPropertiesFormatDatabricksVirtualNetwork `json:"databricksVirtualNetwork,omitempty"` + PeeringState *PeeringState `json:"peeringState,omitempty"` + ProvisioningState *PeeringProvisioningState `json:"provisioningState,omitempty"` + RemoteAddressSpace *AddressSpace `json:"remoteAddressSpace,omitempty"` + RemoteVirtualNetwork VirtualNetworkPeeringPropertiesFormatRemoteVirtualNetwork `json:"remoteVirtualNetwork"` + UseRemoteGateways *bool `json:"useRemoteGateways,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeeringpropertiesformatdatabricksvirtualnetwork.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeeringpropertiesformatdatabricksvirtualnetwork.go new file mode 100644 index 000000000000..a9cd8bd10ff6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeeringpropertiesformatdatabricksvirtualnetwork.go @@ -0,0 +1,8 @@ +package vnetpeering + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkPeeringPropertiesFormatDatabricksVirtualNetwork struct { + Id *string `json:"id,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeeringpropertiesformatremotevirtualnetwork.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeeringpropertiesformatremotevirtualnetwork.go new file mode 100644 index 000000000000..117a1334c299 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/model_virtualnetworkpeeringpropertiesformatremotevirtualnetwork.go @@ -0,0 +1,8 @@ +package vnetpeering + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkPeeringPropertiesFormatRemoteVirtualNetwork struct { + Id *string `json:"id,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/predicates.go new file mode 100644 index 000000000000..ac584153d308 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/predicates.go @@ -0,0 +1,27 @@ +package vnetpeering + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type VirtualNetworkPeeringOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p VirtualNetworkPeeringOperationPredicate) Matches(input VirtualNetworkPeering) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/version.go new file mode 100644 index 000000000000..1d9a4d8e1b22 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2023-02-01/vnetpeering/version.go @@ -0,0 +1,12 @@ +package vnetpeering + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2023-02-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/vnetpeering/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 39a164b61a49..976e0e718499 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -252,6 +252,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/databoxedge/2020-12-01/device github.com/hashicorp/go-azure-sdk/resource-manager/databoxedge/2020-12-01/orders github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2022-04-01-preview/accessconnector github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2022-04-01-preview/workspaces +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/go-azure-sdk/resource-manager/datadog/2021-03-01 github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2021-03-01/agreements diff --git a/website/docs/r/databricks_virtual_network_peering.html.markdown b/website/docs/r/databricks_virtual_network_peering.html.markdown new file mode 100644 index 000000000000..0fbc361b4728 --- /dev/null +++ b/website/docs/r/databricks_virtual_network_peering.html.markdown @@ -0,0 +1,107 @@ +--- +subcategory: "Databricks" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_databricks_virtual_network_peering" +description: |- + Manages a Databricks Virtual Network Peering +--- + +# azurerm_databricks_virtual_network_peering + +Manages a Databricks Virtual Network Peering + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_virtual_network" "remote" { + name = "remote-vnet" + resource_group_name = azurerm_resource_group.example.name + address_space = ["10.0.1.0/24"] + location = azurerm_resource_group.example.location +} + +resource "azurerm_databricks_workspace" "example" { + name = "example-workspace" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + sku = "standard" +} + +resource "azurerm_databricks_virtual_network_peering" "example" { + name = "databricks-vnet-peer" + resource_group_name = azurerm_resource_group.example.name + workspace_id = azurerm_databricks_workspace.example.id + + remote_address_space_prefixes = azurerm_virtual_network.remote.address_space + remote_virtual_network_id = azurerm_virtual_network.remote.id + allow_virtual_network_access = true +} + +resource "azurerm_virtual_network_peering" "remote" { + name = "peer-to-databricks" + resource_group_name = azurerm_resource_group.example.name + virtual_network_name = azurerm_virtual_network.remote.name + remote_virtual_network_id = azurerm_databricks_virtual_network_peering.example.virtual_network_id + allow_virtual_network_access = true +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the Databricks Virtual Network Peering resource. Changing this forces a new resource to be created. + +* `resource_group_name` - (Required) The name of the Resource Group in which the Databricks Virtual Network Peering should exist. Changing this forces a new resource to be created. + +* `workspace_id` - (Required) The ID of the Databricks Workspace that this Databricks Virtual Network Peering is bound. Changing this forces a new resource to be created. + +* `address_space_prefixes` - (Required) A list of address blocks reserved for this virtual network in CIDR notation. Changing this forces a new resource to be created. + +* `remote_address_space_prefixes` - (Required) A list of address blocks reserved for the remote virtual network in CIDR notation. Changing this forces a new resource to be created. + +* `remote_virtual_network_id` - (Required) The ID of the remote virtual network. Changing this forces a new resource to be created. + +~> **NOTE:** The remote virtual network should be in the same region as the databricks workspace. Please see the [product documentation](https://learn.microsoft.com/azure/databricks/administration-guide/cloud-configurations/azure/vnet-peering) for more information. + +* `allow_virtual_network_access` - (Optional) Can the VMs in the local virtual network space access the VMs in the remote virtual network space? Defaults to `true`. + +* `allow_forwarded_traffic` - (Optional) Can the forwarded traffic from the VMs in the local virtual network be forwarded to the remote virtual network? Defaults to `false`. + +* `allow_gateway_transit` - (Optional) Can the gateway links be used in the remote virtual network to link to the Databricks virtual network? Defaults to `false`. + +* `use_remote_gateways` - (Optional) Can remote gateways be used on the Databricks virtual network? Defaults to `false`. + +~> **NOTE:** If the `use_remote_gateways` is set to `true`, and `allow_gateway_transit` on the remote peering is also `true`, the virtual network will use the gateways of the remote virtual network for transit. Only one peering can have this flag set to `true`. `use_remote_gateways` cannot be set if the virtual network already has a gateway. + +* `virtual_network_id` - The ID of the internal Virtual Network used by the DataBricks Workspace. + +~> **NOTE:** The `virtual_network_id` field is the value you must supply to the `azurerm_virtual_network_peering` resources `remote_virtual_network_id` field to successfully peer the Databricks Virtual Network with the remote virtual network. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Databricks Virtual Network Peering. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the Databricks Virtual Network Peering. +* `update` - (Defaults to 30 minutes) Used when updating the Databricks Virtual Network Peering. +* `read` - (Defaults to 5 minutes) Used when retrieving the Databricks Virtual Network Peering. +* `delete` - (Defaults to 30 minutes) Used when deleting the Databricks Virtual Network Peering. + +## Import + +Databrick Virtual Network Peerings can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_databricks_virtual_network_peering.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Databricks/workspaces/workspace1/virtualNetworkPeerings/peering1 +```