1. Docs
  2. Infrastructure as Code
  3. Languages & SDKs
  4. HCL
  5. Component Reference

Pulumi HCL component reference

    Pulumi HCL modules can be authored as reusable Pulumi components consumable from any Pulumi language (TypeScript, Python, Go, .NET, Java, YAML, or HCL). This is known as a multi-language component (MLC).

    An HCL module becomes an MLC when it has a PulumiPlugin.yaml containing runtime: hcl and declares a component block (and optionally a package block) inside the module’s pulumi block. The rest of the module is an ordinary Pulumi HCL program — see the Pulumi HCL reference for the full program model.

    Example

    PulumiPlugin.yaml:

    runtime: hcl
    

    main.hcl:

    pulumi {
      component {
        name = "VpcNetwork"
      }
      package {
        name    = "my-networking"
        version = "1.0.0"
      }
      required_providers {
        aws = {
          source  = "pulumi/aws"
          version = ">= 6.0"
        }
      }
    }
    
    variable "cidr_block" {
      type    = string
      default = "10.0.0.0/16"
    }
    
    resource "aws_vpc" "vpc" {
      cidr_block = var.cidr_block
    }
    
    output "vpc_id" {
      value = aws_vpc.vpc.id
    }
    

    The module’s variable blocks become the component’s inputs and its output blocks become the component’s outputs.

    Component definition

    component block

    Declares the HCL module as a component resource.

    FieldTypeRequiredDefaultDescription
    namestringYesComponent name. Must be a valid Pulumi name (alphanumeric, hyphens, underscores; must start with a letter or underscore).
    modulestringNo"index"Module segment of the component’s resource token. Must be a valid Pulumi name.

    package block

    Declares the package identity for the component.

    FieldTypeRequiredDefaultDescription
    namestringNoDirectory name of the modulePackage name. Must be a valid Pulumi name when specified.
    versionstringNo"0.0.0-dev"Package version. Must be a valid semver string when specified.

    Only one component block and one package block are allowed per pulumi block. Using component or package in a regular Pulumi program (one invoked directly via pulumi up) produces an error.

    Resource token

    The component’s Pulumi resource token is formed as:

    {package.name}:{component.module}:{component.name}
    

    For the example above the token is my-networking:index:VpcNetwork.

    PulumiPlugin.yaml

    The PulumiPlugin.yaml file tells the Pulumi engine how to run the component provider. For HCL MLCs it should specify the hcl runtime:

    runtime: hcl
    

    The component and package blocks in the HCL source supply the provider name and version, so they do not need to be hardcoded elsewhere.