Skip to content

Pulumi YAML reference ​

Pulumi programs can be defined in many languages, and the Pulumi YAML dialect offers an additional language for authoring Pulumi programs.

Pulumi supports programs written in YAML or JSON. In both cases, the programs (.yaml or .json files) follow a schema with five top-level sections:

PropertyTypeRequiredExpressionDescription
configconfig optionsNoNoConfig specifies the Pulumi config inputs to the deployment.
resourcesmap[string]ResourceNoNoResources declares the Pulumi resources that the program deploys and manages.
variablesmap[string]ExpressionNoYesVariables specifies intermediate values of the program. The values of variables are expressions that can be reused.
outputsmap[string]ExpressionNoYesOutputs specifies the Pulumi stack outputs of the program and how they are computed from the resources.
pulumimap[string]ExpressionNoNoConfiguration of the Pulumi CLI.

In many locations within this schema, values may be expressions that compute a value based on the config, variables, or outputs of resources. These expressions can be provided in two ways:

  • If an object is provided as a value, and has a key that has the prefix fn::, the object is treated as an expression, and the expression is resolved to a new value that is used in place of the object.
  • Any string value is interpreted as an interpolation, with ${...} being replaced by evaluating the expression in the ....

The supported expression forms for each of these are detailed in Expressions.

Config ​

INFO

Pulumi YAML programs declare config using the same project-level config schema documented in the Pulumi project file reference. The schema is shown again here for convenience, alongside YAML-flavored examples.

config is a map of config property keys to either values or structured declarations. The value of config is an object whose keys are logical names by which the config input is referenced in expressions within the program, and whose values are elements of the schema below. Each item in this object represents an independent config input. Either type or default is required; when type is omitted, the type is inferred from default.

A config key in the project's own namespace can also map directly to a scalar or array value as a shorthand for a structured declaration with only default set. For example, replicas: 3 is equivalent to replicas: { default: 3 }. A key namespaced by another package, such as aws:region: us-west-2, sets that key's value instead.

PropertyTypeRequiredExpressionDescription
typestringNoNoThe data type for the config value. Valid types are: string, boolean, integer, array, and object.
itemsobjectRequired if type is arrayNoA nested structured declaration that describes each item in the array.
defaultanyNoNoA default value of the appropriate type for the program to use if no value is set on the stack.
secretboolNoNoWhen true, the config value is encrypted as a secret. Secret values must be set with pulumi config set --secret.

WARNING

In beta, Pulumi YAML projects used a top-level configuration key, which accepted a different schema with Title-Case types — String, Number, Integer, Boolean, Object, and the generic forms List<String>, List<Number>, List<Integer>, List<Boolean>, and List<Object>. Programs that still use configuration continue to work, but the YAML runtime emits a deprecation warning when it loads Pulumi.yaml. New programs should use config with the schema above; the array + items form replaces List<T>, and number is not a separate type (use integer).

The following example demonstrates several common config declarations, including scalar types, secrets, lists, and objects:

yaml
name: my-project
runtime: yaml
config:
  # Shorthand for a default value (type inferred from the value)
  greeting: hello
  # A required string value (no default)
  environment:
    type: string
  # An integer with a default
  replicas:
    type: integer
    default: 3
  # A boolean flag with a default
  enableLogging:
    type: boolean
    default: true
  # A required secret string (set with `pulumi config set --secret`)
  databasePassword:
    type: string
    secret: true
  # A list of strings
  allowedRegions:
    type: array
    items:
      type: string
    default:
      - us-east-1
      - us-west-2
  # An object (map of string keys to any values)
  apiConfig:
    type: object
    default:
      endpoint: https://api.example.com
      timeout: 30
resources:
  my-bucket:
    type: aws:s3:BucketV2
    properties:
      tags:
        Environment: ${environment}
outputs:
  # Reference the whole object or individual properties using dot notation
  apiEndpoint: ${apiConfig.endpoint}

Config values are set using pulumi config set for scalar types, pulumi config set --path for nested object properties, and pulumi config set --secret for secrets. They are referenced in your program using ${configKey} interpolation expressions, with dot notation (${configKey.property}) for accessing properties within object-typed values.

Resources ​

The value of resources is an object whose keys are logical resource names by which the resource is referenced in expressions within the program, and whose values are elements of the schema below. Each item in this object represents a resource that the Pulumi program manages.

PropertyTypeRequiredExpressionsDescription
typestringYesNoType is the Pulumi type token for this resource.
defaultProviderboolNoNoDefaultProvider specifies if a provider should be used for resources without an explicit one set. Set only on provider resources.
propertiesmap[string]ExpressionNoYesProperties contains the primary resource-specific keys and values to initialize the resource state.
optionsResource optionsNoNoOptions contains all resource options supported by Pulumi.
getResource GetterNoYesA getter function for the resource. Supplying get is mutually exclusive to properties.

Resource options ​

The value of the options property of a Resource is an object whose keys are resource option names and whose values are elements of the schema below. No resource options are required.

The dependsOn, parent, provider, and providers values permit expressions which must use interpolation syntax to reference resources by name. For example:

yaml
    options:
      provider: ${myEksProvider}
      providers:
        - ${myAwsProvider}
      dependsOn:
        - ${otherResource}
      parent: ${someParentResource}
PropertyTypeDescription
additionalSecretOutputsstring[]AdditionalSecretOutputs specifies properties that must be encrypted as secrets
aliasesstring[]Aliases specifies names that this resource used to have, so that renaming or refactoring doesn’t replace it
customTimeoutsCustom TimeoutCustomTimeouts overrides the default retry/timeout behavior for resource provisioning
deleteBeforeReplaceboolDeleteBeforeReplace overrides the default create-before-delete behavior when replacing
dependsOnExpression[]DependsOn makes this resource explicitly depend on another resource, by name, so that it won't be created before the dependent finishes being created (and the reverse for destruction). Normally, Pulumi automatically tracks implicit dependencies through inputs/outputs, but this can be used when dependencies aren't captured purely from input/output edges.
ignoreChangesstring[]IgnoreChanges declares that changes to certain properties should be ignored during diffing
importstringImport adopts an existing resource from your cloud account under the control of Pulumi
parentExpressionParent specifies a parent for the resource
protectboolProtect prevents accidental deletion of a resource
providerExpressionProvider specifies an explicitly configured provider, instead of using the default global provider
providersExpression[]List of providers for a resource and its children.
versionstringVersion specifies a provider plugin version that should be used when operating on a resource
pluginDownloadURLstringPluginDownloadURL specifies a provider plugin download URL
replaceOnChangesstring[]ReplaceOnChanges specifies if changes to certain properties on a resource should force replacement instead of an in-place update.
retainOnDeleteboolRetainOnDelete causes a resource to be preserved in the cloud even when it is deleted from the Pulumi state.
replaceWithExpression[]ReplaceWith makes this resource be replaced whenever any of the listed resources are replaced.
deletedWithExpressionDeletedWith skips deleting this resource when the referenced resource is deleted in the same operation.
hideDiffsstring[]HideDiffs lists properties whose diffs are hidden in CLI output.
replacementTriggerExpressionReplacementTrigger replaces the resource whenever the value of the expression changes.
envVarMappingsmap[string]stringEnvVarMappings remaps environment variables to the keys a provider reads, for explicitly configured providers.

Resource getter ​

Supplying a get key turns the resource declaration into a getter function.

PropertyTypeRequiredDescription
idstringYesThe ID of the resource to import
statemap[string]ExpressionNoKnown properties (input & output) of the resource. This assists the provider in figuring out the correct resource.

Custom timeout ​

The optional customTimeouts property of a resource is an object of the following schema:

PropertyTypeRequiredExpressionDescription
createstringNoNoCreate is the custom timeout for create operations.
deletestringNoNoDelete is the custom timeout for delete operations.
updatestringNoNoUpdate is the custom timeout for update operations.

Providers and provider versions ​

Explicitly defining providers in YAML, or explicitly setting their versions when creating resources, is useful for at least two reasons:

  1. Using explicit versions enables pinning the dependencies used, a technique used to improve build reliability.
  2. Using explicit providers enables controlling the options for providers used by each resource, as described in Unlock Programmatic Control by Disabling Default Providers.

