Come join Pulumi for the industry's first Cloud Engineering Summit! October 7–8. Save Your Spot

JetBrains TeamCity

This page details how to use JetBrains TeamCity to deploy a sample infrastructure, using Pulumi. In the example below, we will deploy to AWS, but any cloud can be used.

Prerequisites

  • A working installation of TeamCity
  • An account on the Pulumi Console.
  • The latest version of Pulumi. Installation instructions are here.
  • Setup a new project and stack using one of our Get Started guides or by running pulumi new and choosing one of the many templates that are available.

Sample Project

The example we are going to deploy is located here. You may download the project and upload it to your own repo to avoid having to clone the entire Pulumi Examples repo onto your TeamCity server.

Configuring the TeamCity Project

For the purposes of this guide, we are going to build a TeamCity project via the UI. An alternative way to do this, would be to use the Kotlin DSL.

When creating a new project via the UI, we will see the project creation wizard. We are going to create a project From a repository URL from the Pulumi Examples repository. This specific repository is open source so we do not need to enter a Username and Password. We can then instruct TeamCity to proceed to the next step.

TeamCity will tell us if it can successfully connect to the repository. If it can, then it will ask us to name this project and to create a build configuration name. We are going to name the project Examples and we will create a build configuration called Tutorial. We can then Proceed to the next step. We can click the link that says configure build steps manually and then can start creating our project.

A TeamCity configuration is made of build steps. We can break down the steps required for us to deploy this application into a number of build steps.

Install NodeJS and NPM Build Step

The first thing we need to do is to ensure that NodeJS and NPM are installed on our build agents. We would chose Command Line as the build runner type and TeamCity will present us with the build runner wizard

We are going to create a Build Step with the following parameters:

Runner type: Command Line
Step name: Install NodeJS & NPM
Execute step: If all previous steps finished successfully
Working directory: aws-ts-eks-hello-world
Run: Custom script
Custom Script:

yum -y install nodejs  
npm version

We can Save the step. Let’s add the next build step by clicking on Add Build Step.

Installing Pulumi Build Step

We are going to create a Build Step with the following parameters:

Runner type: Command Line
Step name: Install Pulumi
Execute step: If all previous steps finished successfully
Working directory: aws-ts-eks-hello-world
Run: Custom script
Custom Script:

curl -sSL https://get.pulumi.com | sh

Again, we can Save the step and add the next build step by clicking on Add Build Step.

Restoring NPM Dependencies Build Steo

We are going to create a Build Step with the following parameters:

Runner type: Command Line
Step name: Restore Dependencies
Execute step: If all previous steps finished successfully
Working directory: aws-ts-eks-hello-world
Run: Custom script
Custom Script:

curl -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.13.7/2019-06-11/bin/linux/amd64/aws-iam-authenticator
chmod +x ./aws-iam-authenticator
mkdir -p $HOME/bin && cp ./aws-iam-authenticator $HOME/bin/aws-iam-authenticator
npm install

Again, we can Save the step and add the next build step by clicking on Add Build Step.

Pulumi Stack Creation Build Steo

We are going to create a Build Step with the following parameters:

Runner type: Command Line
Step name: Stack Creation
Execute step: If all previous steps finished successfully
Working directory: aws-ts-eks-hello-world
Run: Custom script
Custom Script:

pulumi stack init %STACK_NAME%
pulumi config set aws:region %AWS_REGION%

Again, we can Save the step and add the last build step by clicking on Add Build Step.

Pulumi Up Build Step

Runner type: Command Line
Step name: Pulumi Up
Execute step: If all previous steps finished successfully
Working directory: aws-ts-eks-hello-world
Run: Custom script
Custom Script:

pulumi up --yes

Configuring Build Parameters

We need to create a few build parameters before we can actually run the build. The TeamCity Documentation describes how to create these parameters. The parameters we will create are as follows:

AWS_REGION: us-east-2
STACK_NAME: development-example

env.AWS_ACCESS_KEY_ID:
env.AWS_SECRET_ACCESS_KEY:
env.PULUMI_ACCESS_TOKEN:
env.PATH: %env.PATH%:%env.HOME%/.pulumi/bin:%env.HOME%/bin

Running the build

Now that all the steps are created and the configuration has been added to TeamCity, we can run the build by clicking on the Run button. After a few minutes, we should have a successful build. On inspection of the build log, we can see that the infrastructure has been successfully deployed:

[17:05:48][Step 5/5]                     exec: {
[17:05:48][Step 5/5]                         apiVersion: "client.authentication.k8s.io/v1alpha1"
[17:05:48][Step 5/5]                         args      : [
[17:05:48][Step 5/5]                             [0]: "token"
[17:05:48][Step 5/5]                             [1]: "-i"
[17:05:48][Step 5/5]                             [2]: "helloworld-eksCluster-c5bd220"
[17:05:48][Step 5/5]                         ]
[17:05:48][Step 5/5]                         command   : "aws-iam-authenticator"
[17:05:48][Step 5/5]                     }
[17:05:48][Step 5/5]                 }
[17:05:48][Step 5/5]             }
[17:05:48][Step 5/5]         ]
[17:05:48][Step 5/5]     }
[17:05:48][Step 5/5]     namespaceName  : "helloworld-eyay6eno"
[17:05:48][Step 5/5]     serviceHostname: "a2b21d9e5f4ee11e99d67026bafffdcc-603547860.us-east-2.elb.amazonaws.com"
[17:05:48][Step 5/5]     serviceName    : "helloworld-d4oadgeg"
[17:05:48][Step 5/5]
[17:05:48][Step 5/5] Resources:
[17:05:48][Step 5/5]     + 40 created
[17:05:48][Step 5/5]
[17:05:48][Step 5/5] Duration: 13m0s
[17:05:48][Step 5/5]
[17:05:48][Step 5/5] Permalink: https://app.pulumi.com/stack72/aws-ts-eks-hello-world/development-example/updates/1
[17:05:48][Step 5/5] Process exited with code 0