diff --git a/sdk/resourcemanager/postgresql/armpostgresql/assets.json b/sdk/resourcemanager/postgresql/armpostgresql/assets.json index 0a673e5602dd..c7e1e87d6349 100644 --- a/sdk/resourcemanager/postgresql/armpostgresql/assets.json +++ b/sdk/resourcemanager/postgresql/armpostgresql/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "go", "TagPrefix": "go/resourcemanager/postgresql/armpostgresql", - "Tag": "go/resourcemanager/postgresql/armpostgresql_d9bc2d0da1" + "Tag": "go/resourcemanager/postgresql/armpostgresql_2a306718c0" } diff --git a/sdk/resourcemanager/postgresql/armpostgresql/postgresql_live_test.go b/sdk/resourcemanager/postgresql/armpostgresql/postgresql_live_test.go index 7bf657fd16b5..64c3c42c4a63 100644 --- a/sdk/resourcemanager/postgresql/armpostgresql/postgresql_live_test.go +++ b/sdk/resourcemanager/postgresql/armpostgresql/postgresql_live_test.go @@ -14,6 +14,7 @@ import ( "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/internal/testutil" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/postgresql/armpostgresql" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" @@ -35,14 +36,14 @@ type PostgresqlTestSuite struct { func (testsuite *PostgresqlTestSuite) SetupSuite() { testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/postgresql/armpostgresql/testdata") + testsuite.ctx = context.Background() testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) - testsuite.serverName = testutil.GenerateAlphaNumericID(testsuite.T(), "pgservers", 6) - testsuite.adminPassword = testutil.GetEnv("ADMIN_PASSWORD", "000000000000") - testsuite.location = testutil.GetEnv("LOCATION", "eastus") + testsuite.serverName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "serverna", 14, true) + testsuite.adminPassword = testutil.GetEnv("ADMIN_PASSWORD", "") + 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 @@ -81,8 +82,8 @@ func (testsuite *PostgresqlTestSuite) Prepare() { AdministratorLoginPassword: to.Ptr(testsuite.adminPassword), }, SKU: &armpostgresql.SKU{ - Family: to.Ptr("Gen5"), Name: to.Ptr("GP_Gen5_8"), + Family: to.Ptr("Gen5"), Tier: to.Ptr(armpostgresql.SKUTierGeneralPurpose), }, Tags: map[string]*string{ @@ -94,7 +95,7 @@ func (testsuite *PostgresqlTestSuite) Prepare() { testsuite.Require().NoError(err) } -// Microsoft.DBforPostgreSQL/servers +// Microsoft.DBforPostgreSQL/servers/{serverName} func (testsuite *PostgresqlTestSuite) TestServers() { var err error // From step Servers_List @@ -143,23 +144,8 @@ func (testsuite *PostgresqlTestSuite) TestServers() { testsuite.Require().NoError(err) } -// Microsoft.DBforPostgreSQL/servers/replicas -func (testsuite *PostgresqlTestSuite) TestReplicas() { - var err error - // From step Replicas_ListByServer - fmt.Println("Call operation: Replicas_ListByServer") - replicasClient, err := armpostgresql.NewReplicasClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) - testsuite.Require().NoError(err) - replicasClientNewListByServerPager := replicasClient.NewListByServerPager(testsuite.resourceGroupName, testsuite.serverName, nil) - for replicasClientNewListByServerPager.More() { - _, err := replicasClientNewListByServerPager.NextPage(testsuite.ctx) - testsuite.Require().NoError(err) - break - } -} - -// Microsoft.DBforPostgreSQL/servers/firewallRules -func (testsuite *PostgresqlTestSuite) TestFirewallrules() { +// Microsoft.DBforPostgreSQL/servers/{serverName}/firewallRules/{firewallRuleName} +func (testsuite *PostgresqlTestSuite) TestFirewallRules() { var err error // From step FirewallRules_CreateOrUpdate fmt.Println("Call operation: FirewallRules_CreateOrUpdate") @@ -197,67 +183,63 @@ func (testsuite *PostgresqlTestSuite) TestFirewallrules() { testsuite.Require().NoError(err) } -// Microsoft.DBforPostgreSQL/servers/virtualNetworkRules -func (testsuite *PostgresqlTestSuite) TestVirtualnetworkrules() { +// Microsoft.DBforPostgreSQL/servers/{serverName}/virtualNetworkRules/{virtualNetworkRuleName} +func (testsuite *PostgresqlTestSuite) TestVirtualNetworkRules() { var subnetId string var err error // From step VirtualNetwork_Create - template := map[string]interface{}{ + template := map[string]any{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", - "outputs": map[string]interface{}{ - "subnetId": map[string]interface{}{ + "outputs": map[string]any{ + "subnetId": map[string]any{ "type": "string", "value": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), parameters('subnetName'))]", }, }, - "parameters": map[string]interface{}{ - "location": map[string]interface{}{ + "parameters": map[string]any{ + "location": map[string]any{ "type": "string", - "defaultValue": "$(location)", + "defaultValue": testsuite.location, }, - "subnetName": map[string]interface{}{ + "subnetName": map[string]any{ "type": "string", "defaultValue": "pgsubnet", }, - "virtualNetworksName": map[string]interface{}{ + "virtualNetworksName": map[string]any{ "type": "string", "defaultValue": "pgvnet", }, }, - "resources": []interface{}{ - map[string]interface{}{ + "resources": []any{ + map[string]any{ "name": "[parameters('virtualNetworksName')]", "type": "Microsoft.Network/virtualNetworks", "apiVersion": "2021-05-01", "location": "[parameters('location')]", - "properties": map[string]interface{}{ - "addressSpace": map[string]interface{}{ - "addressPrefixes": []interface{}{ + "properties": map[string]any{ + "addressSpace": map[string]any{ + "addressPrefixes": []any{ "10.0.0.0/16", }, }, - "subnets": []interface{}{ - map[string]interface{}{ + "subnets": []any{ + map[string]any{ "name": "[parameters('subnetName')]", - "properties": map[string]interface{}{ + "properties": map[string]any{ "addressPrefix": "10.0.0.0/24", }, }, }, }, - "tags": map[string]interface{}{}, + "tags": map[string]any{}, }, }, } - params := map[string]interface{}{ - "location": map[string]interface{}{"value": testsuite.location}, - } deployment := armresources.Deployment{ Properties: &armresources.DeploymentProperties{ - Template: template, - Parameters: params, - Mode: to.Ptr(armresources.DeploymentModeIncremental), + Template: template, + Mode: to.Ptr(armresources.DeploymentModeIncremental), }, } deploymentExtend, err := testutil.CreateDeployment(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName, "VirtualNetwork_Create", &deployment) @@ -300,7 +282,7 @@ func (testsuite *PostgresqlTestSuite) TestVirtualnetworkrules() { testsuite.Require().NoError(err) } -// Microsoft.DBforPostgreSQL/servers/databases +// Microsoft.DBforPostgreSQL/servers/{serverName}/databases/{databaseName} func (testsuite *PostgresqlTestSuite) TestDatabases() { var err error // From step Databases_CreateOrUpdate @@ -339,7 +321,7 @@ func (testsuite *PostgresqlTestSuite) TestDatabases() { testsuite.Require().NoError(err) } -// Microsoft.DBforPostgreSQL/servers/configurations +// Microsoft.DBforPostgreSQL/servers/{serverName}/configurations/{configurationName} func (testsuite *PostgresqlTestSuite) TestConfigurations() { var err error // From step Configurations_CreateOrUpdate @@ -371,8 +353,64 @@ func (testsuite *PostgresqlTestSuite) TestConfigurations() { testsuite.Require().NoError(err) } +// Microsoft.DBforPostgreSQL/servers/{serverName}/administrators/activeDirectory +func (testsuite *PostgresqlTestSuite) TestServerAdministrators() { + var err error + // From step ServerAdministrators_CreateOrUpdate + fmt.Println("Call operation: ServerAdministrators_CreateOrUpdate") + serverAdministratorsClient, err := armpostgresql.NewServerAdministratorsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + serverAdministratorsClientCreateOrUpdateResponsePoller, err := serverAdministratorsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.serverName, armpostgresql.ServerAdministratorResource{ + Properties: &armpostgresql.ServerAdministratorProperties{ + AdministratorType: to.Ptr("ActiveDirectory"), + Login: to.Ptr("bob@contoso.com"), + Sid: to.Ptr("c6b82b90-a647-49cb-8a62-0d2d3cb7ac7c"), + TenantID: to.Ptr("c6b82b90-a647-49cb-8a62-0d2d3cb7ac7c"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, serverAdministratorsClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step ServerAdministrators_List + fmt.Println("Call operation: ServerAdministrators_List") + serverAdministratorsClientNewListPager := serverAdministratorsClient.NewListPager(testsuite.resourceGroupName, testsuite.serverName, nil) + for serverAdministratorsClientNewListPager.More() { + _, err := serverAdministratorsClientNewListPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step ServerAdministrators_Get + fmt.Println("Call operation: ServerAdministrators_Get") + _, err = serverAdministratorsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.serverName, nil) + testsuite.Require().NoError(err) + + // From step ServerAdministrators_Delete + fmt.Println("Call operation: ServerAdministrators_Delete") + serverAdministratorsClientDeleteResponsePoller, err := serverAdministratorsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.serverName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, serverAdministratorsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DBforPostgreSQL/servers/replicas +func (testsuite *PostgresqlTestSuite) TestReplicas() { + var err error + // From step Replicas_ListByServer + fmt.Println("Call operation: Replicas_ListByServer") + replicasClient, err := armpostgresql.NewReplicasClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + replicasClientNewListByServerPager := replicasClient.NewListByServerPager(testsuite.resourceGroupName, testsuite.serverName, nil) + for replicasClientNewListByServerPager.More() { + _, err := replicasClientNewListByServerPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } +} + // Microsoft.DBforPostgreSQL/servers/updateConfigurations -func (testsuite *PostgresqlTestSuite) TestServerparameters() { +func (testsuite *PostgresqlTestSuite) TestServerParameters() { var err error // From step ServerParameters_ListUpdateConfigurations fmt.Println("Call operation: ServerParameters_ListUpdateConfigurations") @@ -399,7 +437,7 @@ func (testsuite *PostgresqlTestSuite) TestServerparameters() { } // Microsoft.DBforPostgreSQL/servers/logFiles -func (testsuite *PostgresqlTestSuite) TestLogfiles() { +func (testsuite *PostgresqlTestSuite) TestLogFiles() { var err error // From step LogFiles_ListByServer fmt.Println("Call operation: LogFiles_ListByServer") @@ -413,49 +451,8 @@ func (testsuite *PostgresqlTestSuite) TestLogfiles() { } } -// Microsoft.DBforPostgreSQL/servers/administrators/activeDirectory -func (testsuite *PostgresqlTestSuite) TestServeradministrators() { - var err error - // From step ServerAdministrators_CreateOrUpdate - fmt.Println("Call operation: ServerAdministrators_CreateOrUpdate") - serverAdministratorsClient, err := armpostgresql.NewServerAdministratorsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) - testsuite.Require().NoError(err) - serverAdministratorsClientCreateOrUpdateResponsePoller, err := serverAdministratorsClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.serverName, armpostgresql.ServerAdministratorResource{ - Properties: &armpostgresql.ServerAdministratorProperties{ - AdministratorType: to.Ptr("ActiveDirectory"), - Login: to.Ptr("bob@contoso.com"), - Sid: to.Ptr("c6b82b90-a647-49cb-8a62-0d2d3cb7ac7c"), - TenantID: to.Ptr("c6b82b90-a647-49cb-8a62-0d2d3cb7ac7c"), - }, - }, nil) - testsuite.Require().NoError(err) - _, err = testutil.PollForTest(testsuite.ctx, serverAdministratorsClientCreateOrUpdateResponsePoller) - testsuite.Require().NoError(err) - - // From step ServerAdministrators_List - fmt.Println("Call operation: ServerAdministrators_List") - serverAdministratorsClientNewListPager := serverAdministratorsClient.NewListPager(testsuite.resourceGroupName, testsuite.serverName, nil) - for serverAdministratorsClientNewListPager.More() { - _, err := serverAdministratorsClientNewListPager.NextPage(testsuite.ctx) - testsuite.Require().NoError(err) - break - } - - // From step ServerAdministrators_Get - fmt.Println("Call operation: ServerAdministrators_Get") - _, err = serverAdministratorsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.serverName, nil) - testsuite.Require().NoError(err) - - // From step ServerAdministrators_Delete - fmt.Println("Call operation: ServerAdministrators_Delete") - serverAdministratorsClientDeleteResponsePoller, err := serverAdministratorsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.serverName, nil) - testsuite.Require().NoError(err) - _, err = testutil.PollForTest(testsuite.ctx, serverAdministratorsClientDeleteResponsePoller) - testsuite.Require().NoError(err) -} - // Microsoft.DBforPostgreSQL/servers/recoverableServers -func (testsuite *PostgresqlTestSuite) TestRecoverableservers() { +func (testsuite *PostgresqlTestSuite) TestRecoverableServers() { var err error // From step RecoverableServers_Get fmt.Println("Call operation: RecoverableServers_Get") @@ -466,7 +463,7 @@ func (testsuite *PostgresqlTestSuite) TestRecoverableservers() { } // Microsoft.DBforPostgreSQL/servers/performanceTiers -func (testsuite *PostgresqlTestSuite) TestServerbasedperformancetier() { +func (testsuite *PostgresqlTestSuite) TestServerBasedPerformanceTier() { var err error // From step ServerBasedPerformanceTier_List fmt.Println("Call operation: ServerBasedPerformanceTier_List") @@ -481,7 +478,7 @@ func (testsuite *PostgresqlTestSuite) TestServerbasedperformancetier() { } // Microsoft.DBforPostgreSQL/locations/performanceTiers -func (testsuite *PostgresqlTestSuite) TestLocationbasedperformancetier() { +func (testsuite *PostgresqlTestSuite) TestLocationBasedPerformanceTier() { var err error // From step LocationBasedPerformanceTier_List fmt.Println("Call operation: LocationBasedPerformanceTier_List") @@ -496,7 +493,7 @@ func (testsuite *PostgresqlTestSuite) TestLocationbasedperformancetier() { } // Microsoft.DBforPostgreSQL/checkNameAvailability -func (testsuite *PostgresqlTestSuite) TestChecknameavailability() { +func (testsuite *PostgresqlTestSuite) TestCheckNameAvailability() { var err error // From step CheckNameAvailability_Execute fmt.Println("Call operation: CheckNameAvailability_Execute") diff --git a/sdk/resourcemanager/postgresql/armpostgresql/privateendpointconnections_live_test.go b/sdk/resourcemanager/postgresql/armpostgresql/privateendpointconnections_live_test.go new file mode 100644 index 000000000000..ba1c718d40df --- /dev/null +++ b/sdk/resourcemanager/postgresql/armpostgresql/privateendpointconnections_live_test.go @@ -0,0 +1,271 @@ +//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 armpostgresql_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/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/postgresql/armpostgresql" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" + "github.com/stretchr/testify/suite" +) + +type PrivateEndpointConnectionsTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + postgresqlserverId string + serverName string + adminPassword string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *PrivateEndpointConnectionsTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/postgresql/armpostgresql/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.serverName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "serverna", 14, true) + testsuite.adminPassword = testutil.GetEnv("ADMIN_PASSWORD", "") + 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 *PrivateEndpointConnectionsTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestPrivateEndpointConnectionsTestSuite(t *testing.T) { + suite.Run(t, new(PrivateEndpointConnectionsTestSuite)) +} + +func (testsuite *PrivateEndpointConnectionsTestSuite) Prepare() { + var err error + // From step Servers_Create + fmt.Println("Call operation: Servers_Create") + serversClient, err := armpostgresql.NewServersClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + serversClientCreateResponsePoller, err := serversClient.BeginCreate(testsuite.ctx, testsuite.resourceGroupName, testsuite.serverName, armpostgresql.ServerForCreate{ + Location: to.Ptr(testsuite.location), + Properties: &armpostgresql.ServerPropertiesForDefaultCreate{ + CreateMode: to.Ptr(armpostgresql.CreateModeDefault), + MinimalTLSVersion: to.Ptr(armpostgresql.MinimalTLSVersionEnumTLS12), + SSLEnforcement: to.Ptr(armpostgresql.SSLEnforcementEnumEnabled), + StorageProfile: &armpostgresql.StorageProfile{ + BackupRetentionDays: to.Ptr[int32](7), + GeoRedundantBackup: to.Ptr(armpostgresql.GeoRedundantBackupDisabled), + StorageMB: to.Ptr[int32](128000), + }, + AdministratorLogin: to.Ptr("cloudsa"), + AdministratorLoginPassword: to.Ptr(testsuite.adminPassword), + }, + SKU: &armpostgresql.SKU{ + Name: to.Ptr("GP_Gen5_8"), + Family: to.Ptr("Gen5"), + Tier: to.Ptr(armpostgresql.SKUTierGeneralPurpose), + }, + Tags: map[string]*string{ + "ElasticServer": to.Ptr("1"), + }, + }, nil) + testsuite.Require().NoError(err) + var serversClientCreateResponse *armpostgresql.ServersClientCreateResponse + serversClientCreateResponse, err = testutil.PollForTest(testsuite.ctx, serversClientCreateResponsePoller) + testsuite.Require().NoError(err) + testsuite.postgresqlserverId = *serversClientCreateResponse.ID +} + +// Microsoft.DBforPostgreSQL/servers/{serverName}/privateEndpointConnections/{privateEndpointConnectionName} +func (testsuite *PrivateEndpointConnectionsTestSuite) TestPrivateEndpointConnections() { + var err error + // 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": "pepostgresql-nic", + }, + "postgresqlserverId": map[string]any{ + "type": "string", + "defaultValue": testsuite.postgresqlserverId, + }, + "privateEndpointName": map[string]any{ + "type": "string", + "defaultValue": "pepostgresql", + }, + "virtualNetworksName": map[string]any{ + "type": "string", + "defaultValue": "pepostgresqlvnet", + }, + }, + "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": "default", + "properties": map[string]any{ + "addressPrefix": "10.0.0.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', parameters('virtualNetworksName'))]", + }, + "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'), 'default')]", + }, + }, + }, + }, + }, + }, + map[string]any{ + "name": "[parameters('privateEndpointName')]", + "type": "Microsoft.Network/privateEndpoints", + "apiVersion": "2020-11-01", + "dependsOn": []any{ + "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworksName'))]", + }, + "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{ + "postgresqlServer", + }, + "privateLinkServiceConnectionState": map[string]any{ + "description": "Auto-Approved", + "actionsRequired": "None", + "status": "Approved", + }, + "privateLinkServiceId": "[parameters('postgresqlserverId')]", + }, + }, + }, + "subnet": map[string]any{ + "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworksName'), 'default')]", + }, + }, + }, + }, + "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) + + var privateEndpointConnectionName string + // From step PrivateEndpointConnections_ListByServer + fmt.Println("Call operation: PrivateEndpointConnections_ListByServer") + privateEndpointConnectionsClient, err := armpostgresql.NewPrivateEndpointConnectionsClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + privateEndpointConnectionsClientNewListByServerPager := privateEndpointConnectionsClient.NewListByServerPager(testsuite.resourceGroupName, testsuite.serverName, nil) + for privateEndpointConnectionsClientNewListByServerPager.More() { + result, err := privateEndpointConnectionsClientNewListByServerPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + privateEndpointConnectionName = *result.Value[0].Name + break + } + + // From step PrivateEndpointConnections_Get + fmt.Println("Call operation: PrivateEndpointConnections_Get") + _, err = privateEndpointConnectionsClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.serverName, privateEndpointConnectionName, nil) + testsuite.Require().NoError(err) + + var privateLinkResourceName string + // from step PrivateLinkResources_ListByServer + fmt.Println("Call operation: PrivateLinkResources_ListByServer") + privateLinkResourcesClient, err := armpostgresql.NewPrivateLinkResourcesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + privateLinkResourcesClientNewListByServerPager := privateLinkResourcesClient.NewListByServerPager(testsuite.resourceGroupName, testsuite.serverName, nil) + for privateLinkResourcesClientNewListByServerPager.More() { + result, err := privateLinkResourcesClientNewListByServerPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + privateLinkResourceName = *result.Value[0].Name + break + } + + // From step PrivateLinkResources_Get + fmt.Println("Call operation: PrivateLinkResources_Get") + _, err = privateLinkResourcesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.serverName, privateLinkResourceName, nil) + testsuite.Require().NoError(err) + + // From step PrivateEndpointConnections_Delete + fmt.Println("Call operation: PrivateEndpointConnections_Delete") + privateEndpointConnectionsClientDeleteResponsePoller, err := privateEndpointConnectionsClient.BeginDelete(testsuite.ctx, testsuite.resourceGroupName, testsuite.serverName, privateEndpointConnectionName, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, privateEndpointConnectionsClientDeleteResponsePoller) + testsuite.Require().NoError(err) +} diff --git a/sdk/resourcemanager/postgresql/armpostgresql/serversecurityalertpolicies_live_test.go b/sdk/resourcemanager/postgresql/armpostgresql/serversecurityalertpolicies_live_test.go new file mode 100644 index 000000000000..f8cecb98ac1c --- /dev/null +++ b/sdk/resourcemanager/postgresql/armpostgresql/serversecurityalertpolicies_live_test.go @@ -0,0 +1,126 @@ +//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 armpostgresql_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/internal/testutil" + "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/postgresql/armpostgresql" + "github.com/stretchr/testify/suite" +) + +type ServerSecurityAlertPoliciesTestSuite struct { + suite.Suite + + ctx context.Context + cred azcore.TokenCredential + options *arm.ClientOptions + serverName string + adminPassword string + location string + resourceGroupName string + subscriptionId string +} + +func (testsuite *ServerSecurityAlertPoliciesTestSuite) SetupSuite() { + testutil.StartRecording(testsuite.T(), "sdk/resourcemanager/postgresql/armpostgresql/testdata") + + testsuite.ctx = context.Background() + testsuite.cred, testsuite.options = testutil.GetCredAndClientOptions(testsuite.T()) + testsuite.serverName, _ = recording.GenerateAlphaNumericID(testsuite.T(), "serverna", 14, true) + testsuite.adminPassword = testutil.GetEnv("ADMIN_PASSWORD", "") + 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 *ServerSecurityAlertPoliciesTestSuite) TearDownSuite() { + _, err := testutil.DeleteResourceGroup(testsuite.ctx, testsuite.subscriptionId, testsuite.cred, testsuite.options, testsuite.resourceGroupName) + testsuite.Require().NoError(err) + testutil.StopRecording(testsuite.T()) +} + +func TestServerSecurityAlertPoliciesTestSuite(t *testing.T) { + suite.Run(t, new(ServerSecurityAlertPoliciesTestSuite)) +} + +func (testsuite *ServerSecurityAlertPoliciesTestSuite) Prepare() { + var err error + // From step Servers_Create + fmt.Println("Call operation: Servers_Create") + serversClient, err := armpostgresql.NewServersClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + serversClientCreateResponsePoller, err := serversClient.BeginCreate(testsuite.ctx, testsuite.resourceGroupName, testsuite.serverName, armpostgresql.ServerForCreate{ + Location: to.Ptr(testsuite.location), + Properties: &armpostgresql.ServerPropertiesForDefaultCreate{ + CreateMode: to.Ptr(armpostgresql.CreateModeDefault), + MinimalTLSVersion: to.Ptr(armpostgresql.MinimalTLSVersionEnumTLS12), + SSLEnforcement: to.Ptr(armpostgresql.SSLEnforcementEnumEnabled), + StorageProfile: &armpostgresql.StorageProfile{ + BackupRetentionDays: to.Ptr[int32](7), + GeoRedundantBackup: to.Ptr(armpostgresql.GeoRedundantBackupDisabled), + StorageMB: to.Ptr[int32](128000), + }, + AdministratorLogin: to.Ptr("cloudsa"), + AdministratorLoginPassword: to.Ptr(testsuite.adminPassword), + }, + SKU: &armpostgresql.SKU{ + Name: to.Ptr("GP_Gen5_8"), + Family: to.Ptr("Gen5"), + Tier: to.Ptr(armpostgresql.SKUTierGeneralPurpose), + }, + Tags: map[string]*string{ + "ElasticServer": to.Ptr("1"), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, serversClientCreateResponsePoller) + testsuite.Require().NoError(err) +} + +// Microsoft.DBforPostgreSQL/servers/{serverName}/securityAlertPolicies/{securityAlertPolicyName} +func (testsuite *ServerSecurityAlertPoliciesTestSuite) TestServerSecurityAlertPolicies() { + var err error + // From step ServerSecurityAlertPolicies_CreateOrUpdate + fmt.Println("Call operation: ServerSecurityAlertPolicies_CreateOrUpdate") + serverSecurityAlertPoliciesClient, err := armpostgresql.NewServerSecurityAlertPoliciesClient(testsuite.subscriptionId, testsuite.cred, testsuite.options) + testsuite.Require().NoError(err) + serverSecurityAlertPoliciesClientCreateOrUpdateResponsePoller, err := serverSecurityAlertPoliciesClient.BeginCreateOrUpdate(testsuite.ctx, testsuite.resourceGroupName, testsuite.serverName, armpostgresql.SecurityAlertPolicyNameDefault, armpostgresql.ServerSecurityAlertPolicy{ + Properties: &armpostgresql.SecurityAlertPolicyProperties{ + EmailAccountAdmins: to.Ptr(true), + State: to.Ptr(armpostgresql.ServerSecurityAlertPolicyStateDisabled), + }, + }, nil) + testsuite.Require().NoError(err) + _, err = testutil.PollForTest(testsuite.ctx, serverSecurityAlertPoliciesClientCreateOrUpdateResponsePoller) + testsuite.Require().NoError(err) + + // From step ServerSecurityAlertPolicies_ListByServer + fmt.Println("Call operation: ServerSecurityAlertPolicies_ListByServer") + serverSecurityAlertPoliciesClientNewListByServerPager := serverSecurityAlertPoliciesClient.NewListByServerPager(testsuite.resourceGroupName, testsuite.serverName, nil) + for serverSecurityAlertPoliciesClientNewListByServerPager.More() { + _, err := serverSecurityAlertPoliciesClientNewListByServerPager.NextPage(testsuite.ctx) + testsuite.Require().NoError(err) + break + } + + // From step ServerSecurityAlertPolicies_Get + fmt.Println("Call operation: ServerSecurityAlertPolicies_Get") + _, err = serverSecurityAlertPoliciesClient.Get(testsuite.ctx, testsuite.resourceGroupName, testsuite.serverName, armpostgresql.SecurityAlertPolicyNameDefault, nil) + testsuite.Require().NoError(err) +}