If a specific provider version is necessary, use the following approaches, listed in order of preference.

Default provider ​

Declaring a default provider simplifies configuring a provider version across all resources for that provider.

To configure the default provider instance for all resources for that provider's name, use the resources section to declare a provider resource.

For the type property, prefix the name of the provider with pulumi:providers, for example, pulumi:providers:aws. Setting the defaultProvider property to true, defined at the same level as type, configures this as a default provider.

yaml
resources:
  aws-provider:
    type: pulumi:providers:aws
    defaultProvider: true
    options:
      version: 6.45.0
  my-bucket:
    type: aws:s3:Bucket

In this example the my-bucket resource, and any other AWS resources, uses the default AWS provider version 6.45.0.

Only one provider of a given type can be declared as the default provider.

Explicit provider ​

To declare an explicit provider instance for specific resources, declare a provider resource in the resources section. For the type property, prefix the name of the provider with pulumi:providers.

yaml
resources:
  provider:
    type: pulumi:providers:azure
    options:
      version: 5.1.0

The provider instance can then be used as described in section Resource options by setting the provider option:

yaml
resources:
  provider:
    type: pulumi:providers:azure
    options:
      version: 5.1.0
  rg:
    type: azure:core:ResourceGroup
    properties:
      location: WestEurope
    options:
      provider: ${provider}

Explicit providers take precedence over default providers.

Resource version ​

To declare a resource with a specific provider version use the version option as described in Resource options:

yaml
resources:
  something:
    type: aws:s3:Bucket
    properties:
      ...
    options:
      version: 5.6.0

Third-party providers ​

Third-party providers may require a pluginDownloadURL option for Pulumi to download the provider plugin. The publisher of that provider should provide this URL, following the guide to publishing packages.

Each of the preceding ways to set a version (on a default provider, on an explicit provider, or on individual resources) can be combined with the pluginDownloadURL option to use a third-party provider.

This declares one of Pulumi's own providers as a default provider, setting an explicit pluginDownloadURL.

yaml
resources:
  aws-provider:
    type: pulumi:providers:aws
    defaultProvider: true
    options:
      version: 6.45.0
      pluginDownloadURL: github://api.github.com/pulumi
  my-bucket:
    type: aws:s3:Bucket

Variables ​

The value of variables is an object whose keys are logical names and whose values are expressions. Variables hold intermediate values that you can reuse throughout the program. Config, variables, and resource keys all exist in a single namespace, and you reference a variable with ${name} interpolation, just like config values and resources. A variable can also reference other variables.

yaml
config:
  environment:
    type: string
variables:
  bucketPrefix: app-${environment}
  commonTags:
    Environment: ${environment}
resources:
  my-bucket:
    type: aws:s3:BucketV2
    properties:
      bucketPrefix: ${bucketPrefix}
      tags: ${commonTags}

Outputs and stack references ​

The value of outputs is an object whose keys are the logical names of the outputs that are available from outside the Pulumi stack (via pulumi stack output), and whose values are potentially computed expressions that resolve to the values of the desired outputs.

yaml
outputs:
  outputName: ${resource.id}

Stack references can be used to access the outputs of one stack from within another stack. A stack reference requires the fully qualified name of the stack as an argument in the format of <organization>/<project>/<stack>.

yaml
resources:
  reference:
    type: pulumi:pulumi:StackReference
    properties:
      name: org/project/stack

outputs:
  secondOutputName: ${reference.outputs["outputName"]}

The secondOutputName output has the value of the outputName output from the stack org/project/stack.

Pulumi CLI configuration ​

The pulumi section configures the Pulumi CLI. The requiredVersion option specifies the version range of the Pulumi CLI that this project requires. The format follows the syntax of semantic version ranges. This option is useful when your program requires a newer feature and you want to ensure the program doesn't run with a CLI that is too old.

yaml
pulumi:
  requiredVersion: ">=3.0.0 !3.1.2"

This configuration requires a Pulumi CLI version that is at least 3.0.0 but not 3.1.2. If run with a version outside this range, the program exits with an error.

Expressions ​

Expressions can be used in several contexts:

  • the properties of properties of resources
  • the properties of options of resources that take references to other resources: parent, dependsOn, provider, and providers
  • the values of variables and outputs
  • some or all values provided to built-in functions, as specified below

Generally speaking, most values permit an expression, and exceptions are documented as not permitting an expression.

In these contexts, you can provide any JSON/YAML value. Pulumi interpolates a string value, and evaluates an object that has a key with a prefix of fn:: as an expression.

Interpolation ​

In expression locations, strings are evaluated as interpolations and any nested ${...} expressions within the string value are replaced by the value of the expression .... The syntax of expressions within interpolations permits property access only.

To use ${} in a string literal, escape $ with $$ like so:

yaml
variables:
  plainString: $${value}

A string like Hello, ${foo} converts the expression foo to a string.

If a string contains only an ${...} expression, it's considered a substitution.

Property access ​

Within an expression denoted by ${...} property access is permitted according to the forms below. Config, variables, and resource keys all exist in a single namespace, and in the examples, root or equivalent must be the name of one of these items, and it must be valid to access the foo property of that item if it's a map or object, or if it's an array, the index must be valid.

  • ${root}
  • ${root.foo}
  • ${root["foo"]}
  • ${root.bar.quux}
  • ${root["bar"].quux}
  • ${root["bar"]["quux"]}
  • ${root[0]}
  • ${root[100]}
  • ${root[0].foo}
  • ${root[0][1].foo}
  • ${root.foo.items[0].bar[1]}
  • ${root["key with \"escaped\" quotes"]}
  • ${root["key with a ."]}
  • ${["root key with \"escaped\" quotes"].foo}
  • ${["root key with a ."][100]}

We have not discussed types until now, but implicitly every expression has a type, such as number, string, map, array, or even resource. When interpolated, these values must become strings, otherwise they are substituted in. Additionally:

  • maps must have string keys and expression values
  • arrays have non-negative integer indices and expression values
  • property access on a Resource retrieves outputs

Substitution ​

Expressions denoted by ${...} are only converted to strings when interpolated into a string with surrounding text. If a resource property takes a list or a map for example, that can be provided by a variable whose value can be substituted in. In the following example, the httpPort variable is used to reduce repetition in the two Kubernetes Service resources.

yaml
name: kubernetes-port-example
runtime: yaml
variables:
  httpPort:
    protocol: TCP
    port: 80
    targetPort: 8000
resources:
  serviceOne:
    type: kubernetes:core/v1:Service
    properties:
      spec:
        selector:
          app: "MyApp"
        ports:
          - ${httpPort}
  serviceTwo:
    type: kubernetes:core/v1:Service
    properties:
      spec:
        selector:
          app: "OtherApp"
        ports:
          - ${httpPort}

The last two lines are equivalent as if the variable were substituted for its value:

yaml
        ports:
          - protocol: TCP
            port: 80
            targetPort: 8000

Built-in functions ​

In any expression location, an object containing a single key beginning with fn:: calls a built-in function.

fn::toBase64 ​

Converts a UTF-8 string into a Base64 encoded string using the standard encoding.

yaml
variables:
  greeting:
    fn::toBase64: "Hello, world!"

The expression ${greeting} returns SGVsbG8sIHdvcmxkIQ==.

fn::fromBase64 ​

Converts a Base64 encoded string into a UTF-8 string. This fails if the result is not a valid UTF-8 string.

yaml
variables:
  greeting:
    fn::fromBase64: SGVsbG8sIFdvcmxkIQ==

The expression ${greeting} returns Hello, World!.

fn::toJSON ​

Converts a value into its JSON representation.

yaml
variables:
  item:
    fn::toJSON:
      key1: value1
      key2: 123

The expression ${item} returns the JSON string {"key1":"value1","key2":123}.

fn::invoke ​

Calls a function from a package and returns either the whole object or a single field if given the return property. This can be any of the functions in the registry providers as well as functions found in the pulumi-std package that includes math functions such as sum and abs, logic functions such as anytrue, and string functions such as split.

The schema is:

PropertyTypeRequiredExpressionDescription
functionstringYesNoName of a function to call.
argumentsmap[string]ExpressionYesYesArguments to pass to the expression, each key is a named argument.
optionsInvoke optionsNoNoOptions for the provider calling the function.
returnstringNoNoReturn the value of the field with this name.

