Git Product home page Git Product logo

terraform-cheatsheet's Introduction

Terraform CheatSheet

A usefull cheatsheet for Terraform usage. Written by Germain LEFEBVRE by August 2018 from Terraform v0.11.7.

Table of Contents

  1. Context
  2. Terraform Commands
  3. Terraform configuration management
    1. Global variables
    2. Environment management
    3. Requiring variables
    4. Environments variables

Context

See version of Terraform with terraform --version :

Terraform v0.11.7

Terraform commands

The first step to know is all your structure will be store in a main.tf file in your current directory.

These are the main Terraform commands.

Show Terraform help.

terraform --help

Usage: terraform [--version] [--help] <command> [args]

Initiliaze your Terraform directory (1st step needed with new directory). terraform init

Validate your Terraform files, coherence in structure but no syntax checking.

terraform validate

See what Terraform will change but not applying any change.

terraform plan

Apply modifications on your infrastructure.

terraform apply

Remove all your modifications (made with apply). terraform destroy

Terraform configuration management

Global variables

With the art of calling all your resources from a main.tf file you will have a another files containing all your variables. The file name does not matter while your call it with the .tf extension. Whatever the way your name it, variables.tf or vars.tf, it will be call while it remains in the same directory of your main.tf file.

./
 +-- main.tf
 +-- vars.tf

Environment management

Take care to your configuration files if your want to manage different environments becasue it will change regarding the way your wnat to handle it.

I have a particular preference for managing config files with files but no workspace because everything is files in Linux. To do so you will pay attention to seprate every environments in different files (dev, sit, qa, prod, ...).

Requiring variables

The main thing to know is you need a global variables file to specify your required variables. As requiring vars file I mean the Global variables files described just above.

Environments variables

After describing requiring variables you can play in creating structure by environment (directories) and setup a file with your environment vars. The name of this file does not matter in a chaos way. But if you want to make automation I suggest you to name the env files exactly the same in all your env directories.

Considering your resource file named main.tfand your global vars file name variables.tf you wil have a file structure like this :

./
+-- dev/
    +-- vars.tf
+-- prod/
    +-- vars.tf
+-- main.tf
+-- variables.tf

Like this files main.tf and variables.tf wil be called at every terraform run. You will just need to specify your environment file with the parameter -var-file=<you_file> :

terraform plan -var-file=./dev/vars.tf

terraform-cheatsheet's People

Contributors

germainlefebvre4 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.