Pulumi Command Provider
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
- gotcha Commands are inherently not idempotent. Without explicit `triggers`, Pulumi won't rerun commands even if their inputs change, leading to potential resource drift. Always specify `triggers` if you want a command to rerun on input changes.
- gotcha By default, `local.Command` and `remote.Command` resources do not perform any 'delete' actions. If a command creates external resources, those resources will persist even if the Pulumi stack is destroyed or the command resource is removed, leading to unmanaged resources or cloud waste.
- gotcha Sensitive information output by commands (e.g., passwords, tokens) will appear in Pulumi logs unless explicitly marked as sensitive. This can pose a security risk.
- breaking Upgrading to new major versions (e.g., from 1.x to 2.x) of the `pulumi-command` provider or the core Pulumi SDK can introduce breaking changes in resource properties, behavior, or required arguments. Always review release notes carefully.
Install
-
pip install pulumi-command
Imports
- local.Command
from pulumi_command import local
- remote.Command
from pulumi_command import remote
- provider.Provider
from pulumi_command import provider
Quickstart
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
# )
# )