diff --git a/sdk/resourcemanager/databricks/armdatabricks/assets.json b/sdk/resourcemanager/databricks/armdatabricks/assets.json new file mode 100644 index 000000000000..890f005a8bbe --- /dev/null +++ b/sdk/resourcemanager/databricks/armdatabricks/assets.json @@ -0,0 +1,6 @@ +{ + "AssetsRepo": "Azure/azure-sdk-assets", + "AssetsRepoPrefixPath": "go", + "TagPrefix": "go/resourcemanager/databricks/armdatabricks", + "Tag": "go/resourcemanager/databricks/armdatabricks_4a2f7eab0e" +} diff --git a/sdk/resourcemanager/databricks/armdatabricks/databricks_live_test.go b/sdk/resourcemanager/databricks/armdatabricks/databricks_live_test.go new file mode 100644 index 000000000000..f4d9977fa8b7 --- /dev/null +++ b/sdk/resourcemanager/databricks/armdatabricks/databricks_live_test.go @@ -0,0 +1,457 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +package armdatabricks_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/databricks/armdatabricks" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "github.com/stretchr/testify/suite" +) + +type DatabricksTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + managedResourceGroupName string + peeringName string + virtaulNetworkId string + workspaceId string + workspaceName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *DatabricksTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/databricks/armdatabricks/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.managedResourceGroupName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "managedrg", 15, false) + testsuite.peeringName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "peeringn", 14, false) + testsuite.workspaceName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "workspac", 14, false) + testsuite.location = testutil.GetEnv("LOCATION", "westus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name + testsuite.Prepare() +} + +func (testsuite *DatabricksTestSuite) TearDownSuite() { + testsuite.Cleanup() + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestDatabricksTestSuite(t *testing.T) { + suite.Run(t, new(DatabricksTestSuite)) +} + +func (testsuite *DatabricksTestSuite) Prepare() { + var err error + // From step Create_VirtualNetwork + template := map[string]any{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "outputs": map[string]any{ + "virtaulNetworkId": map[string]any{ + "type": "string", + "value": "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworksName'))]", + }, + }, + "parameters": map[string]any{ + "location": map[string]any{ + "type": "string", + "defaultValue": testsuite.location, + }, + "networkSecurityGroupName": map[string]any{ + "type": "string", + "defaultValue": "databricks-nsg", + }, + "virtualNetworksName": map[string]any{ + "type": "string", + "defaultValue": "databricksvnet2", + }, + }, + "resources": []any{ + map[string]any{ + "name": "[parameters('networkSecurityGroupName')]", + "type": "Microsoft.Network/networkSecurityGroups", + "apiVersion": "2022-11-01", + "location": "[parameters('location')]", + }, + map[string]any{ + "name": "[parameters('virtualNetworksName')]", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2021-05-01", + "dependsOn": []any{ + "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]", + }, + "location": "[parameters('location')]", + "properties": map[string]any{ + "addressSpace": map[string]any{ + "addressPrefixes": []any{ + "10.0.0.0/16", + }, + }, + "subnets": []any{ + map[string]any{ + "name": "default", + "properties": map[string]any{ + "addressPrefix": "10.0.0.0/24", + }, + }, + map[string]any{ + "name": "myPublicSubnet", + "properties": map[string]any{ + "addressPrefix": "10.0.1.0/24", + "delegations": []any{ + map[string]any{ + "name": "Microsoft.Databricks.workspaces", + "type": "Microsoft.Network/virtualNetworks/subnets/delegations", + "properties": map[string]any{ + "serviceName": "Microsoft.Databricks/workspaces", + }, + }, + }, + "networkSecurityGroup": map[string]any{ + "id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]", + }, + }, + }, + map[string]any{ + "name": "myPrivateSubnet", + "properties": map[string]any{ + "addressPrefix": "10.0.2.0/24", + "delegations": []any{ + map[string]any{ + "name": "Microsoft.Databricks.workspaces", + "type": "Microsoft.Network/virtualNetworks/subnets/delegations", + "properties": map[string]any{ + "serviceName": "Microsoft.Databricks/workspaces", + }, + }, + }, + "networkSecurityGroup": map[string]any{ + "id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroupName'))]", + }, + }, + }, + }, + }, + "tags": map[string]any{}, + }, + }, + } + deployment := armresources.Deployment{ + Properties: &armresources.DeploymentProperties{ + Template: template, + Mode: to.Ptr(armresources.DeploymentModeIncremental), + }, + } + deploymentExtend, err := testutil.CreateDeployment(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName, "Create_VirtualNetwork", &deployment) + testsuite.Require().NoError(err) + testsuite.virtaulNetworkId = deploymentExtend.Properties.Outputs.(map[string]interface{})["virtaulNetworkId"].(map[string]interface{})["value"].(string) + + // From step Workspaces_CreateOrUpdate + fmt.Println("Call operation: Workspaces_CreateOrUpdate") + workspacesClient, err := armdatabricks.NewWorkspacesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + workspacesClientCreateOrUpdateResponsePoller, err := workspacesClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.workspaceName, armdatabricks.Workspace{ + Location: to.Ptr(testsuite.location), + Properties: &armdatabricks.WorkspaceProperties{ + ManagedResourceGroupID: to.Ptr("/subscriptions/" + testsuite.subscriptionId + "/resourceGroups/" + testsuite.managedResourceGroupName), + Parameters: &armdatabricks.WorkspaceCustomParameters{ + CustomPrivateSubnetName: &armdatabricks.WorkspaceCustomStringParameter{ + Value: to.Ptr("myPrivateSubnet"), + }, + CustomPublicSubnetName: &armdatabricks.WorkspaceCustomStringParameter{ + Value: to.Ptr("myPublicSubnet"), + }, + CustomVirtualNetworkID: &armdatabricks.WorkspaceCustomStringParameter{ + Value: to.Ptr(testsuite.virtaulNetworkId), + }, + }, + }, + SKU: &armdatabricks.SKU{ + Name: to.Ptr("premium"), + }, + }, nil) + testsuite.Require().NoError(err) + var workspacesClientCreateOrUpdateResponse *armdatabricks.WorkspacesClientCreateOrUpdateResponse + workspacesClientCreateOrUpdateResponse, err = testutil.PollForTest(testsuite.ctx, workspacesClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + testsuite.workspaceId = *workspacesClientCreateOrUpdateResponse.ID + + // From step Create_PrivateEndpoint + template = map[string]any{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": map[string]any{ + "location": map[string]any{ + "type": "string", + "defaultValue": testsuite.location, + }, + "networkInterfaceName": map[string]any{ + "type": "string", + "defaultValue": "endpointdatabricks-nic", + }, + "privateEndpointName": map[string]any{ + "type": "string", + "defaultValue": "endpointdatabricks", + }, + "virtualNetworksName": map[string]any{ + "type": "string", + "defaultValue": "endpointvnet", + }, + "workspaceId": map[string]any{ + "type": "string", + "defaultValue": testsuite.workspaceId, + }, + }, + "resources": []any{ + map[string]any{ + "name": "[parameters('virtualNetworksName')]", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2020-11-01", + "location": "[parameters('location')]", + "properties": map[string]any{ + "addressSpace": map[string]any{ + "addressPrefixes": []any{ + "10.0.0.0/16", + }, + }, + "enableDdosProtection": false, + "subnets": []any{ + map[string]any{ + "name": "pesubnet", + "properties": map[string]any{ + "addressPrefix": "10.0.3.0/24", + "delegations": []any{}, + "privateEndpointNetworkPolicies": "Disabled", + "privateLinkServiceNetworkPolicies": "Enabled", + }, + }, + }, + "virtualNetworkPeerings": []any{}, + }, + }, + map[string]any{ + "name": "[parameters('networkInterfaceName')]", + "type": "Microsoft.Network/networkInterfaces", + "apiVersion": "2020-11-01", + "dependsOn": []any{ + "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'pesubnet')]", + }, + "location": "[parameters('location')]", + "properties": map[string]any{ + "dnsSettings": map[string]any{ + "dnsServers": []any{}, + }, + "enableIPForwarding": false, + "ipConfigurations": []any{ + map[string]any{ + "name": "privateEndpointIpConfig", + "properties": map[string]any{ + "primary": true, + "privateIPAddress": "10.0.0.4", + "privateIPAddressVersion": "IPv4", + "privateIPAllocationMethod": "Dynamic", + "subnet": map[string]any{ + "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'pesubnet')]", + }, + }, + }, + }, + }, + }, + map[string]any{ + "name": "[parameters('privateEndpointName')]", + "type": "Microsoft.Network/privateEndpoints", + "apiVersion": "2020-11-01", + "dependsOn": []any{ + "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'pesubnet')]", + }, + "location": "[parameters('location')]", + "properties": map[string]any{ + "customDnsConfigs": []any{}, + "manualPrivateLinkServiceConnections": []any{}, + "privateLinkServiceConnections": []any{ + map[string]any{ + "name": "[parameters('privateEndpointName')]", + "properties": map[string]any{ + "groupIds": []any{ + "databricks_ui_api", + }, + "privateLinkServiceConnectionState": map[string]any{ + "description": "Auto-Approved", + "actionsRequired": "None", + "status": "Approved", + }, + "privateLinkServiceId": "[parameters('workspaceId')]", + }, + }, + }, + "subnet": map[string]any{ + "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'pesubnet')]", + }, + }, + }, + map[string]any{ + "name": "[concat(parameters('virtualNetworksName'), '/pesubnet')]", + "type": "Microsoft.Network/virtualNetworks/subnets", + "apiVersion": "2020-11-01", + "dependsOn": []any{ + "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworksName'))]", + }, + "properties": map[string]any{ + "addressPrefix": "10.0.3.0/24", + "delegations": []any{}, + "privateEndpointNetworkPolicies": "Disabled", + "privateLinkServiceNetworkPolicies": "Enabled", + }, + }, + }, + "variables": map[string]any{}, + } + deployment = armresources.Deployment{ + Properties: &armresources.DeploymentProperties{ + Template: template, + Mode: to.Ptr(armresources.DeploymentModeIncremental), + }, + } + _, err = testutil.CreateDeployment(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName, "Create_PrivateEndpoint", &deployment) + testsuite.Require().NoError(err) +} + +// Microsoft.Databricks/workspaces/{workspaceName} +func (testsuite *DatabricksTestSuite) TestWorkspaces() { + var err error + // From step Workspaces_ListByResourceGroup + fmt.Println("Call operation: Workspaces_ListByResourceGroup") + workspacesClient, err := armdatabricks.NewWorkspacesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + workspacesClientNewListByResourceGroupPager := workspacesClient.NewListByResourceGroupPager(testsuite.resourceGroupName, nil) + for workspacesClientNewListByResourceGroupPager.More() { + _, err := workspacesClientNewListByResourceGroupPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step Workspaces_Get + fmt.Println("Call operation: Workspaces_Get") + _, err = workspacesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.workspaceName, nil) + testsuite.Require().NoError(err) + + // From step Workspaces_Update + fmt.Println("Call operation: Workspaces_Update") + workspacesClientUpdateResponsePoller, err := workspacesClient.BeginUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.workspaceName, armdatabricks.WorkspaceUpdate{ + Tags: map[string]*string{ + "mytag1": to.Ptr("myvalue1"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, workspacesClientUpdateResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.Databricks/workspaces/{workspaceName}/privateEndpointConnections/{privateEndpointConnectionName} +func (testsuite *DatabricksTestSuite) TestPrivateEndpointConnections() { + var privateEndpointConnectionName string + var err error + // From step PrivateEndpointConnections_List + fmt.Println("Call operation: PrivateEndpointConnections_List") + privateEndpointConnectionsClient, err := armdatabricks.NewPrivateEndpointConnectionsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + privateEndpointConnectionsClientNewListPager := privateEndpointConnectionsClient.NewListPager(testsuite.resourceGroupName, testsuite.workspaceName, nil) + for privateEndpointConnectionsClientNewListPager.More() { + nextResult, err := privateEndpointConnectionsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + + privateEndpointConnectionName = *nextResult.Value[0].Name + break + } + + // From step PrivateEndpointConnections_Create + fmt.Println("Call operation: PrivateEndpointConnections_Create") + privateEndpointConnectionsClientCreateResponsePoller, err := privateEndpointConnectionsClient.BeginCreate(testsuite.ctx, testsuite.resourceGroupName, testsuite.workspaceName, privateEndpointConnectionName, armdatabricks.PrivateEndpointConnection{ + Properties: &armdatabricks.PrivateEndpointConnectionProperties{ + PrivateLinkServiceConnectionState: &armdatabricks.PrivateLinkServiceConnectionState{ + Description: to.Ptr("Approved by databricksadmin@contoso.com"), + Status: to.Ptr(armdatabricks.PrivateLinkServiceConnectionStatusRejected), + }, + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, privateEndpointConnectionsClientCreateResponsePoller) + testsuite.Require().NoError(err) + + // From step PrivateEndpointConnections_Get + fmt.Println("Call operation: PrivateEndpointConnections_Get") + _, err = privateEndpointConnectionsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.workspaceName, privateEndpointConnectionName, nil) + testsuite.Require().NoError(err) + + // From step PrivateLinkResources_List + fmt.Println("Call operation: PrivateLinkResources_List") + privateLinkResourcesClient, err := armdatabricks.NewPrivateLinkResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + privateLinkResourcesClientNewListPager := privateLinkResourcesClient.NewListPager(testsuite.resourceGroupName, testsuite.workspaceName, nil) + for privateLinkResourcesClientNewListPager.More() { + _, err := privateLinkResourcesClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step PrivateLinkResources_Get + fmt.Println("Call operation: PrivateLinkResources_Get") + _, err = privateLinkResourcesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.workspaceName, "databricks_ui_api", nil) + testsuite.Require().NoError(err) + + // From step PrivateEndpointConnections_Delete + fmt.Println("Call operation: PrivateEndpointConnections_Delete") + privateEndpointConnectionsClientDeleteResponsePoller, err := privateEndpointConnectionsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.workspaceName, privateEndpointConnectionName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, privateEndpointConnectionsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.Databricks/workspaces/{workspaceName}/outboundNetworkDependenciesEndpoints +func (testsuite *DatabricksTestSuite) TestOutboundNetworkDependenciesEndpoints() { + var err error + // From step OutboundNetworkDependenciesEndpoints_List + fmt.Println("Call operation: OutboundNetworkDependenciesEndpoints_List") + outboundNetworkDependenciesEndpointsClient, err := armdatabricks.NewOutboundNetworkDependenciesEndpointsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + _, err = outboundNetworkDependenciesEndpointsClient.List(testsuite.ctx, testsuite.resourceGroupName, testsuite.workspaceName, nil) + testsuite.Require().NoError(err) +} + +func (testsuite *DatabricksTestSuite) Cleanup() { + var err error + // From step Workspaces_Delete + fmt.Println("Call operation: Workspaces_Delete") + workspacesClient, err := armdatabricks.NewWorkspacesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + workspacesClientDeleteResponsePoller, err := workspacesClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.workspaceName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, workspacesClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/databricks/armdatabricks/go.mod b/sdk/resourcemanager/databricks/armdatabricks/go.mod index 21c30edc148c..e77ed7b4ad19 100644 --- a/sdk/resourcemanager/databricks/armdatabricks/go.mod +++ b/sdk/resourcemanager/databricks/armdatabricks/go.mod @@ -5,17 +5,25 @@ go 1.18 require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 + github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 + github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 + github.com/stretchr/testify v1.7.0 ) require ( - github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 // indirect github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dnaeon/go-vcr v1.1.0 // indirect github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/google/uuid v1.3.0 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect golang.org/x/crypto v0.6.0 // indirect golang.org/x/net v0.7.0 // indirect golang.org/x/sys v0.5.0 // indirect golang.org/x/text v0.7.0 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/sdk/resourcemanager/databricks/armdatabricks/go.sum b/sdk/resourcemanager/databricks/armdatabricks/go.sum index 8ba445a8c4da..9e67f59f4a17 100644 --- a/sdk/resourcemanager/databricks/armdatabricks/go.sum +++ b/sdk/resourcemanager/databricks/armdatabricks/go.sum @@ -4,20 +4,32 @@ github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2 h1:uqM+VoHjVH6zdlkLF2b6O github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.2/go.mod h1:twTKAa1E6hLmSDjLhaCkbTMQKc7p/rNLU40rLxGEOCI= github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 h1:leh5DwKv6Ihwi+h60uHtn6UWAxBbZ0q8DwQVMzf61zw= github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2 h1:mLY+pNLjCUeKhgnAJWAKhEUQM+RJQo2H1fuGSw1Ky1E= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal v1.1.2/go.mod h1:FbdwsQ2EzwvXxOPcMFYO8ogEc9uMMIj3YkmCdXdAFmk= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/managementgroups/armmanagementgroups v1.0.0 h1:pPvTJ1dY0sA35JOeFq6TsY2xj6Z85Yo23Pj4wCCvu4o= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1 h1:7CBQ+Ei8SP2c6ydQTGCCrS35bDxgTMfoP2miAwK++OU= +github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.1.1/go.mod h1:c/wcGeGx5FUPbM/JltUYHZcKmigwyVLJlDq+4HdtXaw= github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0 h1:UE9n9rkJF62ArLb1F3DEjRt8O3jLwMWdSoypKV4f3MU= github.com/AzureAD/microsoft-authentication-library-for-go v0.9.0/go.mod h1:kgDmCTgBzIEPFElEF+FK0SdjAor06dRq2Go927dnQ6o= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c= +github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko= github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= @@ -27,5 +39,11 @@ golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/sdk/resourcemanager/databricks/armdatabricks/vnetpeering_live_test.go b/sdk/resourcemanager/databricks/armdatabricks/vnetpeering_live_test.go new file mode 100644 index 000000000000..41ca0549bb25 --- /dev/null +++ b/sdk/resourcemanager/databricks/armdatabricks/vnetpeering_live_test.go @@ -0,0 +1,178 @@ +//go:build go1.18 +// +build go1.18 + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +package armdatabricks_test + +import ( + "context" + "fmt" + "testing" + + "github.com/Azure/azure-sdk-for-go/sdk/azcore" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" + "github.com/Azure/azure-sdk-for-go/sdk/internal/recording" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/databricks/armdatabricks" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "github.com/stretchr/testify/suite" +) + +type VnetpeeringTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + peeringName string + virtaulNetworkId string + workspaceName string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *VnetpeeringTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/databricks/armdatabricks/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.peeringName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "peeringn", 14, false) + testsuite.workspaceName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "workspac", 14, false) + testsuite.location = testutil.GetEnv("LOCATION", "westus") + testsuite.resourceGroupName = testutil.GetEnv("RESOURCE_GROUP_NAME", "scenarioTestTempGroup") + testsuite.subscriptionId = testutil.GetEnv("AZURE_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000") + resourceGroup, _, err := testutil.CreateResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.location) + testsuite.Require().NoError(err) + testsuite.resourceGroupName = *resourceGroup.Name + testsuite.Prepare() +} + +func (testsuite *VnetpeeringTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestVnetpeeringTestSuite(t *testing.T) { + suite.Run(t, new(VnetpeeringTestSuite)) +} + +func (testsuite *VnetpeeringTestSuite) Prepare() { + var err error + // From step Workspaces_CreateOrUpdate + fmt.Println("Call operation: Workspaces_CreateOrUpdate") + workspacesClient, err := armdatabricks.NewWorkspacesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + workspacesClientCreateOrUpdateResponsePoller, err := workspacesClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.workspaceName, armdatabricks.Workspace{ + Location: to.Ptr(testsuite.location), + Properties: &armdatabricks.WorkspaceProperties{ + ManagedResourceGroupID: to.Ptr("/subscriptions/" + testsuite.subscriptionId + "/resourceGroups/myManaged" + testsuite.resourceGroupName), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, workspacesClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step Create_VirtualNetwork + template := map[string]any{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "outputs": map[string]any{ + "virtaulNetworkId": map[string]any{ + "type": "string", + "value": "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworksName'))]", + }, + }, + "parameters": map[string]any{ + "location": map[string]any{ + "type": "string", + "defaultValue": testsuite.location, + }, + "virtualNetworksName": map[string]any{ + "type": "string", + "defaultValue": "databricksvnet", + }, + }, + "resources": []any{ + map[string]any{ + "name": "[parameters('virtualNetworksName')]", + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2021-05-01", + "location": "[parameters('location')]", + "properties": map[string]any{ + "addressSpace": map[string]any{ + "addressPrefixes": []any{ + "10.0.0.0/16", + }, + }, + "subnets": []any{ + map[string]any{ + "name": "default", + "properties": map[string]any{ + "addressPrefix": "10.0.0.0/24", + }, + }, + }, + }, + "tags": map[string]any{}, + }, + }, + } + deployment := armresources.Deployment{ + Properties: &armresources.DeploymentProperties{ + Template: template, + Mode: to.Ptr(armresources.DeploymentModeIncremental), + }, + } + deploymentExtend, err := testutil.CreateDeployment(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName, "Create_VirtualNetwork", &deployment) + testsuite.Require().NoError(err) + testsuite.virtaulNetworkId = deploymentExtend.Properties.Outputs.(map[string]interface{})["virtaulNetworkId"].(map[string]interface{})["value"].(string) +} + +// Microsoft.Databricks/workspaces/{workspaceName}/virtualNetworkPeerings/{peeringName} +func (testsuite *VnetpeeringTestSuite) TestVNetPeering() { + var err error + // From step vNetPeering_CreateOrUpdate + fmt.Println("Call operation: vNetPeering_CreateOrUpdate") + vNetPeeringClient, err := armdatabricks.NewVNetPeeringClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + vNetPeeringClientCreateOrUpdateResponsePoller, err := vNetPeeringClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.workspaceName, testsuite.peeringName, armdatabricks.VirtualNetworkPeering{ + Properties: &armdatabricks.VirtualNetworkPeeringPropertiesFormat{ + AllowForwardedTraffic: to.Ptr(false), + AllowGatewayTransit: to.Ptr(false), + AllowVirtualNetworkAccess: to.Ptr(true), + RemoteVirtualNetwork: &armdatabricks.VirtualNetworkPeeringPropertiesFormatRemoteVirtualNetwork{ + ID: to.Ptr(testsuite.virtaulNetworkId), + }, + UseRemoteGateways: to.Ptr(false), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, vNetPeeringClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step vNetPeering_ListByWorkspace + fmt.Println("Call operation: vNetPeering_ListByWorkspace") + vNetPeeringClientNewListByWorkspacePager := vNetPeeringClient.NewListByWorkspacePager(testsuite.resourceGroupName, testsuite.workspaceName, nil) + for vNetPeeringClientNewListByWorkspacePager.More() { + _, err := vNetPeeringClientNewListByWorkspacePager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step vNetPeering_Get + fmt.Println("Call operation: vNetPeering_Get") + _, err = vNetPeeringClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.workspaceName, testsuite.peeringName, nil) + testsuite.Require().NoError(err) + + // From step vNetPeering_Delete + fmt.Println("Call operation: vNetPeering_Delete") + vNetPeeringClientDeleteResponsePoller, err := vNetPeeringClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.workspaceName, testsuite.peeringName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, vNetPeeringClientDeleteResponsePoller) + testsuite.Require().NoError(err) +}