Comparing Different IaC Tools for Serverless Deployment : (2) Pulumi + Gitlab
In the previous article (Link), I defined the stack base to compare the different IaC (Infrastructure As Code) tools in serverless. In this article, we review the deployment of this infrastructure using Pulumi.
The Gitlab pipeline:
The Pulumi documentation provides an example of a pipeline Link. The example is comprehensive and well-explained; however, it lacks a section for resource destruction using the pipelines. I have added this section and tested both creation and destruction within the same pipeline.
The structure of the pipeline is based on a set of scripts. These scripts, setup.sh and run-pulumi.sh, are invoked from the pipeline. Based on this, I wrote a script to destroy the resources.
Destroy script
All scripts are located in the 'scripts' folder. I have added a new script named 'destroy-pulumi.sh' with the following structure:
#!/bin/bash
# exit if a command returns a non-zero exit code and also
# print the commands and their args as they are executed
set -e -x
# Add the pulumi CLI to the PATH
export PATH=$PATH:$HOME/.pulumi/bin
yarn install
pulumi stack select dev
pulumi config set aws:region eu-central-1
# The following is just a sample config setting that the hypothetical pulumi
# program needs.
# Learn more about pulumi configuration at: https://www.pulumi.com/docs/concepts/config/
# pulumi config set mysetting myvalue
pulumi destroy --yes # this line will be the pulumi preview command in pulumi-preview.sh
In the script, the most important commands are pulumi stack select dev
to select the stack to destroy, and pulumi config set aws:region eu-central-1
to configure the region where the stack is; and finally the pulumi destroy --yes
.
gitlab-ci.yml
To call the scripts, the pipeline uses three lines in their respective stages. For the destroy stage, the commands in the execution section would be:
# pulumi-up stage
before_script:
- chmod +x ./scripts/*.sh
- ./scripts/setup.sh
script:
- ./scripts/destroy-pulumi.sh
The before_script
prepares the environment, and the script
executes the resource destruction.
To run this stage, it is necessary to configure the DESTROY
variable to OK
in the web interface of the pipeline.
The repository:
This is the repository with all files (Link), and configurations needed to deploy the mimic-stack. The complete pipeline includes the following stages:
Stages:
sync-with-github: Sync with GitHub. The current environment for this is in my GitLab account.
git-clone-lambda-code: Get the code for the mimic stack.
npm-install: JavaScript was chosen as the language to build the infrastructure, hence this stage is necessary.
infrastructure-update: Deploy infrastructure.
infrastructure-destroy: Destroy infrastructure.
Context
All this is support for the talk I gave at the last commit-confLink to video
References:
Subscribe to my newsletter
Read articles from Oscar Cortes Bracho directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Oscar Cortes Bracho
Oscar Cortes Bracho
Cloud Software Engineer