Skip to content

Commit

Permalink
Autonaming configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailshilkov committed Jan 7, 2025
1 parent 2d7e518 commit 7676e24
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 9 deletions.
105 changes: 105 additions & 0 deletions content/blog/autonaming-configuration/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
title: "Introducing Auto-naming Configuration in Pulumi"
date: 2025-01-16T08:00:00-07:00
meta_desc: "Learn how to configure Pulumi's resource naming to match your organization's naming conventions and requirements across all cloud providers."
meta_image: meta.png
authors:
- mikhail-shilkov
tags:
- features
---

I'm thrilled to announce the release of our auto-naming configuration feature. This highly anticipated capability addresses one of our most requested features [pulumi/pulumi#1518](https://github.com/pulumi/pulumi/issues/1518) and gives you complete control over how Pulumi names your cloud resources.

<!--more-->

## The Journey to Better Resource Naming

Since Pulumi's early days, auto-naming has been a core feature that ensures unique names for cloud resources by generating random name suffixes. While this approach solved many challenges around zero-downtime deployments and stack co-existence, we heard consistently from our community that you needed more control over how your resources are named.

The original [feature request](https://github.com/pulumi/pulumi/issues/1518) I opened in June 2018 has generated extensive discussion, with users sharing various use cases and requirements. Today, I'm happy to finally close that issue with a solution that addresses the community's needs while maintaining Pulumi's robust resource management capabilities.

## Introducing Auto-naming Configuration

With the new auto-naming configuration feature, you now have full control over how Pulumi generates resource names. Here are some common scenarios you can achieve:

### Disable Auto-naming

If you want complete control over your resource names, you can disable auto-naming entirely:

```yaml
pulumi:autonaming:
mode: disabled
```
In this mode, Pulumi will require you to provide explicit physical names for all resources.
### Use Logical Names As-Is
For scenarios where you want Pulumi to copy exactly the logical names to become the physical names, you can use the `verbatim` mode:

```yaml
pulumi:autonaming:
mode: verbatim
```

No random suffixes will be added to the resource names.

Note that when using verbatim names or patterns without random components, resources that need to be replaced will require delete-before-replace behavior, which can lead to downtime.

### Custom Naming Patterns

Create your own naming patterns that combine static text, resource information, and random elements:

```yaml
pulumi:autonaming:
pattern: ${project}-${stack}-${name}${alphanum(6)}
```

See the [auto-naming configuration documentation](/docs/concepts/resources/names/#autonaming-configuration) to see the full list of available expressions.

### Configuration Syntax

The configuration syntax differs slightly depending on where you define it:

In your project file `Pulumi.yaml`:

```yaml
config:
pulumi:autonaming:
value:
mode: verbatim
```

In your stack configuration file `Pulumi.<stack-name>.yaml`:

```yaml
config:
pulumi:autonaming:
mode: verbatim
```

The same applies to other configuration patterns shown above - use the `value:` key in project-level configuration, but omit it in stack-level configuration.

## Getting Started

To use the auto-naming configuration feature, you'll need:

1. Pulumi CLI 3.143.0 or later
2. The following minimum provider versions:
- AWS provider 6.66.0 or later
- Azure Native provider 2.78.0 or later
- Azure Classic provider 6.14.0 or later
- Google Cloud Platform provider 8.11.0 or later

Once you have the required versions installed, simply add your desired auto-naming configuration to your Pulumi configuration file.

For complete documentation and advanced usage scenarios, visit our [auto-naming configuration documentation](/docs/intro/concepts/resources/names/#auto-naming-configuration).

## General Availability

We're excited to announce that the auto-naming configuration feature is now generally available across our major cloud providers. This release marks an important milestone in Pulumi's evolution, delivering a robust and flexible solution for resource naming that our community has been asking for.

Thank you to everyone who participated in the [RFC discussion](https://github.com/pulumi/pulumi/discussions/17592) and preview period and provided valuable feedback. Your input has been invaluable in creating a solution that works for diverse use cases while maintaining Pulumi's core strengths.

If you have any questions or feedback about the auto-naming configuration feature, please don't hesitate to reach out to us on GitHub or in the [Pulumi Community Slack](https://slack.pulumi.com).
Binary file added content/blog/autonaming-configuration/meta.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions content/blog/infrastructure-as-code-resource-naming/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ tags:
- features
---

{{% notes %}}
We've introduced a new way to customize or disable auto-naming with a configuration option. See [Auto-naming Configuration](/blog/autonaming-configuration/) for more information about all the ways you can customize auto-naming.
{{% /notes %}}

"What's in a name? That which we call a rose by any other name would smell as sweet." William Shakespeare's oft repeated quote was used to help Juliet explain that a "Montague" is worthy of love. Juliet may have underestimated the importance of a name, however, since things didn't work out so well for everyone in Verona! Many customers have questions about "names" in Pulumi -- and in an effort to make sure that things work out better for them than they did for Romeo, here's a quick note on naming!

<!--more-->
Expand All @@ -27,6 +31,10 @@ Second, physical names are used in important ways when we update our resources.

## Controlled Naming

{{% notes %}}
We've introduced a new way to customize or disable auto-naming with a configuration option. See [Auto-naming Configuration](/blog/autonaming-configuration/) for more information about all the ways you can customize auto-naming.
{{% /notes %}}

There are times, however, where precise naming is important. You might need to match an existing environment, or want to explicitly control other behavior. If you know for certain that you want to control the naming yourself, you can indeed override auto-naming. Simply specify the physical name on your resource during creation. Most resources expose a `name` property that may be specified in the argument object to the constructor:

```typescript
Expand Down
5 changes: 3 additions & 2 deletions content/blog/pulumi-recommended-patterns-the-basics/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Now we're all set, so let's dive into writing a Pulumi application.

The first thing you'll notice when you write a Pulumi app is that every single resource must have its own name. This *Pulumi resource name*, or a logical resource name if you prefer, is used inside your stack state file to uniquely identify your resources. This name is also what you will find at first when exploring your stack resources in the Pulumi web console.

Depending on the resource type, a second name (a *cloud resource name* or a *physical resource name* if you like) may also be provided. This name will be what is used in your cloud vendor's web console. If this *cloud resource name* is unspecified, Pulumi uses the *Pulumi resource name* and appends a [random suffix](/docs/concepts/resources#autonaming) to it to make it unique.
Depending on the resource type, a second name (a *cloud resource name* or a *physical resource name* if you like) may also be provided. This name will be what is used in your cloud vendor's web console. If this *cloud resource name* is unspecified, Pulumi uses the *Pulumi resource name* and appends a [random suffix](/docs/concepts/resources/names/#autonaming) to it to make it unique.

As a recommendation, you should use explicit names for all your *Pulumi resource names* and then let Pulumi determine what the *cloud resource names* should be. Let's explore the benefits:

Expand All @@ -88,7 +88,8 @@ Along with this recommendation, using a unique prefix in the name of your resour

Here are a few links to understand physical names and auto-naming a bit better:

* [Resources and auto-naming](/docs/concepts/resources#autonaming)
* [Resources and auto-naming](/docs/concepts/resources/names/#autonaming)
* [Auto-naming Configuration](/docs/concepts/resources/names/#autonaming-configuration)
* [Infrastructure as Code Resource Naming](/blog/infrastructure-as-code-resource-naming/)
* [Why do resource names have random hex character suffixes?](/docs/support/faq#why-do-resource-names-have-random-hex-character-suffixes)

Expand Down
2 changes: 1 addition & 1 deletion content/blog/pulumi-release-notes-m64/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class Program

### AWS Native provider supports auto-naming

Most Pulumi providers support [auto-naming for resources](/docs/concepts/resources#autonaming), which makes it easier to have multiple stacks of the same Pulumi program by avoiding naming conflicts, among other benefits. Now, our AWS Native provider joins the club with full auto-naming support.
Most Pulumi providers support [auto-naming for resources](/docs/concepts/resources/names/#autonaming), which makes it easier to have multiple stacks of the same Pulumi program by avoiding naming conflicts, among other benefits. Now, our AWS Native provider joins the club with full auto-naming support.

[Learn more about AWS auto-naming in this GitHub issue](https://github.com/pulumi/pulumi-aws-native/issues/156)
Expand Down
4 changes: 2 additions & 2 deletions content/docs/iac/concepts/how-pulumi-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ stack mystack
- aws.s3.BucketV2 "content-bucket125ce"
```

Note the extra suffixes on the end of these bucket names. This is due to a process called [auto-naming](/docs/concepts/resources#autonaming), which Pulumi uses by default in order to allow you to deploy multiple copies of your infrastructure without creating name collisions for resources. This behavior can be disabled if desired.
Note the extra suffixes on the end of these bucket names. This is due to a process called [auto-naming](/docs/concepts/resources/names/#autonaming), which Pulumi uses by default in order to allow you to deploy multiple copies of your infrastructure without creating name collisions for resources. This behavior can be disabled if desired.

Now, let's make a change to one of resources and run `pulumi up` again. Since Pulumi operates on a desired state model, it will use the last deployed state to compute the minimal set of changes needed to update your deployed infrastructure. For example, imagine that we wanted to add tags to the S3 `media-bucket`. We change our program to express this new desired state:

Expand Down Expand Up @@ -461,7 +461,7 @@ This time, the engine will not need to make any changes to `media-bucket` since

Pulumi executes resource operations in parallel whenever possible, but understands that some resources may have dependencies on other resources. If an [output](/docs/concepts/inputs-outputs/) of one resource is provided as an input to another, the engine records the dependency between these two resources as part of the state and uses these when scheduling operations. This list can also be augmented by using the [dependsOn](/docs/concepts/resources#dependson) resource option.

By default, if a resource must be replaced, Pulumi will attempt to create a new copy of the resource before destroying the old one. This is helpful because it allows updates to infrastructure to happen without downtime. This behavior can be controlled by the [deleteBeforeReplace](/docs/concepts/resources#deletebeforereplace) option. If you have disabled [auto-naming](/docs/concepts/resources#autonaming) by providing a specific name for a resource, it will be treated as if it was marked as `deleteBeforeReplace` automatically (otherwise the create operation for the new version would fail since the name is in use).
By default, if a resource must be replaced, Pulumi will attempt to create a new copy of the resource before destroying the old one. This is helpful because it allows updates to infrastructure to happen without downtime. This behavior can be controlled by the [deleteBeforeReplace](/docs/concepts/resources#deletebeforereplace) option. If you have disabled [auto-naming](/docs/concepts/resources/names/#autonaming) using configuration or by providing a specific name for a resource, it will be treated as if it was marked as `deleteBeforeReplace` automatically (otherwise the create operation for the new version would fail since the name is in use).

## Declarative and imperative approach

Expand Down
2 changes: 1 addition & 1 deletion content/docs/iac/concepts/options/import.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,6 @@ For this to work, your Pulumi stack must be configured correctly. In this exampl
If the resource’s arguments differ from the imported state, the import will fail. You will receive this message: `warning: inputs to import do not match the existing resource; importing this resource will fail`. Select “details” in the `pulumi up` preview to learn what the differences are. If you try to proceed without correcting the inconsistencies, you will see this message: `error: inputs to import do not match the existing resource`. To fix these errors, make sure that your program computes a state that completely matches the resource to be imported.

Because of auto-naming, it is common to run into this error when you import a resource’s name property. Unless you explicitly specify a name, Pulumi will auto-generate one, which is guaranteed not to match, because it will have a random hex suffix. To fix this problem, explicitly specify the resource’s name [as described here](/docs/iac/concepts/resources/names/#autonaming). Note that, in the example for the EC2 security group, the name was specified by passing `web-sg-62a569b` as the resource’s name property.
Because of auto-naming, it is common to run into this error when you import a resource’s name property. Unless you explicitly specify a name, Pulumi will auto-generate one, which is guaranteed not to match, because it will have a random hex suffix. To fix this problem, explicitly specify the resource’s name or disable auto-naming [as described here](/docs/iac/concepts/resources/names/#autonaming-configuration). Note that, in the example for the EC2 security group, the name was specified by passing `web-sg-62a569b` as the resource’s name property.

Once a resource is successfully imported, remove the `import` option because Pulumi is now managing the resource.
2 changes: 1 addition & 1 deletion content/docs/iac/concepts/resources/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ resources:
{{< /chooser >}}
All resources have a required [`name`](/docs/concepts/resources/names) argument, which must be unique across resources of the same kind in a [`stack`](/docs/concepts/stack). This *logical name* influences the *physical name* assigned by your infrastructure’s cloud provider. Pulumi [auto-names](/docs/concepts/resources/names#autonaming) physical resources by default, so the physical name and the logical name may differ. This auto-naming behavior can be overridden, if required.
All resources have a required [`name`](/docs/concepts/resources/names) argument, which must be unique across resources of the same kind in a [`stack`](/docs/concepts/stack). This *logical name* influences the *physical name* assigned by your infrastructure’s cloud provider. Pulumi [auto-names](/docs/concepts/resources/names/#autonaming) physical resources by default, so the physical name and the logical name may differ. This auto-naming behavior can be overridden, if required.

The `args` argument is an object with a set of named property input values that are used to initialize the resource. These can be normal raw values—such as strings, integers, lists, and maps—or [outputs](/docs/concepts/inputs-outputs/) from other resources. Each resource has a number of named input properties that control the behavior of the resulting infrastructure. To determine what arguments a resource supports, refer to that resource’s API documentation in the [Registry](/registry/).

Expand Down
Loading

0 comments on commit 7676e24

Please sign in to comment.