Running Terraform with Cloudify (Part 2)

In the previous article Running Terraform with Cloudify Part 1 we have covered how to create a blueprint for a dedicated Terraform template.

What You’ll learn

In this article we will create a generic blueprint. The blueprint receives the inputs Terraform version, the URL/Git path, variables and environment variables.

You can always adjust the blueprints to your need. For example if you are using private repo (one of the examples from Part1), you can add user and password inputs.

Prerequisites

You’ll need to have the following setup on you development machine.

Git — To work with our tutorial examples

Python 3.7 — To run Cloudify CLI (cfy)

Docker — To run Cloudify Manager container

AWS access key id and secret access key with permissions to create and delete EC2 instances. You can follow the AWS documentation on how to get those in the link

What is Cloudify?

Cloudify is an orchestration tool that can do many things.

In our current example I’ll walk you step by with the best practices on what is required to spin an EC2 instance.

We will create a simple blueprint file that describes how EC2 instance should be created and upload it to Cloudify Manager.

To spin an EC2 instance we will created and install a deployment. As part of it Cloudify Manager will connect to AWS and create an EC2 instance as described in the blueprint.

Let’s Start

Cloudify Installation: Running locally Cloudify Manager is very easy. You’ll need to install locally on your machine docker and run on it Cloudify Manager Community edition container.

To run Cloudify Manager Community edition simply run the following command. You might wait some time until the application is fully up and running

sudo docker run --name cfy_manager_local -d --restart unless-stopped -v /sys/fs/cgroup:/sys/fs/cgroup:ro --tmpfs /run --tmpfs /run/lock --security-opt seccomp:unconfined --cap-add SYS_ADMIN -p 80:80 -p 8000:8000 cloudifyplatform/community-cloudify-manager-aio:latest

Congratulations now you can browse to http://localhost and login with default user and password admin:admin

Cloudify CLI installation

You have two ways to work with Cloudify Manager. You can work either with UI or CLI. In this article we will work CLI.

To install Cloudify CLI run the following command:

pip install cloudify==6.1.0

Installing Plugins

Before we start we need to install AWS and Utilities Plugin

To simplify let’s upload all supported plugins

cfy plugins bundle-upload

Terraform Blueprint

Let’s first walk through what we is the blueprint objective.

The blueprint receives the Terraform version. The Terraform binary URL will be calculated based on it.

The Terraform also requires variables and environment variables that should be filled during the deployment creation.

Now when we are aware of what the blueprint does let’s deep dive.

There are 5 inputs:

  1. terraform_version — The terraform version to be used. The default version is 0.13.0 but other version can be provided as well.
  2. module_location — The URL to zip or .git repository, the input doesn’t have a default value and it’s marked as required. Therefor it must be provided when running the blueprint.
  3. terraform_template_location — if the terraform template to be executed is in the root directory use the default value, In case it’s in a directory provide the relative path to it.
  4. variables — is a key, value dictionary, the expected key is the variable name and the value is the value to be passed
  5. environment_variables — same as the variables but for the environment variables

Terraform node type

The Terraform binary path is calculated based on the selected version. It’s concatination https://releases.hashicorp.com/terraform/ + VERSION +/terraform_ + VERSION + _linux_amd64.zip e.g if you use the default value 0.13.0 the URL will be https://releases.hashicorp.com/terraform/0.13.0/terraform_0.13.0_linux_amd64.zip

Terraform Module

The rest of the inputs, module_souce , terraform_template_location , variable , and environment_variables will be injected directly

let’s checkout the example and run it.

git clone git@github.com:cloudify-community/cloudify-tutorial.git
cd cloudify-tutorial/terraform/tf_09_terraform_blueprint

The directory contains two files. blueprint.yaml is the file we have described above. inputs.yaml is the file that contains the values for the blueprint‘s inputs.

The inputs.yaml have the following structure

If you haven’t set up secrets for your AWS account yet run the following command:

cfy secrets create YOUR_ACCESS_KEY_ID aws_access_key_id
cfy secrets create YOUR_AWS_SECRET_ACCESS_KEY aws_secret_access_key

Now we are ready to apply the changes

cfy apply -i inputs.yaml

comments

    Leave a Reply

    Your email address will not be published.

    Back to top