pulumi / pulumi-azure-native

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

arm2pulumi converter missing server_name in serverkey property #273

Closed tusharshahrs closed 3 years ago

tusharshahrs commented 4 years ago

I used this: https://www.pulumi.com/arm2pulumi/ to convert a ARM template for sql server into a python template.

The key_resource block:

key_resource = azure_nextgen.sql.v20150501preview.ServerKey("keyResource",
    key_name=f"{servers_shahtdbservername2_name_param}/ServiceManaged",
    resource_group_name=resource_group_name_param,
    server_key_type="ServiceManaged")

is missing the following server_name as it is required: https://www.pulumi.com/docs/reference/pkg/azure-nextgen/sql/serverkey/#server_name_python

How to reproduce:

  1. Go here: https://www.pulumi.com/arm2pulumi/
  2. Drop following arm template code ( server was created in azure console and template was downloaded afterwards).
    {
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "vulnerabilityAssessments_Default_storageContainerPath": {
            "type": "SecureString"
        },
        "servers_shahtdbservername2_name": {
            "defaultValue": "shahtdbservername2",
            "type": "String"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Sql/servers",
            "apiVersion": "2019-06-01-preview",
            "name": "[parameters('servers_shahtdbservername2_name')]",
            "location": "eastus2",
            "tags": {
                "created-by": "tusharshah",
                "creationSource": "console",
                "owner": "team-ce",
                "Purpose": "test template"
            },
            "kind": "v12.0",
            "properties": {
                "administratorLogin": "shahtshaht",
                "version": "12.0",
                "publicNetworkAccess": "Enabled"
            }
        },
        {
            "type": "Microsoft.Sql/servers/advisors",
            "apiVersion": "2014-04-01",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/CreateIndex')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "autoExecuteValue": "Disabled"
            }
        },
        {
            "type": "Microsoft.Sql/servers/advisors",
            "apiVersion": "2014-04-01",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/DbParameterization')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "autoExecuteValue": "Disabled"
            }
        },
        {
            "type": "Microsoft.Sql/servers/advisors",
            "apiVersion": "2014-04-01",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/DefragmentIndex')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "autoExecuteValue": "Disabled"
            }
        },
        {
            "type": "Microsoft.Sql/servers/advisors",
            "apiVersion": "2014-04-01",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/DropIndex')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "autoExecuteValue": "Disabled"
            }
        },
        {
            "type": "Microsoft.Sql/servers/advisors",
            "apiVersion": "2014-04-01",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/ForceLastGoodPlan')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "autoExecuteValue": "Enabled"
            }
        },
        {
            "type": "Microsoft.Sql/servers/auditingPolicies",
            "apiVersion": "2014-04-01",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/Default')]",
            "location": "East US 2",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "auditingState": "Disabled"
            }
        },
        {
            "type": "Microsoft.Sql/servers/auditingSettings",
            "apiVersion": "2017-03-01-preview",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/Default')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "state": "Disabled",
                "retentionDays": 0,
                "auditActionsAndGroups": [],
                "storageAccountSubscriptionId": "00000000-0000-0000-0000-000000000000",
                "isStorageSecondaryKeyInUse": false,
                "isAzureMonitorTargetEnabled": false
            }
        },
        {
            "type": "Microsoft.Sql/servers/databases/auditingPolicies",
            "apiVersion": "2014-04-01",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/master/Default')]",
            "location": "East US 2",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "auditingState": "Disabled"
            }
        },
        {
            "type": "Microsoft.Sql/servers/databases/auditingSettings",
            "apiVersion": "2017-03-01-preview",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/master/Default')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "state": "Disabled",
                "retentionDays": 0,
                "storageAccountSubscriptionId": "00000000-0000-0000-0000-000000000000",
                "isAzureMonitorTargetEnabled": false
            }
        },
        {
            "type": "Microsoft.Sql/servers/databases/extendedAuditingSettings",
            "apiVersion": "2017-03-01-preview",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/master/Default')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "state": "Disabled",
                "retentionDays": 0,
                "storageAccountSubscriptionId": "00000000-0000-0000-0000-000000000000",
                "isAzureMonitorTargetEnabled": false
            }
        },
        {
            "type": "Microsoft.Sql/servers/databases/geoBackupPolicies",
            "apiVersion": "2014-04-01",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/master/Default')]",
            "location": "East US 2",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "state": "Enabled"
            }
        },
        {
            "type": "Microsoft.Sql/servers/databases/securityAlertPolicies",
            "apiVersion": "2020-02-02-preview",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/master/Default')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "state": "Disabled"
            }
        },
        {
            "type": "Microsoft.Sql/servers/databases/transparentDataEncryption",
            "apiVersion": "2014-04-01",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/master/current')]",
            "location": "East US 2",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "status": "Disabled"
            }
        },
        {
            "type": "Microsoft.Sql/servers/databases/vulnerabilityAssessments",
            "apiVersion": "2017-03-01-preview",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/master/Default')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "recurringScans": {
                    "isEnabled": false,
                    "emailSubscriptionAdmins": true
                }
            }
        },
        {
            "type": "Microsoft.Sql/servers/encryptionProtector",
            "apiVersion": "2015-05-01-preview",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/current')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "kind": "servicemanaged",
            "properties": {
                "serverKeyName": "ServiceManaged",
                "serverKeyType": "ServiceManaged"
            }
        },
        {
            "type": "Microsoft.Sql/servers/extendedAuditingSettings",
            "apiVersion": "2017-03-01-preview",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/Default')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "state": "Disabled",
                "retentionDays": 0,
                "auditActionsAndGroups": [],
                "storageAccountSubscriptionId": "00000000-0000-0000-0000-000000000000",
                "isStorageSecondaryKeyInUse": false,
                "isAzureMonitorTargetEnabled": false
            }
        },
        {
            "type": "Microsoft.Sql/servers/firewallRules",
            "apiVersion": "2015-05-01-preview",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/AllowAllWindowsAzureIps')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "startIpAddress": "0.0.0.0",
                "endIpAddress": "0.0.0.0"
            }
        },
        {
            "type": "Microsoft.Sql/servers/keys",
            "apiVersion": "2015-05-01-preview",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/ServiceManaged')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "kind": "servicemanaged",
            "properties": {
                "serverKeyType": "ServiceManaged"
            }
        },
        {
            "type": "Microsoft.Sql/servers/securityAlertPolicies",
            "apiVersion": "2020-02-02-preview",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/Default')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "state": "Disabled"
            }
        },
        {
            "type": "Microsoft.Sql/servers/vulnerabilityAssessments",
            "apiVersion": "2018-06-01-preview",
            "name": "[concat(parameters('servers_shahtdbservername2_name'), '/Default')]",
            "dependsOn": [
                "[resourceId('Microsoft.Sql/servers', parameters('servers_shahtdbservername2_name'))]"
            ],
            "properties": {
                "recurringScans": {
                    "isEnabled": false,
                    "emailSubscriptionAdmins": true
                },
                "storageContainerPath": "[parameters('vulnerabilityAssessments_Default_storageContainerPath')]"
            }
        }
    ]
    }

