Infrastructure-as-Code Series: Project Structure

Wednesday, Sep 26, 2018 10:50 · 357 words · 2 minutes read terraform devops iac series

Infrastructure-as-Code Series

  1. Getting Started
  2. Project Structure
  3. DNS (Part 1)
  4. DNS (Part 2)

In my previous blog post “Infrastructure-as-Code Series: Getting Started” I have described how to setup Terraform on your machine and how to apply in different infrastructure configuration scenarios.

Project Tree

Create your project structure using the following directory hierarchy:

▾ dc/
    ▾ fra1/
        ▾ production/
        ▾ staging/
    ▾ tor1/
        ▾ production/
        ▾ staging/
▾ dns/
    ▾ templates/
▾ lb/
▾ nodes/
    ▾ templates/

Brief Description of the Project Structure

  • dc – data centers (fra1, tor1) specific configuration settings per environments (staging, production)
  • dns – dns definitions
  • lb – public load-balancers definitions
  • nodes – compute nodes definitions
  • Makefile – a makefile with all commands for validating, debugging, deploying and destroying cloud infrastructure

Test the Project

Initialize (if needed) your project:

terraform init

Initializing provider plugins...
- Checking for available provider plugins on
- Downloading plugin for provider "digitalocean" (0.1.3)...
- Downloading plugin for provider "template" (1.0.0)...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.digitalocean: version = "~> 0.1"
* provider.template: version = "~> 1.0"

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

Run the debug command under your project:

export TF_VAR_digitalocean_token=<DO_TOKEN>

make debug dc=tor1 env=production op=nodes

In the next blog post I will describe how to provision DNS setup for your infrastructure.

The complete demo application, described in this blog post, can be found here.
comments powered by Disqus