GithubHelp home page GithubHelp logo

san99tiago / terraform-playground Goto Github PK

View Code? Open in Web Editor NEW
14.0 2.0 5.0 526 KB

My own public Terraform/Packer examples towards IaC deployments in AWS.

License: MIT License

Shell 1.48% HCL 92.84% JavaScript 0.29% Makefile 1.17% Python 4.21%
aws packer terraform devops-tools hcl iac iac-terraform infrastructure-as-code terraform-aws terraform-module

terraform-playground's Introduction

๐Ÿ”จ TERRAFORM-PLAYGROUND ๐Ÿ”จ

Learning Terraform with AWS examples.

This repository covers a simple-learning approach for Terraform (90%) and Packer (10%) with AWS.

We will cover important Infrastructure as Code (IaC) concepts that support the best DevOps practices.


General Overview of this Repository ๐ŸŠ

This repository is my own learning-playground for Terraform-based projects. It has different examples and the overall idea is to have fun with Infrastructure as Code projects towards AWS.

The examples are simple, but they are a good way to learn terraform from "scratch".

Dependencies ๐Ÿšฆ

My advice is to primary understand the way Terraform works with basic tutorials, and then try to develop amazing project ideas based on these examples.

Software dependencies (based on project)

  • Visual Studio Code
    Visual Studio Code is my main code editor for high-level programming. This is not absolutely necessary, but from my experience, it gives us a great performance and we can link it with Git and GitHub easily.

  • Terraform
    Terraform is a way to codify, automate, provision and version cloud APIs into declarative configuration files. The main purpose of Terraform is to create IaC for provisioning amazing infrastructure to different clouds.

  • Packer
    Packer allows us to create identical machine images for multiple platforms from a single source configuration. We will use it to create AWS AMIs to launch custom EC2 images.

Important Terraform Remarks ๐ŸŽง

Some important notes to keep in mind for the usage of Terraform are:

Install Terraform Bin/Exe

To install Terraform, please go to Download Terraform and install the specific version for your OS. Remember to add the specific path to the binary, so that Terraform CLI can be used correctly.

Terraform Files

Terraform files usually have the .tf extension and there is also the .tf.json convention for a JSON-based variant of the language. See extra details on Terraform Files and Directories.

Terraform State

One of the most important files are the terraform.tfstate and terraform.tfstate.backup, which determine the state and they can be stored locally or remotely. These files contain the state of the infrastructure and configurations related to the IaC. They also maps real world resources to the configuration and keep track of extra relevant information. You can learn more about the state in Terraform State

Terraform Dependency Lock

Another important file is the .terraform.lock.hcl, which is the Dependency Lock File and it tracks the provider dependencies.

Terraform Commands

  • Initialize Terraform directory and downloads providers:

    terraform init
  • Initialize Terraform directory and do not download providers:

    terraform init --get-plugins=false
  • Download and update root modules:

    terraform get
  • Create an execution plan:

    terraform plan
  • Create an execution plan only for a targeted resource:

    terraform plan -target="random_cool_resource.random_cool_resource_name"
  • Create a destroy plan:

    terraform plan -destroy
  • Execute (apply) changes in the real environment:

    terraform apply
  • Execute (apply) changes in the real environment with specific variable file:

    terraform apply --var-file dev.tfvars.json
  • Execute (apply) changes only for a targeted resource:

    terraform apply -target="random_cool_resource.random_cool_resource_name"
  • Destroy all resources:

    terraform destroy
  • Destroy only a targeted resource:

    terraform destroy -target="random_cool_resource.random_cool_resource_name"
  • Refresh the state of Terraform state file with real environment:

    terraform refresh
  • Terraform workspace commands:

    terraform workspace new
    terraform workspace select
    terraform workspace list
    terraform workspace show
    terraform workspace delete
  • Format Terraform files into HCL canonical structure:

    terraform fmt
  • Validate Terraform files:

    terraform validate
  • Create graph of resources and its dependencies:

    terraform graph
    # Copy the output to "http://webgraphviz.com"
  • Enumerates all outputs from the root module:

    terraform output
  • Enumerates an specific output from the root module:

    terraform output <specific_output>
  • Terraform state commands:

    terraform state list
    terraform state list aws_instance.my_cool_ec2
    terraform state show aws_instance.my_cool_ec2
    terraform state pull
    terraform state push
    terraform state mv
    terraform state rm

Important Packer Remarks ๐ŸŽง

Some important notes to keep in mind for the usage of Packer are:

Install Packer Bin/Exe

To install Packer, please go to Download Packer and install the specific version for your OS. Remember to add the specific path to the binary, so that Packer CLI can be used correctly.

How the AMI is created

When the AMI process is being executed, it usually creates an EC2 instance called Packer Builder. Keep this in mind if you want to do extra debugging related to the AMI creation on AWS.

Packer Commands

  • Validate a JSON file that creates an AMI:

    packer validate cool-ubuntu-aws-ami.json
  • Build the AMI with Packer and a JSON file:

    packer build cool-ubuntu-aws-ami.json

Usage ๐Ÿ’ซ

All projects are really well commented and most of them have specifications and remarks for their purpose and I/O.
I will be uploading most of the files, and try to keep it as clean as possible.

Special thanks ๐ŸŽ

  • Thanks to all contributors of the great OpenSource projects that I am using.

Author ๐ŸŽน

Santiago Garcia Arango

Senior DevOps Engineer passionate about advanced cloud-based solutions and deployments in AWS. I am convinced that today's greatest challenges must be solved by people that love what they do.

terraform-playground's People

Contributors

san99tiago avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

terraform-playground's Issues

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.