https://pulumi.com logo
#python
Title
# python
a

average-school-38756

02/11/2021, 4:05 PM
Am i misunderstanding aliases? A resource with
name="my-name"
shows no changes detected for
pulumi up
, yet that same resource with
opts=ResourceOptions(aliases=[Alias(name="my-name")]}
instead wants to do a "replace" based on a detected name change
r

red-match-15116

02/11/2021, 4:34 PM
Hey! Not sure what you’re hitting here, but there’s some details on aliases in our programming model docs.
a

average-school-38756

02/11/2021, 4:40 PM
do i have to explicitly declare a new
name
value when i move the old one to
aliases
? can't transition to auto-generated names?
r

red-match-15116

02/11/2021, 8:31 PM
Huh, good question. Do you have a code sample where this is failing? Auto-naming happens for specific properties of a resource, not the resource name. The resource name is always required. So for instance:
bucket = s3.Bucket("my-bucket")
would use autonaming to create a bucket named
my-bucket-[random-integers]
If you wanted to change the resource name of the bucket without replacing it you would do something like:
bucket = s3.Bucket("new-bucket-name", opts=ResourceOptions(aliases=[Alias(name="my-bucket")])
a

average-school-38756

02/11/2021, 8:57 PM
Originally, it was:
Copy code
aws.dynamodb.Table(
    "foo",
    attributes=[aws.dynamodb.TableAttributeArgs(name="bar", type="S")],
    hash_key="bar",
    billing_mode="PAY_PER_REQUEST",
    opts=pulumi.ResourceOptions(
        protect=True
    ),
)
Then a resource called "foo-e876689" was created. After successfully importing the resource into a new project/stack, i wanted to remove the explicit
name
value, to keep the code generic. i tried using aliases for this:
Copy code
aws.dynamodb.Table(
    "foo",
    attributes=[aws.dynamodb.TableAttributeArgs(name="bar", type="S")],
    hash_key="bar",
    billing_mode="PAY_PER_REQUEST",
    opts=pulumi.ResourceOptions(
        protect=True, aliases=[pulumi.Alias(name="foo-e876689")]
    ),
)
But if i remove
name="foo-e876689"
it doesn't know to not replace, even with the alias defined. Only this works:
Copy code
aws.dynamodb.Table(
    "foo",
    name="foo-e876689",
    attributes=[aws.dynamodb.TableAttributeArgs(name="bar", type="S")],
    hash_key="bar",
    billing_mode="PAY_PER_REQUEST",
    opts=pulumi.ResourceOptions(
        protect=True,
    ),
)
i'm thinking aliases work for "foo" Pulumi resource name and not for the AWS resource name?
If that's the case, how to i get the Pulumi state to keep the name of the existing resource and still not have it defined in my code (since in that case, i couldn't spin up multiple stacks for the same project without name clobbering in AWS?)
Even the URN format for aliases is stack-specific
r

red-match-15116

02/11/2021, 9:40 PM
I think you might be able to use the ignoreChanges resource option for the
name
property.
a

average-school-38756

02/11/2021, 9:40 PM
i will take a look- thanks
this seems to work quite well
🎉 1
2 Views