If I use an explicit provider (e.g. aws.Provder()) and then change its name it leads to all resources that use it being replaced. I tried to use aliases to prevent this, but aliasing the provider seems to have no effect and all resources still get replaced.
I've reproduced this across TypeScript and Go with Pulumi.
pulumi-ts-provider-alias % pulumi version
v1.11.0
pulumi-ts-provider-alias % npm ls --depth 0
pulumi-ts-provider-alias@ /Users/clstokes/cc/scratch/pulumi-ts-provider-alias
├── @pulumi/[email protected]
├── @pulumi/[email protected]
├── @pulumi/[email protected]
└── @types/[email protected]
up the code belowproviderName value to "name2"pulumi preview --diff and see the bucket will be replaced because the provider changes.import * as aws from "@pulumi/aws";
const providerName = "name2";
const awsProvider = new aws.Provider(providerName, {
region: "us-west-2",
}, { aliases: [{ name: "name1" }]});
// }, { aliases: ["urn:pulumi:dev::pulumi-ts-provider-alias::pulumi:providers:aws::name1"] });
const bucket = new aws.s3.Bucket("my-bucket", {}, { provider: awsProvider });
export const bucketName = bucket.id;
preview --diff output after provide name changepulumi-ts-provider-alias % pulumi preview --diff
Previewing update (dev):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:dev::pulumi-ts-provider-alias::pulumi:pulumi:Stack::pulumi-ts-provider-alias-dev]
+-aws:s3/bucket:Bucket: (replace)
[id=my-bucket-a797c6e]
[urn=urn:pulumi:dev::pulumi-ts-provider-alias::aws:s3/bucket:Bucket::my-bucket]
[provider: urn:pulumi:dev::pulumi-ts-provider-alias::pulumi:providers:aws::name1::577bc71c-4473-4681-a2ef-6ba5f38fbed1 => urn:pulumi:dev::pulumi-ts-provider-alias::pulumi:providers:aws::name2::577bc71c-4473-4681-a2ef-6ba5f38fbed1]
- accelerationStatus : ""
acl : "private"
- arn : "arn:aws:s3:::my-bucket-a797c6e"
~ bucket : "my-bucket-a797c6e" => "my-bucket-6e9c422"
- bucketDomainName : "my-bucket-a797c6e.s3.amazonaws.com"
- bucketRegionalDomainName: "my-bucket-a797c6e.s3.us-west-2.amazonaws.com"
- corsRules : []
forceDestroy : false
- hostedZoneId : "Z3BJ6K6RIION7M"
- id : "my-bucket-a797c6e"
- lifecycleRules : []
- loggings : []
- region : "us-west-2"
- requestPayer : "BucketOwner"
- tags : {}
- versioning : {
- enabled : false
- mfaDelete: false
}
--outputs:--
~ bucketName: "my-bucket-a797c6e" => output<string>
Resources:
+-1 to replace
2 unchanged
Permalink: https://app.pulumi.com/clstokes/pulumi-ts-provider-alias/dev/previews/73e4816a-b850-4305-9ac7-07d720efa49c
Not only does rename not work, reparenting also doesn't work, and what's worse, renaming (name/type) or reparenting of a ComponentResource which the provider is referencing as parent also doesn't work, making stacks quite inflexible for refactoring.
Workaround for now is to carefully stack export and stack import (backups, small steps, sed).
Ran into this on yet another occasion. Try to refactor a resource hierarchy when one of the resources that moves is a provider. Specifically, try moving around an eks.Cluster (eg. from top level into a component resource). It’ll work almost, (when adding aliases: [{parent: pulumi.rootStackResource}] to the eks.Cluster resource), but you can’t move the nodeAccess configmap, because it can’t find its kubernetes provider which is a cluster output (it’s trying to use the new provider that you don’t have yet).
As mentioned, it seems aliasing doesn't propagate properly for the provider field on dependent resources (which is essentially an independent, parallel hierarchy to the one formed by parent relationships).
And ran into it again. Could we please have some kind of statement of how to deal with this issue. It makes pulumi very unpleasant to work with.
Most helpful comment
Not only does rename not work, reparenting also doesn't work, and what's worse, renaming (name/type) or reparenting of a ComponentResource which the provider is referencing as parent also doesn't work, making stacks quite inflexible for refactoring.
Workaround for now is to carefully
stack exportandstack import(backups, small steps,sed).