Pulumi Any Terraform

Local Provider

Manage local files, directories, and sensitive files with Pulumi

The Local provider enables you to manage local filesystem resources like files, sensitive files, and command execution using Pulumi. This provider is dynamically bridged from the Terraform Local Provider.

Installation

Install the Local provider package using your preferred package manager:

bun add pulumi-local
pnpm add pulumi-local
yarn add pulumi-local
npm install pulumi-local

Configuration

No configuration required - the Local provider works out of the box with your local filesystem.

Quick Start

import * as pulumi from "@pulumi/pulumi";
import * as local from "pulumi-local";

// Create a local file
const config = new local.File("app-config", {
    filename: "/tmp/config.json",
    content: JSON.stringify({
        environment: "production",
        debug: false,
    }),
});

export const configPath = config.filename;

Key Features

File Management

Create and manage local files with specific content and permissions:

const readme = new local.File("readme", {
    filename: "./output/README.md",
    content: "# My Project\n\nGenerated by Pulumi",
});

Sensitive Files

Handle files containing sensitive data with restricted permissions:

const credentials = new local.SensitiveFile("credentials", {
    filename: "/tmp/credentials.json",
    content: JSON.stringify({
        apiKey: "secret-key-value",
        dbPassword: "secret-password",
    }),
});

Read Existing Files

Read the content of existing files as data sources:

const hostname = local.getFile({
    filename: "/etc/hostname",
});

Execute Commands

Run local commands and capture their output:

const gitHash = local.getCommand({
    command: "git rev-parse HEAD",
});

Common Use Cases

Generate Configuration Files

import * as pulumi from "@pulumi/pulumi";
import * as local from "pulumi-local";

const stack = pulumi.getStack();

const envFile = new local.File("env-config", {
    filename: `.env.${stack}`,
    content: pulumi.interpolate`NODE_ENV=${stack}
API_URL=https://api.${stack}.example.com
LOG_LEVEL=${stack === "production" ? "warn" : "debug"}`,
});

export const envPath = envFile.filename;

Write Deployment Artifacts

import * as pulumi from "@pulumi/pulumi";
import * as local from "pulumi-local";

// Write deployment metadata
const metadata = new local.File("deploy-metadata", {
    filename: "./deploy/metadata.json",
    content: pulumi.interpolate`{
    "stack": "${pulumi.getStack()}",
    "project": "${pulumi.getProject()}",
    "timestamp": "${new Date().toISOString()}"
}`,
});

Store Sensitive Credentials

import * as local from "pulumi-local";

const kubeconfig = new local.SensitiveFile("kubeconfig", {
    filename: "~/.kube/config",
    content: kubeconfigContent, // From another provider
});

Resource Types

ResourceDescription
FileCreate and manage local files
SensitiveFileCreate files with sensitive content and restricted permissions

Data Sources

Data SourceDescription
getFileRead content of an existing local file
getSensitiveFileRead content of an existing sensitive file
getCommandExecute a local command and capture output

Getting Help

On this page