pulumi / pulumi-azure-native

Azure Native Provider
Apache License 2.0
129 stars 35 forks source link

GeoBackupPolicy error on destroy #564

Open jamesianberry opened 3 years ago

jamesianberry commented 3 years ago

azure-nextgen:sql/latest:GeoBackupPolicy (LocalSqlDbLocalGeoBackupPolicy): error: json: cannot unmarshal array into Go struct field serviceError2.details of type map[string]interface {}

during destroy with the following C# code: using Sql = Pulumi.AzureNextGen.Sql.Latest; ... var localSqlDbLocalGeoBackupPolicy = new Sql.GeoBackupPolicy("LocalSqlDbLocalGeoBackupPolicy", new Sql.GeoBackupPolicyArgs { DatabaseName = localSqlDbLocal.Name, GeoBackupPolicyName = "Default", ResourceGroupName = args.ResourceGroup.Name, ServerName = localSqlServer.Name, State = Sql.GeoBackupPolicyState.Enabled, });

mikhailshilkov commented 3 years ago

The error message parsing will improve in the next release with https://github.com/pulumi/pulumi-azure-nextgen/issues/213

The destroy operation will likely still fail - with a better error message. Maybe, can you see that message in the activity log of the database?

mikhailshilkov commented 3 years ago

I tried a sample with the latest 0.5.0 and got the error

Status=400 Code="40822" Message="This feature is not available for the selected database's edition (GeneralPurpose)." Details=[{"code":"40822","message":"This feature is not available for the selected database's edition (GeneralPurpose).","severity":"16","target":null}] InnerError={"multi":[]}

on destroy. I have no idea why it did NOT fail on creation: it responded with 201 Created but now gives 400 BadRequest for the same endpoint. Maybe disabling is not allowed.

Anyway, this probably depends on your server's SKU. I'm curious to know which error you are getting.

jamesianberry commented 3 years ago

I've upgraded to 0.5.0 but get the same error when trying to destroy the existing stack: Diagnostics: azure-nextgen:sql/latest:GeoBackupPolicy (LocalSqlDbLocalGeoBackupPolicy): error: json: cannot unmarshal array into Go struct field serviceError2.details of type map[string]interface {} I'll delete this stack and resource group and see what happens with a fresh stack (I also have another stack built with 0.4.0).

jamesianberry commented 3 years ago

Successfully recreated the stack, with the diff including:

LocalSqlDbLocalGeoBackupPolicy (azure-nextgen:sql:GeoBackupPolicy)
+  azure-nextgen:sql/latest:GeoBackupPolicy (create)
    [urn=urn:pulumi:mnu2auto::autobots::azure-nextgen:sql/latest:GeoBackupPolicy::LocalSqlDbLocalGeoBackupPolicy]
    databaseName       : "mnu2autolocal"
    geoBackupPolicyName: "Default"
    resourceGroupName  : "mnu2auto"
    serverName         : "mnu2autolocal"
    state              : "Enabled"

The template of the database has two mentions:

{
            "type": "Microsoft.Sql/servers/databases/geoBackupPolicies",
            "apiVersion": "2014-04-01",
            "name": "[concat(parameters('servers_mnu2autolocal_name'), '/master/Default')]",
            "location": "Australia East",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_mnu2autolocal_name'))]"
            ],
            "properties": {
                "state": "Disabled"
            }
        },

and

        {
            "type": "Microsoft.Sql/servers/databases/geoBackupPolicies",
            "apiVersion": "2014-04-01",
            "name": "[concat(parameters('servers_mnu2autolocal_name'), '/', parameters('servers_mnu2autolocal_name'), '/Default')]",
            "location": "Australia East",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers/databases', parameters('servers_mnu2autolocal_name'), parameters('servers_mnu2autolocal_name'))]",
                "[resourceId('Microsoft.Sql/servers', parameters('servers_mnu2autolocal_name'))]"
            ],
            "properties": {
                "state": "Enabled"
            }
        },

which I read as saying the GeoBackupPolicy is enabled at the database but not server level? Comparing with the server I am trying to replicate I can see that GeoBackup Policy is enabled at both server

        {
            "type": "Microsoft.Sql/servers/databases/geoBackupPolicies",
            "apiVersion": "2014-04-01",
            "name": "[concat(parameters('servers_mnuloadtest_name'), '/master/Default')]",
            "location": "Australia East",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_mnuloadtest_name'))]"
            ],
            "properties": {
                "state": "Enabled"
            }
        },

and database level:

        {
            "type": "Microsoft.Sql/servers/databases/geoBackupPolicies",
            "apiVersion": "2014-04-01",
            "name": "[concat(parameters('servers_mnuloadtest_name'), '/mnuload/Default')]",
            "location": "Australia East",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers/databases', parameters('servers_mnuloadtest_name'), 'mnuload')]",
                "[resourceId('Microsoft.Sql/servers', parameters('servers_mnuloadtest_name'))]"
            ],
            "properties": {
                "state": "Enabled"
            }
        },

Perhaps I need to try to enable for both.

jamesianberry commented 3 years ago

On attempting to delete the stack, got the same error as you did: LocalSqlDbLocalGeoBackupPolicy (azure-nextgen:sql:GeoBackupPolicy) error: autorest/azure: Service returned an error. Status=400 Code="40822" Message="This feature is not available for the selected database's edition (GeneralPurpose)." Details=[{"code":"40822","message":"This feature is not available for the selected database's edition (GeneralPurpose).","severity":"16","target":null}] InnerError={"multi":[]}

jamesianberry commented 3 years ago

The database I am trying to replicate has this sku:

            "sku": {
                "name": "GP_Gen5",
                "tier": "GeneralPurpose",
                "family": "Gen5",
                "capacity": 2
            },

which is exactly the same as the one I am creating, so I don't see how this error can be correct. I will try to enable the GeoBackupPolicy on the master database.

jamesianberry commented 3 years ago

Got an error:

azure-nextgen:sql/latest:GeoBackupPolicy (LocalSqlDbMasterGeoBackupPolicy):
    error: parent resource does not exist for resource '/subscriptions/a2a556e1-0404-4b5d-b60d-a230044f4ff8/resourceGroups/mnu2auto/providers/Microsoft.Sql/servers/mnu2autolocal/databases/master/geoBackupPolicies/Default'

for this added code:

using Sql  = Pulumi.AzureNextGen.Sql.Latest;
...
        var localSqlDbMasterGeoBackupPolicy = new Sql.GeoBackupPolicy("LocalSqlDbMasterGeoBackupPolicy", new Sql.GeoBackupPolicyArgs
        {
            DatabaseName = "master",
            GeoBackupPolicyName = "Default",
            ResourceGroupName = args.ResourceGroup.Name,
            ServerName = localSqlServer.Name,
            State = Sql.GeoBackupPolicyState.Enabled,
        });

which I think is because I am using a literal rather than a reference to the master database. When I try 'pulumi up' again, I get:

azure-nextgen:sql/latest:GeoBackupPolicy (LocalSqlDbMasterGeoBackupPolicy):
    error: autorest/azure: Service returned an error. Status=400 Code="40822" Message="This feature is not available for the selected database's edition (System)." Details=[{"code":"40822","message":"This feature is not available for the selected database's edition (System).","severity":"16","target":null}] InnerError={"multi":[]}

So I haven't yet found how to enable the GeoBackupPolicy on the master database as seen above.

jamesianberry commented 3 years ago

Building the stack with:

            Sku = new Sql3.Inputs.SkuArgs
            {
                Capacity = 20,
                Name = "Standard",
                Tier = "Standard",
            },
            StorageAccountType = "GRS",
            ZoneRedundant = false,
        });

doesn't fix anything:

LocalSqlDbLocalGeoBackupPolicy (azure-nextgen:sql:GeoBackupPolicy)
error: autorest/azure: Service returned an error. Status=400 Code="40822" Message="This feature is not available for the selected database's edition (Standard)." Details=[{"code":"40822","message":"This feature is not available for the selected database's edition (Standard).","severity":"16","target":null}] InnerError={"multi":[]}
mikhailshilkov commented 3 years ago

I think is because I am using a literal rather than a reference to the master database.

Yes, this is the reason. It tried to provision the backup policy before the database existed because there was no dependency in the code between the two resources.