简体   繁体   中英

How do I migrate a Pulumi Azure resource to Azure-Nextgen?

I'm trying to migrate the pulumi code for an Azure storage account (which was originally created with the legacy Azure provider) to the Azure-Nextgen provider. The Aliases property isn't working as expected. Is this possible, or am I missing something obvious?:

Original:

var storageAccount = new Account($"storage_{storageName}", new AccountArgs
    {
        Name = $"{storageName}",
        ResourceGroupName = resourceGroup.Name,
        AccountReplicationType = "LRS",
        AccountTier = "Standard",
        Location = resourceGroup.Location,
        IsHnsEnabled = true,
        MinTlsVersion = "TLS1_2"
    },
    new CustomResourceOptions()
    {
        Protect = true
    });

New:

var storageAccount = new StorageAccount($"storage_{storageName}",
    new StorageAccountArgs()
    {
        AccountName = $"{storageName}",
        Location = location,
        ResourceGroupName = resourceGroup.Name,
        Kind = Kind.StorageV2,
        AccessTier = AccessTier.Hot,
        Sku = new SkuArgs()
        {
            Name = SkuName.Standard_LRS
        },
        IsHnsEnabled = true,
        MinimumTlsVersion = MinimumTlsVersion.TLS1_2
    },
    new CustomResourceOptions()
    {
        Protect = true,
        Aliases =
        {
            new Alias
            {
                Urn = "urn:pulumi:myEnvironment::myStack::azure:storage/account:Account::storage_storageName"
            }
        }
    });

Pulumi preview in console:

azure:storage:Account (storage_storageName):
    error: Preview failed: refusing to delete protected resource 'urn:pulumi:myEnvironment::myStack::azure:storage/account:Account::storage_storageName'

Aliases don't work across providers. The shape of resources in the "classic" Azure provider differs from the next-gen native Azure provider, so the state is not compatible.

You would have to follow the following manual process:

  1. Import the existing storage account as a new resource with NextGen

    pulumi import azure-nextgen:storage/latest:StorageAccount storage /subscriptions/01234567-89ab-cdef-0123-456789abcdef/resourceGroups/my-rgca05c9f8/providers/Microsoft.Storage/storageAccounts/storagea791686
  2. The command above would import the state and print out the code for you. Copy the code to your program.

  3. Now, delete the old resource from your state (not from Azure)

    pulumi state delete urn:pulumi:dev::ts::azure:storage/account:Account::storage
  4. Remove the old resource from your Pulumi program.

  5. Run pulumi up to make sure everything is working. You should see no changes.

There is a migration guide coming in the next couple of weeks, I'll update this answer with a link when it's out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM