DevOps Classroomnotes 18/May/2022

Installing Terraform

  • Windows: We have two options for installing terraform
    • Chocolatey:
      • Install chocolatey Refer Here
      • Use Chocolatey to install terraform choco install terraform
    • Manually configure terraform Refer Here
  • Mac: Refer Here brew install terraform

Working with Terraform

  • Identify the infrastructure you need to create/provision
  • Identify the providers
  • Configure the provider using HCL (Hashicorp Configuration Language)
  • Configure the resources to be created using HCL

Activity 1: Create an S3 Bucket in AWS

  • Manual Steps: Login to the AWS Account
    Preview
    Preview
    Preview
    Preview
    Preview
    Preview
    Preview
  • Provider is where to create infra and Resource is what we are trying to create.
  • In the above case
    • Provider: AWS
    • Resource: S3 Bucket
  • In AWS to connect to aws account we had to login using email and password.
  • Generally Provider configuration involves authentication and it depends on how provider allows it.
  • Refer Here for the terraform providers
  • AWS Provider documentation
    Preview
  • To work with AWS Provider we need access key and secret key, lets see how to generate it Refer Here
  • Refer Here for the documentation of the s3 bucket
  • Now lets try to create infra from terraform
    Preview
  • Initialize the directory
    Preview
  • Validate the configuration
    Preview
  • Now lets create the infrastructure terraform apply
    Preview
    Preview
  • Now to remove the infra terraform destroy
    Preview
  • The configuration which we used
provider "aws" {
    access_key  = "<your-access-key>"
    secret_key  = "<your-secret-key>"
    region      = "ap-south-1"
}

resource "aws_s3_bucket" "b" {
  bucket = "qt-tf-s3-1"

  tags = {
    Name        = "My bucket"
    Environment = "Dev"
  }
}

Terraform Language

  • Terraform configuration can be expressed in
    • HCL/Terraform Language
    • JSON
  • The two major elements in the Terraform language are
    • Arguments:
      • Assigns a value to a particular name bucket = "qt-tf-s3-1"
    • Blocks:
      • A block is container for other content
      • Three major blocks of terraform are
        • provider block
        • resource block
        • datasource block

Provider Block:

  • Basic Syntax:
provider "<provider-name>" {
    <argument-1>
    <argument-2>
    ..
    <argument-n>
}
  • Example
provider "aws" {
    access_key  = "LKJLKSKLJDALDJLKSADSLA"
    secret_key  = "lksdfjdlkasfjlsadfjlksdafjlksdafjdallksafj"
    region      = "ap-south-1"
}

Resource Block

  • Basic Syntax
resource "<PROVIDER>_<TYPE>" "<NAME>" {
    <argument-1>
    <argument-2>
    ..
    <argument-n>
}
  • Example
resource "aws_s3_bucket" "b" {
  bucket = "qt-tf-s3-1"

  tags = {
    Name        = "My bucket"
    Environment = "Dev"
  }
}

Cloud Account Creations

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

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

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube