Welcome to day 72 of the 2024 edition of 90 Days of DevOps!
Today's session is titled "Infrastructure as Code with Pulumi", and it is led by Scott Lowe.
Code for this session, as well as a PDF version of the slides, is available from the companion repository.
To use the example code, you will need the following:
- The AWS CLI installed and configured for an AWS account (Pulumi doesn't rely on the AWS CLI, but it uses the configuration for connecting to AWS)
- An SSH key pair defined in your AWS account and in your desired region
- The
pulumi
CLI tool installed and logged into a backend (see the slides for more information on Pulumi backends; using Pulumi Cloud is the easiest and fastest way to get started) - NodeJS installed
- The
git
CLI tool installed - (Optional) SSH installed on your system, if you want to be able to connect to the instance provisioned by the Pulumi program
Follow these instructions to run this Pulumi program:
- Use
git clone
to clone the companion repository to your local system. - Change into the directory where the repository was cloned.
- Use
pulumi stack init <name>
to create a new Pulumi stack named<name>
. - Run
npm install
to install the dependencies for the Pulumi program. - Run
pulumi config set aws:region <region>
to specify the AWS region where the resources should be created. - Run
pulumi config set keypair <keypair-name>
to specify the name of an existing AWS key pair that can be used for SSH access to an EC2 instance. - (Optional) Set the desired VPC CIDR block with
pulumi config set vpcNetworkCidr <cidr>
. - (Optional) Set the instance type with
pulumi config set <instance-type>
. - Run
pulumi up
to instantiate the infrastructure. - After the stack has finished provisioning, run
pulumi stack output
to get the IP address of the Flatcar Container Linux instance that was created. You can SSH into this instance to run Docker commands and verify that Pulumi launched a Docker container on this instance. - When you're finished, run
pulumi destroy
to tear down all the AWS resources.
Enjoy!