Pulumi is a modern infrastructure as code (IaC) platform that allows you to define, deploy, and manage cloud resources using general-purpose programming languages such as Python, JavaScript, TypeScript, Go, .NET, and Java. It combines the power of imperative programming with the benefits of declarative infrastructure definitions. (pulumi.com, pulumi.com)
-
Install the Pulumi CLI:
curl -fsSL https://get.pulumi.com | sh -
Initialize a New Project:
pulumi new aws-python # Choose your language and cloud -
Write Code: Use your language of choice to import Pulumi libraries and define resources.
-
Configure:
pulumi config set aws:region us-west-2 -
Preview Changes:
pulumi preview
-
Deploy:
pulumi up
-
Manage State: Pulumi stores state in the Pulumi Service by default or in your preferred backend (S3, Azure Blob, etc.).
"""A Python Pulumi program"""
import pulumi
from pulumi_aws import ec2
# Define a Security Group
security_group = ec2.SecurityGroup(
'web-sg',
description='Enable SSH and HTTP access',
ingress=[
ec2.SecurityGroupIngressArgs(
protocol="tcp",
from_port=22,
to_port=22,
cidr_blocks=["0.0.0.0/0"], # Allow SSH access
),
ec2.SecurityGroupIngressArgs(
protocol="tcp",
from_port=80,
to_port=80,
cidr_blocks=["0.0.0.0/0"], # Allow HTTP access
),
]
)
# Create an EC2 instance
ami_id = "ami-005fc0f236362e99f" # Update with a valid Ubuntu AMI for your region
instance = ec2.Instance(
'ubuntu-instance',
instance_type="t2.micro",
ami=ami_id,
vpc_security_group_ids=[security_group.id],
key_name="", # Replace with your AWS key pair
tags={
"Name": "PulumiInstance"
}
)
# Export the public IP of the instance
pulumi.export("public_ip", instance.public_ip)The output is something like this:
- Use Pulumi to deploy other AWS/GCP service
- Pulumi Docs: https://www.pulumi.com/docs/ (pulumi.com)
- AWS EC2 Example (TypeScript reference): https://www.pulumi.com/docs/iac/clouds/aws/guides/more/#create-an-ec2-instance (pulumi.com)