Example calling the getAmi function in the AWS provider package:

yaml
variables:
  AmazonLinuxAmi:
    fn::invoke:
      function: aws:ec2:getAmi
      arguments:
        filters:
          - name: name
            values: ["al2023-ami-2023.*-x86_64"]
        owners: ["137112412989"]
        mostRecent: true
      return: id

The expression ${AmazonLinuxAmi} returns the AMI ID returned from the aws:ec2:getAmi function.

Example calling the sum function in the pulumi-std provider package to subtract 255 from ${route53Weight}:

yaml
variables:
  route53Weight: 400
  modifiedWeight:
    fn::invoke:
      function: std:sum
      arguments:
        input:
          - ${route53Weight}
          - -255
      return: result

The expression ${modifiedWeight} returns 145 in this case.

Invoke options ​

The value of the options property of an fn::invoke is an object with the following properties.

The parent and provider values permit expressions which must use interpolation syntax to reference resources by name. For example:

yaml
    options:
      provider: ${myEksProvider}
      parent: ${someParentResource}
PropertyTypeDescription
parentExpressionParent specifies a parent for the resource
providerExpressionProvider specifies an explicitly configured provider, instead of using the default global provider
versionstringVersion specifies a provider plugin version that should be used when operating on a resource
pluginDownloadURLstringPluginDownloadURL specifies a URL that should be used to download the provider plugin

fn::join ​

Joins strings together separated by a delimiter. Arguments are passed as a list, with the first item being the delimiter, and the second item a list of expressions to concatenate.

yaml
variables:
    banana:
        fn::join:
            - 'NaN'
            - - Ba
              - a

The expression ${banana} has the value "BaNaNa".

fn::split ​

Splits a string on a delimiter. Arguments are passed as a list, with the first item being the delimiter, and the second item the string to split.

yaml
variables:
    fruits:
        fn::split:
            - ", "
            - "apple, orange, banana"

The expression ${fruits} is a list containing the values ["apple", "orange", "banana"].

fn::select ​

Selects one of several options given an index. Arguments are passed as a list, with the first item being the index, 0-based, and the second item a list of expressions to select from.

yaml
variables:
    policyVersion:
        fn::select:
            - 1
            - - v1
              - v1.1
              - v2.0

The expression ${policyVersion} has the value v1.1.

fn::*Asset and fn::*Archive ​

Assets and archives are intrinsic types to Pulumi, like strings and numbers, and some resources may take these as inputs or return them as outputs. The built-ins create each kind of asset or archive. Each takes a single string value, except fn::assetArchive, which takes a map.

Built-inArgument typeDescription
fn::fileAssetstringThe contents of the asset are read from a file on disk.
fn::stringAssetstringThe contents of the asset are read from a string in memory.
fn::remoteAssetstringThe contents of the asset are read from an http, https, or file URI.
fn::fileArchivestringThe contents of the archive are read from either a folder on disk or a file on disk in one of the supported formats: .tar, .tgz, .tar.gz, .zip or .jar.
fn::remoteArchivestringThe contents of the archive are read from an http, https, or file URI, which must produce an archive of one of the same supported types as FileArchive.
fn::assetArchivemapThe contents of the archive are read from a map of either Asset or Archive objects, one file or folder respectively per entry in the map.
yaml
variables:
  aFile:
    fn::fileAsset: ./file.txt
  aString:
    fn::stringAsset: Hello, world!
  aRemoteAsset:
    fn::remoteAsset: https://example.com/data.json

  aFileArchive:
    fn::fileArchive: ./file.zip
  aRemoteArchive:
    fn::remoteArchive: http://example.com/file.zip
  anAssetArchive:
    fn::assetArchive:
      file:
        fn::stringAsset: Hello, world!
      folder:
        fn::fileArchive: ./folder

fn::secret ​

Constructs a Secret from an existing value.

yaml
variables:
  secret:
    fn::secret:
      fn::invoke:
        function: my:pkg:GetSecretValue

fn::unsecret ​

Unwraps a Secret, returning the underlying value with the secret marking removed.

yaml
variables:
  plaintext:
    fn::unsecret: ${someSecretValue}

fn::readFile ​

Reads a file from disk and returns the contents as a string, which must be UTF-8. This function has special rules for its behavior.

yaml
variables:
  someText:
    fn::readFile: ./README.md

Any subpath of the Pulumi project directory is allowed, whether it is absolute, relative, constant, or an expression:

  • fn::readFile: ./README.md, a relative subpath
  • fn::readFile: ${pulumi.cwd}/example.txt, an absolute subpath
  • fn::readFile: /opt/project-dir/example.json, an absolute subpath if the program is in /opt/project-dir

Absolute paths to any location are allowed if they are constants:

  • fn::readFile: /etc/lsb-release
  • fn::readFile: /usr/share/nginx/html
  • fn::readFile: /var/run/secrets/kubernetes.io/serviceaccount/token

Relative paths that escape the project directory and absolute paths that are non-constant are forbidden to prevent path traversals.

  • fn::readFile: ../../etc/shadow, a relative path that escapes the project
  • fn::readFile: ${pulumi.cwd}/../../.ssh/id_rsa.pub, an expression that returns an absolute path that escapes the project

fn::filebase64 ​

Reads a file from disk and returns the contents as a Base64 encoded string using the standard encoding.

yaml
variables:
  encoded:
    fn::filebase64: ./file.txt

fn::filebase64sha256 ​

Reads a file from disk and returns the SHA-256 hash of its contents as a Base64 encoded string.

yaml
variables:
  fileHash:
    fn::filebase64sha256: ./file.txt

fn::sha1 ​

Computes the SHA-1 hash of a string and returns it as a hexadecimal string.

yaml
variables:
  hashed:
    fn::sha1: "Hello, world!"

The expression ${hashed} returns 943a702d06f34599aee1f8da8ef9f7296031d699.

fn::length ​

Returns the length of a list, map, or string as a number. For a list or map, this is the number of elements. For a string, this is the number of characters.

yaml
variables:
  fruits:
    - apple
    - orange
    - banana
  fruitCount:
    fn::length: ${fruits}

The expression ${fruitCount} returns 3.

fn::singleOrNone ​

Takes a list and returns its single element, or null if the list is empty. The function fails if the list contains more than one element.

yaml
variables:
  single:
    fn::singleOrNone:
      - v1

The expression ${single} returns v1.

fn::pulumiResourceName ​

Returns the name a resource was registered with. This is the resource's logical name unless the name resource option overrides it.

yaml
resources:
  bucket:
    type: aws:s3:BucketV2
variables:
  bucketName:
    fn::pulumiResourceName: ${bucket}

The expression ${bucketName} returns bucket.

fn::pulumiResourceType ​

Returns the type token of a resource declared in the program.

yaml
resources:
  bucket:
    type: aws:s3:BucketV2
variables:
  bucketType:
    fn::pulumiResourceType: ${bucket}

The expression ${bucketType} returns aws:s3/bucketV2:BucketV2.

fn::stackReference ​

WARNING

fn::stackReference is deprecated. Declare a resource of type pulumi:pulumi:StackReference instead.

Reads an output from another Pulumi stack. Arguments are passed as a list, with the first item being the fully qualified stack name and the second item the name of the output to read.

yaml
variables:
  otherOutput:
    fn::stackReference:
      - org/project/stack
      - someOutput

Built-in variables ​

Built-in variables accessible within any Pulumi YAML program.

pulumi ​

The built-in pulumi variable contains properties that can be useful for retrieving information about your current workspace.

yaml
    variables:
      cwd: ${pulumi.cwd}
      organization: ${pulumi.organization}
      project: ${pulumi.project}
      rootDirectory: ${pulumi.rootDirectory}
      stack: ${pulumi.stack}
  • ${pulumi.cwd} retrieves the current working directory
  • ${pulumi.organization} retrieves the current Pulumi organization
  • ${pulumi.project} retrieves the current project
  • ${pulumi.rootDirectory} retrieves the project's root directory, which contains the Pulumi.yaml file
  • ${pulumi.stack} retrieves the current stack

Content from the official Pulumi documentation (github.com/pulumi/docs).