DevOps Classroom Series – 07/Oct/2020

Developer Environment for Terraform

  • Refer Here for installing necessary softwares for this course
  • Install Terraform:
    • Windows Machine:
      • Refer Here for offical downloads page
      • For installing and configuring Windows Terminal Refer Here
      • for installing chocolatey Refer Here
      • Installation steps
      choco install terraform -y
      refreshenv.cmd
      terraform --version
      

Working with Terraform

  • For offical docs Refer Here
  • To start working with terraform we need to understand
    • Provider:
      • The virtual environment where you want to create resources
      • Provider configuration will vary from vendor to other.
      • You will also need to setup credential info in terraform to communicate with Provider
    • Resource: The infrastructure to be created.
    • Arguments: arguments are inputs provided to terraform blocks (resource)
    • Attributes: outputs from terraform block (resource)
  • Basic Workflow Preview
  • For all the providers supported by terraform Refer Here
  • Steps for working with terraform
    • Make a note of manual steps for creating infrastructure
    • Configure the Provider with required credentials
    • Create a folder and start writing the resources which you want to create in a declarative style following terraform syntax

Experiment-1: Lets create a S3 bucket in AWS Cloud

  • Manual Steps: Preview Preview Preview Preview
  • Lets try to configure aws Provider:
    • Refer Here for official docs on configuring aws credentials
    • To get access key & secret key Refer Here
  • Create a new folder "hello-tf"
  • Now lets configure visual studio code to help us in writing terraform Preview
  • Create a file called as main.tf
  • Add provider and Refer Here
  • Configure your aws provider with access_key and secret key
provider "aws" {
    region      = "us-west-2"
    access_key  = "<your access key>"
    secret_key  = "<your secret key>"
}
  • So we need to create a resource s3 bucket Refer Here.
  • To write a basic resource the syntax is
resource "<resource type>" "<name>" {
    argument1   = value1
    ...
    argumentn   = value n
}
  • Lets add s3 resource defintion
resource "aws_s3_bucket" "mybucket" {
    bucket      = "qts3fromtf"
    tags = {
    Name        = "My bucket"
    Environment = "Dev"
    CreatedBy   = "Terraform"
  }
}
  • Now navigate to command line and execute
terraform --help # Get to know terraform command line
terraform init --help
terraform init . # this command will download providers to your machine
terraform validate --help
terraform validate .
terraform apply --help
terraform apply .

Preview Preview Preview Preview Preview Preview Preview

  • We have initialized (one time operation in a new folder)
  • Configured the provider & then declared the resource, then we have validated and applied the template
  • If you want to delete whatever is created
  • For sample used in classroom Refer Here

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin