https://pulumi.com logo
#azure
Title
# azure
h

handsome-state-59775

04/26/2021, 2:00 PM
How do I bypass autonaming for an azure-native containerservice.ManagedCluster in Python?
1
b

broad-dog-22463

04/26/2021, 2:03 PM
I think you should be able to pass
resource_name
as a param to do that
h

handsome-state-59775

04/26/2021, 2:41 PM
that's not getting rid of the hex suffix 😞
Copy code
cs.ManagedCluster(
            resource_name='aks',
            ...
on azure portal: aks566fe557
b

broad-dog-22463

04/26/2021, 2:42 PM
ok @tall-librarian-49374 any thoughts on overwriting the custom naming?
t

tall-librarian-49374

04/26/2021, 2:44 PM
It must have something to do with
resource_name
parameter vs.
resource_name
property of the resource in Python…
Try
resource_name_
👍 1
h

handsome-state-59775

04/27/2021, 4:27 AM
Works, thanks! If I provide
protect=True
and
delete_before_replace=True
(as I should, I believe, when overriding autonaming?), I expect Pulumi to block any updates to that resource if that update requires replacement - and thus, deletion in this case. Is my intuition correct?
t

tall-librarian-49374

04/27/2021, 5:59 AM
delete_before_replace
is applies automatically if you switch off auto-naming. and yes, protect=true should prevent any deletion.
Btw, I think we recommend using named argument types instead of plain arguments. I think you would avoid that ugly name
resource_name_
in the argument type.
h

handsome-state-59775

04/27/2021, 7:24 AM
not sure I understand what you mean. could you please suggest edits to this snippet?
Copy code
cs.ManagedCluster(
        resource_name=resource_name,
        resource_name_=resource_name,  # Overrides auto-naming
        resource_group_name=resource_group.name,
        ...
t

tall-librarian-49374

04/27/2021, 7:46 AM
sorry, I think I’m dreaming a feature which doesn’t exist yet
😁 1
ignore me
h

handsome-state-59775

04/27/2021, 7:56 AM
delete_before_replace
 is applies automatically if you switch off auto-naming
quoting https://www.pulumi.com/docs/intro/concepts/resources/#autonaming
Overriding auto-naming makes your project susceptible to naming collisions. As a result, for resources that may need to be replaced, you should specify 
deleteBeforeReplace: true
 in the resource’s options. This option ensures that old resources are deleted before new ones are created, which will prevent those collisions.
so which is it?
t

tall-librarian-49374

04/27/2021, 8:19 AM
I think Azure-Native is smart here, but feel free to try with some temporary resource
deleteBeforeReplace: true
has no downside too, so it’s okay to include it
👍 1
h

handsome-state-59775

04/27/2021, 9:11 AM
thanks, makes sense. already including it, just wanted to know the consequences of accidental omission. so, with autonaming overridden and even with an explicit
delete_before_replace=True
,
p state unprotect --all -y && p up -r --show-replacement-steps -y
results in:
Copy code
azure-native:containerservice:ManagedCluster (aks):
    error: cannot create already existing resource '/subscriptions/****/resourceGroups/****/providers/Microsoft.ContainerService/managedClusters/****-aks'
I was expecting this combination of config and commands to let pulumi delete and recreate the resource if necessary. where could i be going wrong?
5 Views