pulumi / pulumi-azure-native

Azure Native Provider
Apache License 2.0
128 stars 34 forks source link

Creating a SQL database as a copy ignores AutoPauseDelay input #1184

Open pierskarsenbarg opened 3 years ago

pierskarsenbarg commented 3 years ago

Hello!

Issue details

When creating a SQL server and then a another as a copy of the first (code below), even if you set AutoPause to be disabled (-1) in both, the source will have it disabled, but on the destination it will be enabled.

Code example:

package main

import (
    "fmt"

    "github.com/pulumi/pulumi-azure-native/sdk/go/azure/resources"
    sql "github.com/pulumi/pulumi-azure-native/sdk/go/azure/sql"
    "github.com/pulumi/pulumi-random/sdk/v4/go/random"
    "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        // Create an Azure Resource Group
        resourceGroup, err := resources.NewResourceGroup(ctx, "autopauseRg", nil)
        if err != nil {
            return err
        }

        password1, err := random.NewRandomPassword(ctx, "password1", &random.RandomPasswordArgs{
            Length:          pulumi.Int(20),
            Special:         pulumi.Bool(true),
            OverrideSpecial: pulumi.String(fmt.Sprintf("%v%v%v", "_", "%", "@")),
        })
        if err != nil {
            return err
        }

        sourceServer, err := sql.NewServer(ctx, "originalserver", &sql.ServerArgs{
            AdministratorLogin:         pulumi.String("dummylogin"),
            AdministratorLoginPassword: password1.Result,
            ResourceGroupName:          resourceGroup.Name,
            ServerName:                 pulumi.String("pk-sql-server-original"),
        })

        if err != nil {
            return err
        }

        sourceDb, err := sql.NewDatabase(ctx, "database", &sql.DatabaseArgs{
            Collation:         pulumi.String("SQL_Latin1_General_CP1_CI_AS"),
            CreateMode:        pulumi.String("Default"),
            DatabaseName:      pulumi.String("testdb"),
            MaxSizeBytes:      pulumi.Float64(1073741824),
            ResourceGroupName: resourceGroup.Name,
            ServerName:        sourceServer.Name,
            AutoPauseDelay:    pulumi.Int(-1),
            Sku: &sql.SkuArgs{
                Name: pulumi.String("GP_S_Gen5_1"),
                Tier: pulumi.String("GeneralPurpose"),
            },
        })
        if err != nil {
            return err
        }

        password2, err := random.NewRandomPassword(ctx, "password2", &random.RandomPasswordArgs{
            Length:          pulumi.Int(20),
            Special:         pulumi.Bool(true),
            OverrideSpecial: pulumi.String(fmt.Sprintf("%v%v%v", "_", "%", "@")),
        })
        if err != nil {
            return err
        }

        destinationServer, err := sql.NewServer(ctx, "destinationserver", &sql.ServerArgs{
            AdministratorLogin:         pulumi.String("dummylogin"),
            AdministratorLoginPassword: password2.Result,
            ResourceGroupName:          resourceGroup.Name,
            ServerName:                 pulumi.String("pk-sql-server-destination"),
        }, pulumi.DependsOn([]pulumi.Resource{sourceDb, sourceServer}))

        if err != nil {
            return err
        }

        _, err = sql.NewDatabase(ctx, "databaseCopy", &sql.DatabaseArgs{
            CreateMode:        pulumi.String("Copy"),
            DatabaseName:      pulumi.String("dbcopy"),
            ResourceGroupName: resourceGroup.Name,
            ServerName:        destinationServer.Name,
            AutoPauseDelay:    pulumi.Int(-1),
            Sku: &sql.SkuArgs{
                Name: pulumi.String("GP_S_Gen5_1"),
                Tier: pulumi.String("GeneralPurpose"),
            },
            SourceDatabaseId: sourceDb.ID(),
        }, pulumi.DependsOn([]pulumi.Resource{sourceServer}))
        if err != nil {
            return err
        }

        return nil
    })
}

Expected: The destination should have auto-pause disabled Actual: The destination has auto-pause enabled

mikhailshilkov commented 3 years ago

Hey @pierskarsenbarg could you capture the logs and see if we are sending it to the API correctly in the HTTP request body?

pierskarsenbarg commented 3 years ago

@mikhailshilkov Logs here: out.txt

mikhailshilkov commented 3 years ago

Here is the relevant request:

PUT https://management.azure.com/subscriptions/32b9cb2e-69be-4040-80a6-02cd6b2cc5ec/resourceGroups/autopauseRg8a43b750/providers/Microsoft.Sql/servers/pk-sql-server-destination/databases/dbcopy?api-version=2020-11-01-preview
{
  "location": "uksouth",
  "properties": {
    "autoPauseDelay": -1,
    "createMode": "Copy",
    "sourceDatabaseId": "/subscriptions/32b9cb2e-69be-4040-80a6-02cd6b2cc5ec/resourceGroups/autopauseRg8a43b750/providers/Microsoft.Sql/servers/pk-sql-server-original/databases/testdb"
  },
  "sku": {
    "name": "GP_S_Gen5_1",
    "tier": "GeneralPurpose"
  }
}

It all looks good to me... I suspect that's a particularity of Azure then.

mikhailshilkov commented 3 years ago

The response is then:

{
  "sku": {
    "name": "GP_S_Gen5",
    "tier": "GeneralPurpose",
    "family": "Gen5",
    "capacity": 1
  },
  "kind": "v12.0,user,vcore,serverless",
  "properties": {
    "collation": "SQL_Latin1_General_CP1_CI_AS",
    "maxSizeBytes": 1073741824,
    "status": "Online",
    "databaseId": "212e11b7-8f9b-4033-9ea8-617c8ac6cfd6",
    "creationDate": "2021-09-29T16:12:32.677Z",
    "currentServiceObjectiveName": "GP_S_Gen5_1",
    "requestedServiceObjectiveName": "GP_S_Gen5_1",
    "defaultSecondaryLocation": "ukwest",
    "catalogCollation": "SQL_Latin1_General_CP1_CI_AS",
    "zoneRedundant": false,
    "maxLogSizeBytes": 68719476736,
    "readScale": "Disabled",
    "currentSku": {
      "name": "GP_S_Gen5",
      "tier": "GeneralPurpose",
      "family": "Gen5",
      "capacity": 1
    },
    "autoPauseDelay": 60,
    "currentBackupStorageRedundancy": "Geo",
    "requestedBackupStorageRedundancy": "Geo",
    "minCapacity": 0.5000,
    "maintenanceConfigurationId": "/subscriptions/32b9cb2e-69be-4040-80a6-02cd6b2cc5ec/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/SQL_Default"
  },
  "location": "uksouth",
  "id": "/subscriptions/32b9cb2e-69be-4040-80a6-02cd6b2cc5ec/resourceGroups/autopauseRg8a43b750/providers/Microsoft.Sql/servers/pk-sql-server-destination/databases/dbcopy",
  "name": "dbcopy",
  "type": "Microsoft.Sql/servers/databases"
}

🤷