1. Packages
  2. Packages
  3. Any HCL Module
Viewing docs for Any HCL Module 0.9.1
published on Tuesday, Jul 7, 2026 by Pulumi

Any HCL Module

Viewing docs for Any HCL Module 0.9.1
published on Tuesday, Jul 7, 2026 by Pulumi

    The hcl package lets you instantiate any Terraform or OpenTofu module as a Pulumi component resource. Point the Module resource at a module source — a Terraform registry reference, a Git URL, or a local path — pass its input variables, and consume its outputs like any other Pulumi resource, from any supported language.

    The module runs under Pulumi’s engine: its resources are tracked in your Pulumi state, its provider credentials come from your Pulumi configuration, and its sensitive outputs are handled as Pulumi secrets.

    Example

    The following program instantiates the community terraform-aws-modules/vpc/aws module and exports the resulting VPC id.

    import * as pulumi from "@pulumi/pulumi";
    import * as hcl from "@pulumi-labs/hcl";
    
    const vpc = new hcl.Module("vpc", {
        source: "terraform-aws-modules/vpc/aws",
        version: "5.0.0",
        inputs: {
            name: "example-vpc",
            cidr: "10.0.0.0/16",
        },
    });
    
    export const vpcId = vpc.outputs.apply(o => o["vpc_id"]);
    
    import pulumi
    import pulumi_labs_hcl as hcl
    
    vpc = hcl.Module("vpc",
        source="terraform-aws-modules/vpc/aws",
        version="5.0.0",
        inputs={
            "name": "example-vpc",
            "cidr": "10.0.0.0/16",
        })
    
    pulumi.export("vpc_id", vpc.outputs["vpc_id"])
    
    package main
    
    import (
    	"github.com/pulumi-labs/pulumi-hcl/sdk/go/hcl"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		vpc, err := hcl.NewModule(ctx, "vpc", &hcl.ModuleArgs{
    			Source:  "terraform-aws-modules/vpc/aws",
    			Version: pulumi.StringRef("5.0.0"),
    			Inputs: pulumi.Map{
    				"name": pulumi.String("example-vpc"),
    				"cidr": pulumi.String("10.0.0.0/16"),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		ctx.Export("vpcId", vpc.Outputs.MapIndex(pulumi.String("vpc_id")))
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using Pulumi;
    using Pulumi.Labs.Hcl;
    
    return await Deployment.RunAsync(() =>
    {
        var vpc = new Module("vpc", new ModuleArgs
        {
            Source = "terraform-aws-modules/vpc/aws",
            Version = "5.0.0",
            Inputs =
            {
                { "name", "example-vpc" },
                { "cidr", "10.0.0.0/16" },
            },
        });
    
        return new Dictionary<string, object?>
        {
            ["vpcId"] = vpc.Outputs.Apply(o => o["vpc_id"]),
        };
    });
    
    name: example
    runtime: yaml
    resources:
      vpc:
        type: hcl:index:Module
        properties:
          source: terraform-aws-modules/vpc/aws
          version: "5.0.0"
          inputs:
            name: example-vpc
            cidr: 10.0.0.0/16
    outputs:
      vpcId: ${vpc.outputs["vpc_id"]}
    

    Strongly typed SDKs

    The Module resource above takes its source at runtime, so its inputs and outputs are untyped maps. To get a strongly typed SDK for a specific module, generate a parameterized provider for it:

    pulumi package add hcl module <source> [version]
    

    For example, pulumi package add hcl module terraform-aws-modules/vpc/aws 5.0.0 generates a local SDK whose resource exposes that module’s variables and outputs as first-class, typed properties in your language of choice.

    Viewing docs for Any HCL Module 0.9.1
    published on Tuesday, Jul 7, 2026 by Pulumi

      Try Pulumi Cloud free.
      Your team will thank you.

      Start free trial