Giter VIP home page Giter VIP logo

gcp-terraform-ansible-example's Introduction

gcp-terraform-ansible-example

A simple example of terraform and ansible usage in Google Cloud Platform context

Terraform

Terraform is an open-source sofware tool designed to handle Infrastructure as Code (IaC) created by HashiCorp (https://www.hashicorp.com/). The infrastructure is described using HashiCorp Configuration Language (HCL). Learn more on Terraform documentation

Ansible

Ansible is an open-source software tool designed to manage configuration and application-deployment (Kind of Infrastructure as Code). Ansible was written by Michael DeHaan and acquired by Red Hat in 2015. I can configure Unix systems as well as Microsoft Windows. YAML is used to describe system configuration.

Ansible is agentless and temporarily connects remotely via SSH or Windows Remote Management to do its tasks. Learn more on Ansible documentation

Terraform or Ansible ?

Terraform and Ansible are complimentary tools. Terraform helps in the definition and the creation of the infrastructure, Ansible configures and deploys software on the infrastructure created using Terraform (or not).

It's possible to run Ansible from Terraform using a local-exec provisioner (See more on the documentation). Nonetheless our goal is to discover both tools so we will run them separately.

What are we doing ?

Using Terraform this example will lead you to deploy two Compute Engines (virtual machines) on Google Cloud Platform.

One will be located in the region us-central zone us-central1-c (Council Bluffs, Iowa, North America) and the second one in the region europe-west zone europe-west1-b (St. Ghislain, Belgium, Europe). More on : Google Cloud Regions and Zones.

Those virtual machines will host the same ssh key and will share a same VPC (but within different sub-networks). See GCP VCP Documentation.

A firewall rule with be deployed to only authorize SSH connections from the terraform host IP (not really a good idea is a real usage, were are doing it as a technical example).

Another firewall rule will authorize connections on the port 80 (HTTP Protocol) to machines tagged with allow-http.

The second step will be the Ansible execution to install the latest version Apache Server Web, replace the default apache page by our custom page then change an information on this page to differentiate the two machines.

Terraform : structure explanation

The terraform folder contains the following files :

  • main.tf : The main definition which contains the description of the two virtual machines, firewall rules and project-scoped ssh key.
  • outputs.tf : Defines the final output of the terraform execution
  • terraform.tfvars.tpl : A file to complete (it contains our variable), to rename as terraform.tfvars and to place in the (see below) credential folder.

A folder credentials is ignored thanks to the .gitignore file to let you store your credentials (GCP key, SSH keys, terraform.tfvars) and avoid a commit accident.

Ansible : structure explanation

The ansible folder contains the following files :

  • playbook.yml : The Ansible playbook (see documentation) we will run to executes tasks.
  • hosts.tpl : A file to complete and rename as hosts which contains the ansible username (see Terraform ssh key configuration), the path
  • ansible.cfg : A ini config which indicates that hosts are in the hosts file.
  • the www folder

Credits

HTML template

The HTML template used to differentiate VM1 and VM2 is based on Tobias Ahlin work : https://tobiasahlin.com/moving-letters/

gcp-terraform-ansible-example's People

Contributors

nassimbounouas avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

vinodr1989

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.