Geavanceerd
Zoeken inInstallatiegidsen
Zo zoek je
  • Plak een foutmelding tussen aanhalingstekens, bijv. "permission denied", om de oplossingstabel te vinden.
  • Kies een gebied en een deel van de gids (installeren, eerste instellingen, dagelijks gebruik, beveiliging, oplossingen) om direct naar de juiste stap te gaan.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

Gids 54Pulumi · IaC and automation

Install and set up Pulumi

Pulumi is infrastructure as code in real programming languages: Python, TypeScript, Go, C# or Java. You get loops, functions, classes, tests and your normal IDE — and Pulumi still shows a preview and keeps a state like Terraform. This guide installs Pulumi on RHEL and Ubuntu, chooses a state backend (Pulumi Cloud or your own S3 bucket), creates a Python project with stacks for dev and prod, stores secrets safely, and shows the daily commands and fixes.

  • 9 Lessen
  • 10 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

54.1

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.

ItemValue
Programpulumi (installed in ~/.pulumi/bin)
Project filesPulumi.yaml, Pulumi.<stack>.yaml (config), your code (__main__.py …)
Statethe backend you log in to (pulumi login …)
Secretsencrypted in the stack config (Pulumi Cloud, passphrase, or a cloud KMS)
Needsthe language runtime (Python 3 + venv, Node.js, Go …)

54.2

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.0

Install the language runtime you use — for Python: dnf -y install python3 python3-pip (RHEL) or apt-get install -y python3 python3-venv (Ubuntu).

54.3

First configuration: choose a backend

Option 1 — Pulumi Cloud (free for individuals; state, secrets, history and a UI):

pulumi login

Option 2 — your own S3 bucket with KMS for secrets (no outside service):

pulumi login 's3://acme-pulumi-state?region=eu-central-1&awssdk=v2'
pulumi whoami -v

(For a lab only: pulumi login --local keeps the state in ~/.pulumi.)

54.4

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 ls

The code — a private, encrypted S3 bucket per stack:

__main__.py
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)
PartWhy
One stack per environmentSame code, different config and state for dev and prod.
pulumi config set --secretThe 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.

54.5

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-preview

pulumi 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.

54.6

Make it safe

Security checklist:

  • Secrets only with pulumi config set --secret and 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.json lock files).
  • Review pulumi preview --diff before every up, especially replacements.
  • Protect important resources: opts=pulumi.ResourceOptions(protect=True).

54.7

Update and remove

sh get-pulumi.sh
pulumi plugin ls
pulumi plugin rm --all --yes
rm -rf ~/.pulumi

Update the provider packages in your project too (pip install -U pulumi-aws, then test with preview).

54.8

Fix common problems

ProblemCauseFix
CI asks Enter your passphrase to unlock config/secretsPassphrase 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 changedDrift in the cloud.pulumi refresh, then decide: fix the code or let Pulumi fix the cloud.
error: no stack named 'prod' foundWrong 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 resourceThe resource name changed.Use aliases=[...] in ResourceOptions to keep it.

54.9

Next steps

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.

Alle commando's in dit hoofdstuk