Skip to main content

A Pulumi package for consuming Terraform Remote State resources.

Project description

Pulumi Terraform Provider

The Terraform resource provider for Pulumi lets you consume the outputs contained in Terraform state files from your Pulumi programs. The package provides a RemoteStateReference resource which acts like a native Pulumi StackReference.

To use this package, please install the Pulumi CLI first.

Installing

Node.js (JavaScript/TypeScript)

To use from JavaScript or TypeScript in Node.js, install using either npm:

$ npm install @pulumi/terraform

or yarn:

$ yarn add @pulumi/terraform

Python

To use from Python, install using pip:

$ pip install pulumi-terraform

Concepts

The @pulumi/terraform package provides a resource named RemoteStateReference which is used to read outputs from a Terraform state file stored in one of the supported Terraform remote state backends.

Examples

S3

The following program will read a Terraform state file stored in S3:

import * as tf from "@pulumi/terraform";

const remoteState = new tf.state.RemoteStateReference("s3state", {
    backendType: "s3",
    bucket: "pulumi-terraform-state-test",
    key: "test/terraform.tfstate",
    region: "us-west-2"
});

// Use the getOutput function on the resource to access root outputs
const vpcId= remoteState.getOutput("vpc_id");

Local file

The following program will read a Terraform state file stored locally in the filesystem:

import * as tf from "@pulumi/terraform";

const remotestate = new tf.state.RemoteStateReference("localstate", {
   backendType: "local",
   path: path.join(__dirname, "terraform.tfstate"),
});

// Use the getOutput function on the resource to access root outputs
const vpcId= remoteState.getOutput("vpc_id");

Terraform Enterprise

For state stored in Terraform Enterprise, the authentication token must be set via the Pulumi configuration system - for example, using:

pulumi config set --secret terraformEnterpriseToken <value>

The following program will read a Terraform state file stored in Terraform Enterprise, using the value of terraformEnterpriseToken from above:

import * as pulumi from "@pulumi/pulumi";
import * as tf from "@pulumi/terraform";

const config = new pulumi.Config();

const ref = new tf.state.RemoteStateReference("remote", {
    backendType: "remote",
    organization: "pulumi",
    token: config.requireSecret("terraformEnterpriseToken"),
    workspaces: {
        name: "test-state-file"
    }
});

// Use the getOutput function on the resource to access root outputs
const vpcId= remoteState.getOutput("vpc_id");

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pulumi_terraform-5.8.0a1675048832.tar.gz (12.2 kB view details)

Uploaded Source

File details

Details for the file pulumi_terraform-5.8.0a1675048832.tar.gz.

File metadata

File hashes

Hashes for pulumi_terraform-5.8.0a1675048832.tar.gz
Algorithm Hash digest
SHA256 3a7765e02dd5b51e4f8a61b2719a14f5fed518d846a39fb3651a51f2732d8d1b
MD5 88cf314ce8a95ff3bcad614788454d3e
BLAKE2b-256 ccd08a68b0c849ff5e8a56b66dbf2eec33b7b7a0331d44c93e68ebbb6ee4ebc5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page