Hi, is there a way to achieve a subsctring in auto...
# general
p
Hi, is there a way to achieve a subsctring in autonaming pattern? I'm creating an Azure Storage accounts that I would like to be autonamed, but I need to ensure the maximum length of 24 characters, so I would need something like
${substr(name,20)}${alphanum(4)}
. Thanks
s
You can configure custom autonaming to accomplish this: https://www.pulumi.com/docs/iac/concepts/resources/names/#custom-naming-pattern
p
Hi @stocky-restaurant-98004! That's what I'm aiming to use, but can you please show me a sample with the substring / length limiting specifically? I cant find it in the documentation. Thanks!
s
Oh, I see. Try something like
${name(20)}-${alphanum(4)}
or maybe a couple of variants. If that works, let me know and I'll submit a PR so the docs shows this is actually supported, but not documented. If that does not work, submit a feature request in GH to
pulumi/pulumi
.
p
OK, thanks a lot
👍 1
s
Let me know how this goes b/c this should be supported IMO.
p
Hi Josh, unfortunately it doesnt work. Here is the autonaming config:
Copy code
pulumi:autonaming:
    value:
      pattern: ${name}-${config.suffix}-${alphanum(1)}
      providers:
        azure-native:
          resources:
            "azure-native:storage:StorageAccount":
              pattern: ${name}${alphanum(1)}
That works, however when the logical name is too long, it fails with:
Copy code
error: azure-native:storage:StorageAccount resource 'storagetest12345678901234567890' has a problem: 'accountName' is too long (31): at most 24 characters allowed
And when I put the pattern:
Copy code
"azure-native:storage:StorageAccount":
              pattern: ${name(20)}${alphanum(1)}
I get the following:
Copy code
error: azure-native:storage:StorageAccount resource 'storagetest12345678901234567890' has a problem: 'accountName' does not match expression '^[a-z0-9]+$'
Which showcases that the error does not include the autogenerated name, but rather the logical name (and I cannot access the autogenerated name to check what went wrong even in the debug). And also it makes me believe that the macro
${name(20)}
is resolved into
name(20)
or something like that instead of returning the substring.
s
Submit a feature request here. I think this is a good feature. https://github.com/pulumi/pulumi/issues
(unless there's some edge case that I'm not considering that would make this infeasible)
p