Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Know it before you install
A project is your code (Pulumi.yaml). A stack is one deployment of it (dev, prod) with its own config and state. The backend stores the state (Pulumi Cloud, S3, Azure Blob, GCS or a local folder). Providers (aws, azure-native, gcp, kubernetes …) are language packages.
| Item | Value |
|---|---|
| Program | pulumi (installed in ~/.pulumi/bin) |
| Project files | Pulumi.yaml, Pulumi.<stack>.yaml (config), your code (__main__.py …) |
| State | the backend you log in to (pulumi login …) |
| Secrets | encrypted in the stack config (Pulumi Cloud, passphrase, or a cloud KMS) |
| Needs | the language runtime (Python 3 + venv, Node.js, Go …) |
Install on RHEL and Ubuntu
The install script puts Pulumi in your home folder and adds it to your PATH:
curl -fsSL https://get.pulumi.com -o get-pulumi.sh
less get-pulumi.sh
sh get-pulumi.sh
source ~/.bashrc
pulumi version
v3.205.0Install the language runtime you use — for Python: dnf -y install python3 python3-pip (RHEL) or apt-get install -y python3 python3-venv (Ubuntu).
First configuration: choose a backend
Option 1 — Pulumi Cloud (free for individuals; state, secrets, history and a UI):
pulumi loginOption 2 — your own S3 bucket with KMS for secrets (no outside service):
(For a lab only: pulumi login --local keeps the state in ~/.pulumi.)
Create a project and stacks
mkdir infra && cd infra
pulumi new aws-python --name infra --stack dev --secrets-provider="awskms://alias/pulumi-secrets?region=eu-central-1" --yes
pulumi config set aws:region eu-central-1
pulumi config set bucketPrefix acme-dev
pulumi config set --secret dbPassword
pulumi stack init prod --secrets-provider="awskms://alias/pulumi-secrets?region=eu-central-1"
pulumi stack lsThe code — a private, encrypted S3 bucket per stack:
import pulumi
import pulumi_aws as aws
cfg = pulumi.Config()
prefix = cfg.require("bucketPrefix")
stack = pulumi.get_stack()
bucket = aws.s3.Bucket(
"logs",
bucket=f"{prefix}-logs",
tags={"env": stack, "managed_by": "pulumi"},
)
aws.s3.BucketPublicAccessBlock(
"logs-block",
bucket=bucket.id,
block_public_acls=True,
block_public_policy=True,
ignore_public_acls=True,
restrict_public_buckets=True,
)
aws.s3.BucketServerSideEncryptionConfigurationV2(
"logs-sse",
bucket=bucket.id,
rules=[{"apply_server_side_encryption_by_default": {"sse_algorithm": "aws:kms"}}],
)
pulumi.export("bucket_name", bucket.bucket)| Part | Why |
|---|---|
| One stack per environment | Same code, different config and state for dev and prod. |
pulumi config set --secret | The value is encrypted in Pulumi.<stack>.yaml — safe to commit. |
--secrets-provider awskms://… | Secrets encrypted with your KMS key, not a passphrase. |
cfg.require(...) | The program stops with a clear error when a setting is missing. |
Daily use: the commands and the real uses
pulumi stack select dev
pulumi preview --diff
pulumi up
pulumi stack output bucket_name
pulumi refresh
pulumi stack history
pulumi import aws:s3/bucket:Bucket old-logs acme-old-logs
pulumi destroy
pulumi config
pulumi up --stack prod --yes --skip-previewpulumi preview = terraform plan; pulumi up = apply (it also shows a preview and asks); pulumi refresh reads the real cloud state to find drift. In CI, run preview on pull requests and up after merge (there are ready actions for GitHub and GitLab).
Real uses at work:
- Teams that already write Python/TypeScript build infrastructure with the same language, tests and libraries.
- Reusable components (classes) that create a full app stack (bucket + CDN + DNS) in one call.
- Kubernetes and multi-cloud in one program; the Automation API to run Pulumi from your own apps.
Make it safe
Security checklist:
- Secrets only with
pulumi config set --secretand a KMS secrets provider (or Pulumi Cloud) — never in code or plain config. - A private, versioned state bucket with encryption; least-privilege access to it.
- Short-lived cloud credentials (SSO, OIDC in CI).
- Pin provider package versions (
requirements.txt/package.jsonlock files). - Review
pulumi preview --diffbefore everyup, especially replacements. - Protect important resources:
opts=pulumi.ResourceOptions(protect=True).
Update and remove
Update the provider packages in your project too (pip install -U pulumi-aws, then test with preview).
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
CI asks Enter your passphrase to unlock config/secrets | Passphrase secrets provider without the env var. | Set PULUMI_CONFIG_PASSPHRASE as a CI secret, or switch to KMS (pulumi stack change-secrets-provider). |
the stack is currently locked by 1 lock(s) | A run crashed or is still running. | Wait; if it is dead: pulumi cancel (Pulumi Cloud) or remove the lock file in the S3 backend carefully. |
| Preview wants to change things nobody changed | Drift in the cloud. | pulumi refresh, then decide: fix the code or let Pulumi fix the cloud. |
error: no stack named 'prod' found | Wrong backend or stack name. | pulumi whoami -v, pulumi stack ls. |
ModuleNotFoundError: No module named 'pulumi_aws' | The project venv is missing packages. | pulumi install (or pip install -r requirements.txt in the venv). |
| A rename wants to delete and recreate a resource | The resource name changed. | Use aliases=[...] in ResourceOptions to keep it. |
Next steps
- Command page: pulumi.
- The HCL tools: Terraform, OpenTofu. The language: Python.
- At work: Pulumi — IaC in a programming language.
1What is a Pulumi stack?
One deployment of the project (for example dev or prod) with its own config and state.
2How do you store a database password in Pulumi config safely?
pulumi config set --secret dbPassword — it is encrypted with the stack's secrets provider.