How do I bypass autonaming for an azure-native con...
# azure
h
How do I bypass autonaming for an azure-native containerservice.ManagedCluster in Python?
1
b
I think you should be able to pass
resource_name
as a param to do that
h
that's not getting rid of the hex suffix 😞
Copy code
cs.ManagedCluster(
            resource_name='aks',
            ...
on azure portal: aks566fe557
b
ok @tall-librarian-49374 any thoughts on overwriting the custom naming?
t
It must have something to do with
resource_name
parameter vs.
resource_name
property of the resource in Python…
Try
resource_name_
👍 1
h
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
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
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
sorry, I think I’m dreaming a feature which doesn’t exist yet
😁 1
ignore me
h
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
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
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?