1. Overview

Introduction

  • Terraform is tool for building, changing, and versioning infrastructure safely and efficiently

  • It enables application software best practices to infrastructure

  • Compatible with many clouds and services

  • Written in hashicorp configuration language in a file that has .tf extension


Architecture

Providers

  • It is a plugin that allows us to talk to set of APIs

  • For instance, to interact with AWS, we have to download the AWS provider

  • Similarly, in order to interact with Kubernetes, we have to download the Kubernetes provider


Data

  • Used to reference the existing resources in the cloud


Basic Commands

  1. terraform init - looks for all the providers in all config files in current directory and downloads the necessary plugins

  2. terraform plan - does a dry run of your code

  3. terraform apply - to run our code


Sample Activity Code

#####################
# Setting up provider
# Hard coded autentication credentials, non recommended way
#####################
provider "aws" {
  region = "us-east-1"
  access_key = "<access_key>"
  secret_key = "<secret_key>"
}

#####################
# Making a resource
# Same syntax for every provider
#
# resource "<provider>_<resource_type>" "name" {
#   config options.....
#   key = "value"
# }
#####################

#####################
# Deploying EC2 Instance
#####################
resource "aws_instance" "my-first-server" {
    ami = "ami-052efd3df9dad4825"
    instance_type = "t2.micro"

Last updated