Pulumi
This walkthrough shows you how to pass CloudTruth parameters to Pulumi.

Prerequisites

Pulumi deploy with CloudTruth

For this example we will deploy an EC2 instance defining variables with CloudTruth parameters. You can use any target for your deploys.

Set CloudTruth Pulumi Variables

Create a CloudTruth Project called Pulumi.
1
cloudtruth project set Pulumi
Copied!
Now you can create CloudTruth parameters in the Pulumi project that we will pass to Pulumi as Configuration values.
1
cloudtruth --project Pulumi parameter set ami -v ami-0c2b8ca1dad447f8a
2
cloudtruth --project Pulumi parameter set instance_type -v t2.micro
3
cloudtruth --project Pulumi parameter set availability_zones -v [\"us-east-1a\",\"us-east-1b\",\"us-east-1c\"]
Copied!

Create a CloudTruth Template

In order for Pulumi to accept run-time configuration parameters, they must be in a certain format. We can leverage CloudTruth Templates to transform config data to output them in Pulumi's required format.
For this specific example, create a CloudTruth template named pulumi-aws-template directly from a template file we have created in GitHub for this demo:
1
cloudtruth --project Pulumi template set pulumi-aws-template --body <(curl --silent https://raw.githubusercontent.com/cloudtruth-demo/pulumi-template/main/pulumi-aws-template)
Copied!
This template has the following Pulumi config that dynamically references CloudTruth parameters using mustache syntax: --config ami={{ami}} --config instance_type={{instance_type}} --config availability_zones={{{availability_zones}}}

Deploying a Pulumi stack with CloudTruth

Create a new Pulumi project

To work with Pulumi, we must start a new project. For this example we will be using AWS cloud with the Python programming language. To get started run:
1
mkdir pulumi-demo && cd pulumi-demo
2
pulumi new aws-python
Copied!
Note: If you have never used Pulumi before you will be prompted to login after running pulumi new.
You will be prompted to provide a project name, description, stack name, and AWS region. The sensible defaults are fine for all of these.
The AWS region you select for the Pulumi setup must match the availability zones that you enter as CloudTruth parameters. For this example, we are using us-east-1.

Create a Pulumi configuration

Next, you must create your Pulumi configuration file. From the Pulumi project directory just created in the last step, update your __main__.py with the following configuration:
1
import pulumi
2
import pulumi_aws as aws
3
4
config = pulumi.Config()
5
ami = config.require("ami")
6
instance_type = config.require("instance_type")
7
availability_zones = config.require_object("availability_zones")
8
9
cloudtruth = aws.ec2.Instance("cloudtruth",
10
ami=ami,
11
instance_type=instance_type,
12
availability_zone=availability_zones[0])
13
14
pulumi.export("ami", cloudtruth.ami)
15
pulumi.export("instanceType", cloudtruth.instance_type)
16
pulumi.export("zone", cloudtruth.availability_zone)
Copied!
This __main__.py will deploy an EC2 instance to us-east-1 and defines three variables that are centrally managed by CloudTruth.
Pulumi requires AWS CLI access to deploy to AWS. If you already have the AWS CLI installed and configured, then Pulumi will respect those configuration settings.

Using CloudTruth templates to deploy with Pulumi

The last step is to use pulumi up to deploy your Pulumi configuration. Pass in your CloudTruth template created earlier to fill the configuration parameters. This is assuming the project is named Pulumi and the template is named pulumi-aws-template.
1
pulumi up $(cloudtruth --project Pulumi templates get pulumi-aws-template)
Copied!
Congrats! You have now deployed an instance in EC2 leveraging Pulumi and CloudTruth configuration! 🙌

Cleanup

To tear down all resources, simply run pulumi destroy in the project directory.
Last modified 1mo ago