Skip to content

soufantech/pulumi-naming

Repository files navigation


@soufantech/pulumi-naming

Library to simplify and efforces resource naming in Pulumi


typescript-image jest-image npm-image

How to install

Execute command below:

yarn add @soufantech/pulumi-naming

Recommended usage is (see more details in next section):

import * as aws from '@pulumi/aws';
import n from '@soufantech/pulumi-naming';

// Resulting name is: main-dev
const bucket = new aws.s3.Bucket(n());

How to use

Basic: naming

This is the basic component.

// index.ts
import * as aws from '@pulumi/aws';
import { naming } from '@soufantech/pulumi-naming';

const bucketResourceName = naming(
    {
        radical: 'main',
        suffix: 'dev',
    },
    'icon-bucket'
);

const bucket = new aws.s3.Bucket(bucketName); // main-icon-bucket-dev

Factory: createNaming

// index.ts
import * as aws from '@pulumi/aws';
import { createNaming } from '@soufantech/pulumi-naming';

const naming = createNaming({
    radical: 'main',
    suffix: 'dev',
});

const bucket = new aws.s3.Bucket(naming('icon-bucket')); // main-icon-bucket-dev

From config: namingFromConfig

// index.ts
import * as aws from '@pulumi/aws';
import { namingFromConfig as naming } from '@soufantech/pulumi-naming';

const bucket = new aws.s3.Bucket(naming('icon-bucket')); // main-icon-bucket-dev
# Pulumi.dev.yaml
config:
  aws:region: us-east-1
  naming:radical: main
  naming:suffix: dev

*Default export is an alternative to this method

import * as aws from '@pulumi/aws';
import n from '@soufantech/pulumi-naming';

// Resulting name is: main-dev
const bucket = new aws.s3.Bucket(n());

Naming structure

<radical>-<resource-name>-<suffix>

  • radical: project name is a common usage
  • resource-name: required if more than one resource of the same type is created
  • suffix: environment name is a common usage

Options

  • radical: define radical part of name (default: pulumi.getProject())
  • suffix: define suffix part of name (default: undefined)
  • defaultSuffix: use pulumi.getStack() in suffix part of name (default: false)

Built with ❤︎ by SouFan