pulumi/pkg/resource
Mikhail Shilkov fd6853c3f6
Refine autonaming config calculation on provider/resource level (#18034)
Founds the first bug in autonaming configuration... 

Here is my sample program for Azure Native:

```yaml
name: autonaming
description: Autonaming configuration example
runtime: yaml
config:
  pulumi:autonaming:
    value:
      pattern: ${project}-${stack}-${name}
      providers:
        azure-native:
          resources:
            azure-native:storage:StorageAccount:
              pattern: ${project}${stack}${name}${alphanum(6)}
resources:
  rg:
    type: azure-native:resources:ResourceGroup
  sa:
    type: azure-native:storage:StorageAccount
    properties:
      resourceGroupName: ${rg.name}
      sku:
        name: Standard_LRS
      kind: StorageV2
```

Expected result: both resource group and storage account are named as
specified by custom configuration.

Actual result: resource group is named according to our default policy,
not user's configuration.

It starts working correctly if I specify the provider pattern
explicitly:

```yaml
...
pattern: ${project}-${stack}-${name}
  providers:
    azure-native:
      pattern: ${project}-${stack}-${name}
```

It turns out we assign the default config if nothing is specified on the
provider level explicitly, which is wrong: we should use the top-level
"global" config instead.

This PR:

- Changes `resolveNamingConfig` to return a boolean flag of whether an
explicit configuration was found (`false` means we returned a default)
- If `false` is returned on the provider level, then the global
configuration is used
- If `false` is returned on the resource level, then an error is
returned to the user (what were they trying to achieve?)
- While looking at this logic again, I added a check to error if
`enforce` is specified without a `pattern` on any level

Added tests to account for all those use cases, plus a corollary use
case that a user can specify `default` on the provider or resource level
and it will use the default naming, not the parent one.

Fix https://github.com/pulumi/pulumi/issues/18033
2024-12-13 16:01:09 +00:00
..
analyzer Clean up uses of .Error() (#14965) 2023-12-20 15:54:06 +00:00
autonaming Refine autonaming config calculation on provider/resource level (#18034) 2024-12-13 16:01:09 +00:00
deploy Check language plugins in about tests (#18007) 2024-12-11 17:45:19 +00:00
edit Check language plugins in about tests (#18007) 2024-12-11 17:45:19 +00:00
graph Centralize resource state dependency traversal (#17320) 2024-09-23 08:37:34 +00:00
provider Bump gRPC dependencies and migrate `grpc.Dial` (#17701) 2024-11-06 18:36:10 +00:00
stack Enable some more linting rules (#17456) 2024-10-03 17:37:13 +00:00
testdata ci: radical idea - what if slow tests & no stdout makes GH consider runner dead? 2022-03-06 14:52:13 -08:00