When you convert it, the following is there.

import pulumi
import pulumi_azure_nextgen as azure_nextgen

config = pulumi.Config()
servers_shahtdbservername2_name_param = config.get("serversShahtdbservername2NameParam")
if servers_shahtdbservername2_name_param is None:
    servers_shahtdbservername2_name_param = "shahtdbservername2"
advisor_resource = None
advisor_resource0 = None
advisor_resource1 = None
advisor_resource2 = None
advisor_resource3 = None
auditing_policy_resource = None
auditing_policy_resource0 = None
auditing_setting_resource = None
auditing_setting_resource0 = None
encryption_protector_resource = None
extended_auditing_setting_resource = None
extended_auditing_setting_resource0 = None
resource_group_name_param = config.require("resourceGroupNameParam")
firewall_rule_resource = azure_nextgen.sql.v20150501preview.FirewallRule("firewallRuleResource",
    end_ip_address="0.0.0.0",
    firewall_rule_name=f"{servers_shahtdbservername2_name_param}/AllowAllWindowsAzureIps",
    resource_group_name=resource_group_name_param,
    start_ip_address="0.0.0.0")
geo_backup_policy_resource = None
key_resource = azure_nextgen.sql.v20150501preview.ServerKey("keyResource",
    key_name=f"{servers_shahtdbservername2_name_param}/ServiceManaged",
    kind="servicemanaged",
    resource_group_name=resource_group_name_param,
    server_key_type="ServiceManaged")
security_alert_policy_resource = None
security_alert_policy_resource0 = None
server_resource = azure_nextgen.sql.v20190601preview.Server("serverResource",
    administrator_login="shahtshaht",
    location="eastus2",
    public_network_access="Enabled",
    resource_group_name=resource_group_name_param,
    server_name=servers_shahtdbservername2_name_param,
    tags={
        "Purpose": "test template",
        "created-by": "tusharshah",
        "creationSource": "console",
        "owner": "team-ce",
    },
    version="12.0")
transparent_data_encryption_resource = None
vulnerability_assessment_resource = None
vulnerability_assessments_default_storage_container_path_param = config.require("vulnerabilityAssessmentsDefaultStorageContainerPathParam")
vulnerability_assessment_resource0 = azure_nextgen.sql.v20180601preview.ServerVulnerabilityAssessment("vulnerabilityAssessmentResource0",
    recurring_scans=azure_nextgen.sql.v20180601preview.VulnerabilityAssessmentRecurringScansPropertiesArgs(
        email_subscription_admins=True,
        is_enabled=False,
    ),
    resource_group_name=resource_group_name_param,
    storage_container_path=vulnerability_assessments_default_storage_container_path_param,
    vulnerability_assessment_name=f"{servers_shahtdbservername2_name_param}/Default")

Note that the

key_resource = azure_nextgen.sql.v20150501preview.ServerKey("keyResource",
    key_name=f"{servers_shahtdbservername2_name_param}/ServiceManaged",
    kind="servicemanaged",
    resource_group_name=resource_group_name_param,
    server_key_type="ServiceManaged")

is missing the server_name=servers_shahtdbservername2_name_param or to make it generic: server_name=server_name_param

Here is the error code:

File "....azure-nextgen-sqlserver/venv/lib/python3.8/site-packages/pulumi_azure_nextgen/sql/v20150501preview/server_key.py", line 72, in __init__
        raise TypeError("Missing required property 'server_name'")
    TypeError: Missing required property 'server_name'

Recommended Fix: add the additional parameter below: server_name=server_name_param,

Should look like this:

key_resource = azure_nextgen.sql.v20150501preview.ServerKey("keyResource",
    key_name=f"{servers_shahtdbservername2_name_param}/ServiceManaged",
    kind="servicemanaged",
    server_name=server_name_param,
    resource_group_name=resource_group_name_param,
    server_key_type="ServiceManaged")
viveklak commented 4 years ago

This is a subresource with a link back to the parent. The resolution of this in a generic way at compile time is a bit involved. I am looking at options to address this.

viveklak commented 4 years ago

See https://github.com/pulumi/pulumi-azure-nextgen/issues/132 for generic tracker for this.

mikhailshilkov commented 3 years ago

Hopefully, fixed a while back in https://github.com/pulumi/arm2pulumi/issues/2