Pulumi Command Provider

1.2.1 · active · verified Fri Apr 10

The Pulumi Command Provider allows users to execute commands and scripts, either locally or remotely, as part of their Pulumi infrastructure-as-code deployments. It integrates command execution directly into the Pulumi resource model, enabling complex provisioning tasks. The current version is 1.2.1, and the library generally follows a minor point release cadence for bug fixes and feature enhancements, with major versions indicating potential breaking changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a local command that simply echoes a message. The `triggers` input is crucial for ensuring the command re-runs when its inputs change. It also shows a commented-out section for setting up a remote command, highlighting the need for connection details like host, user, and a private key (preferably from an environment variable for security).

import pulumi
from pulumi_command import local
import os

# Example of a local command that echoes a message
# The `triggers` input ensures the command reruns if the message changes.
local_command = local.Command("echo-command",
    create="echo 'Hello from Pulumi local command!'",
    triggers=["Hello from Pulumi local command!"] # Ensures re-run on change
)

# Export the stdout of the command
pulumi.export("command_output", local_command.stdout)

# For remote commands, you'd typically configure SSH:
# from pulumi_command import remote
# remote_command = remote.Command("remote-script",
#     create="ls -la",
#     connection=remote.ConnectionArgs(
#         host="your_remote_host_ip",
#         user="your_username",
#         private_key=os.environ.get('SSH_PRIVATE_KEY', '') # Use environment variable for sensitive data
#     )
# )

view raw JSON →