Terraform Introduction and Basics with AWS

Today’s world is completely data-driven. Each encounter is a data point. The emails you send are managed by Google’s servers as data. Every interaction is a piece of data. However, as you may have noted, they are linked to the internet and not physically joined.  All of a company’s needs in terms of software as a service, platform as a service, and infrastructure as a service may be met by Cloud Computing. Nowadays, no one enjoys making software for each of their use cases, building platforms, or managing their own data center.

Steve Jobs said, and I quote, “I don’t need a hard disk in my computer, if I can get a server faster.” Carrying around those non-connected computers is byzantine by comparison. In this age of the cloud, Steve’s brilliance is obvious.

There are many software as a service (SaaS) providers nowadays, and many of them use cloud providers like Amazon Web Services, Microsoft Azure, Google Cloud Platform and others. However, the costs associated with maintaining such softwares will continue to rise indefinitely as their usage increases. The many services are each assumed to have their own infrastructure, including networks, virtual machines, databases, load balancers, and more. Not going to explain every nuance, but hopefully you get the gist. A large group of people would be needed to handle this. 

Following terraform, an entrant emerged. Terraform is an open-source infrastructure-as-code software solution that enables you to build, modify, and enhance your infrastructure in a reliable and consistent manner. Cloud LaaS resource provisioning, management, and modification became as easy as writing a single line of code.

What is Infrastructure as Code with Terraform?

Infrastructure as Code (IaC) tools let you control infrastructure with configuration files, optimal JSON (GUI). IaC allows you to develop, alter, and manage your infrastructure in a safe, consistent, and repeatable way.

HashiCorp makes Terraform, an infrastructure-as-code technology. It maintains your infrastructure’s lifespan and allows you to define resources and infrastructure in human-readable configuration files. Terraform is better than hand-managing infrastructure in various aspects.

  • Terraform supports multiple cloud platforms
  • Easy-to-read configuration language speeds up infrastructure coding
  • Terraform’s state lets you track resource changes during deployment
  • Allows safe collaboration on infrastructure by versioning configurations
  • It’s open-source

Terraform Basics

Getting Started with Terraform

What would you need? 

->Terraform CLI

-> AWS CLI

-> An Editor, preferably VS Code

-> Terraform VS Code Editor IDE

Installation on MacOS

Terraform Installation

Download Terraform MAC
Install CLI

Unzip the package

# Copy binary zip file to a folder

mkdir /Users/<YOUR-USER>/Documents/terraform-install

COPY Package to “terraform-install” folder

# Unzip

unzip <PACKAGE-NAME>

unzip terraform_0.14.3_darwin_amd64.zip

# Copy terraform binary to /usr/local/bin

echo $PATH

mv terraform /usr/local/bin

# Verify Version

terraform version

VS Code and Terraform Plugin Installation

Microsoft Visual Studio Code Editor
Hashicorp Terraform Plugin for VS Code

AWS CLI Installation 

# Install AWS CLI V2

curl “https://awscli.amazonaws.com/AWSCLIV2.pkg” -o “AWSCLIV2.pkg”

sudo installer -pkg AWSCLIV2.pkg -target /

which aws

aws –version

Configure AWS Credentials

aws configure

AWS Access Key ID [None]: AKIASUF7DEFKSIAWMZ7K

AWS Secret Access Key [None]: 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

Default region name [None]: us-east-1

Default output format [None]: json

# Verify if we are able list S3 buckets

aws sts get-caller-identity

Installation on Linux

Terraform Installation

Download Terraform MAC
Install CLI

VS Code and Terraform Plugin Installation

Microsoft Visual Studio Code Editor
Hashicorp Terraform Plugin for VS Code

AWS CLI Installation  and AWS Credentials

AWS CLI

Follow similar steps from macOS to configure AWS-CLI

Installation on Windows

Terraform Installation

Download Terraform
Install CLI

Unzip the package

Create new folder terraform-bins

Copy the terraform.exe to a terraform-bins

Set PATH in windows

VS Code and Terraform Plugin Installation

Microsoft Visual Studio Code Editor
Hashicorp Terraform Plugin for VS Code

AWS CLI Installation  and AWS Credentials

AWS CLI

Follow similar steps to configure AWS-CLI

Terraform Workflow and Commands

Terraform blocks can be very confusing. To make it simple to understand, we will cover terraform workflow and move right into some command basics. 

Command: terraform init

With this, the config directory, which stores all of the setup files, may be initialized. Basically, this is executed anytime a piece of code is added or removed from the configurations. The providers are downloaded at your command (basically AWS plugin in our case).

Command: terraform validate

Performs a syntax check and an integrity check on the configuration files to ensure they are valid. The term “internally consistent” refers to the fact that all resource changes have been checked. Attempting to delete an empty resource, for instance, should fail validation.

Command: terraform plan

This command creates an execution plan and notifies what all changes are likely to be made. 

Command: terraform apply

Apply is used to apply the configuration as the name suggests.

Command: terraform destroy

Used to destroy a configuration, and applies the change post user confirmation.

Demo Project to Create an EC2 machine using Terraform

With an understanding of what these commands perform, now write some code to build a VM in AWS, often known as EC2 or Elastic Cloud Compute. However, you must first meet the following requirements:

  1. There is an active VPC in the region
  2. AWs Credentials is working 

Let’s create our first terraform-manifests. You can use this sample code below.

# Terraform Settings Block

terraform {

  required_providers {

    aws = {

      source  = “hashicorp/aws”

      #version = “~> 3.21” # Optional but recommended in production

    }

  }

}

# Provider Block

provider “aws” {

  profile = “default” # AWS Credentials Profile configured on your local desktop terminal  $HOME/.aws/credentials

  region  = “us-east-1”

}

# Resource Block

resource “aws_instance” “ec2demo” {

  ami           = “ami-04d29b6f966df1537” # Amazon Linux in us-east-1, update as per your region

  instance_type = “t2.micro”

}

As you would see, Terraform employs three different blocks: the Settings block, the Provider block, and the Resource block. For the time being, we may ignore this and concentrate on the terraform init/validate/plan/apply/destroy command. In our subsequent blog, we’ll go into greater depth on this topic. 

The following is provided solely for your education: 

The cloud provider’s Terraform plug-in and the Terraform version are both specified in the settings block. It’s AWS for us. After declaring the resource in the resource block, we specify the cloud provider’s area in which the resource will be created in the provider’s block.

Command Execution

Step 1: Go to the location where you saved the manifest. The current working directory should be the same as the location of your Terraform manifests. Now let’s run terraform init. This would start the terraform and load the AWS HashiCorp plug-in. Along with it, a terraform.lock.hcl file is generated. It saves the version we’re using so that if there are any changes in the future, it can refer to it.

Step 2: At this point, we can run terraform validation. It will notify you if there is a problem with the file. Otherwise, a configuration valid message will be displayed on the screen.

Step 3: Now execute the terraform plan. This will print all of the resources that terraform will be producing as part of this project. The ‘+’ symbol indicates that it will create it, while the ‘-‘ sign indicates that it will modify it.

 

Step 4: Finally, run and apply terraform. This time, construct a plan and ask for yes or no confirmation. Choose yes – this will launch an ec2 instance.

Conclusion

A fundamental understanding of Terraform is now at your disposal. Declarative language makes it simple to define the exact system architecture you need to build. You can test your modifications and find bugs before releasing them with the plan command. You can maintain DRY and effective code with the help of variables, references and dependencies, which will be covered in subsequent blogs.

Remember, we have barely begun to scratch the surface. For how to manage Terraform state demonstrates, how Terraform remembers the infrastructure it has already built, and how it has far-reaching implications for the way you organize your Terraform code – stay tuned for the next Terraform series. 

 

 

AWS developer toolkit: In-demand skills, learning resources, online courses, interview prep, books & more

Cloud computing has changed the infrastructural architecture of the internet in far more ways than any other technology has. And among all major cloud platforms, AWS or Amazon Web Services takes the giant share. 

To give you an idea, AWS owns more share of the cloud market than four of its closest competitors combined. The ubiquity of the AWS platform is why there is such a huge demand for AWS developers. There is a good chance that any software engineer job requirement will list AWS as a required or expected skill. If you take the time to understand AWS development, you will be a distinguishable and highly valued developer at any organization. 

As the functionality and number of services in AWS are in the hundreds, it can be overwhelming to find the right resources. This AWS developer toolkit is your complete guide for the best resources to learn AWS development.

  1. Deployment: The most basic but essential AWS skill is deployment. There are numerous ways to deploy an application on AWS. It would help if you kept learning AWS deployment because it is frequently upgraded to accommodate technological advancements. You must know concepts like EC2 instance, CloudFormation, Elastic Beanstalk, Elastic Container Service (ECS), and Elastic Kubernetes Service.
  2. AWS SDK: For any application to interact with AWS, it needs to connect with the AWS Software Development Kit. If you have experience with application interactions, you know how APIs are used to collect two applications. The API layer in AWS SDK is vast, and even pros are surprised to find how much can be accomplished with it. As an AWS developer, you must understand how to work with the SDK. Using AWS for your applications becomes easier when you know everyday AWS SDK tasks, such as connecting to a DynamoDB table or pulling down an object from an S3 bucket.
  3. Security: While AWS can open a new frontier of scalability and decentralization, it also comes with specific challenges. You are on your own when creating a production environment, and it is essential to understand the ins and outs of the AWS security model and Identity Access Management or IAM. Most of the bugs arising in AWS result from developers’ misunderstanding of IAM. As a developer, you are expected to understand how Roles and Policies work.
  4. Serverless: More and more developers are relying on AWS’ serverless services like Lambda and API Gateway to solve their problems. Understanding when and why to use serverless solutions is essential for any AWS developer. According to Amazon, “A serverless architecture is a way to build and run applications and services without having to manage infrastructure. Your application runs on servers, but AWS manages all the servers.”

Developers who understand serverless are more in demand as they know how to utilize the modern infrastructure to create systems that scale as the requirement arises. A Serverless Framework is one critical open-source framework that makes it more accessible. As a developer, you must be familiar with Serverless Framework.

Official resources 

Online courses and tutorials for AWS developers 

It is the best course to get started with an overview of the features, capabilities, and benefits of Amazon Web Services. The AWS fundamentals specialization course teaches all core services of the platform and its vital security concepts. It also discusses the basics of building serverless applications with AWS.

Udemy offers this AWS course for developers. It covers the end-to-end implementation of the significant components of AWS. It moves on from the part about how to get started with the AWS technologies to more complex concepts such as SSHING. 

For any cloud engineer, security is one of the most important concepts to master. This AWS course teaches developers the fundamentals of cloud security, compliance, and the shared responsibility model of AWS. There are several AWS services covered in this course, such as Amazon GuardDuty, Amazon CloudWatch, Amazon VPC, AWS Security Hub, AWS Secrets Manager, and Amazon S3.

FreeCodeCamp offers this YouTube tutorial. Its practical guide approach to teaching AWS cloud platform is different from other courses. It teaches startups to get started with a cloud platform, create an account, deploy the application, and budget scale.

Books for AWS developers 

Online communities for AWS developers 

Podcasts for AWS developers

  1. Communication: Good communication is necessary for every professional. Developers are no exceptions. When working on a complex project, they need to work with others. Effective communication is essential to ensure everyone on the team is on the same page and that all deadlines are met. Apart from nurturing your technical skills as an AWS developer, it would help if you worked on speaking clearly and confidently too.
  2. Patience: It is not uncommon behavior for developers to get frustrated. Bugs are a routine for developers and can easily lead to frustration. However, it is a weak emotion, and you must practice patience. Best software engineers know how to handle pressure and keep a calm demeanor even when things seem worse. When you are patient, you are in a better position to make rational decisions and lead teams.
  3. Problem-solving / critical thinking: These skills are paramount to software development. Out of all the soft skills, this one has the most significant effect on the career graph of a developer. Your ability to think outside the box makes you unique as a developer. The difference between us and computers is that we are not set to follow an algorithmic path. We can use unimaginable creativity to solve problems.

Here are more resources to learn about essential soft skills.

Conclusion 

AWS is the market leader in cloud computing, and it makes sense to focus on becoming an AWS developer. AWS is a highly lucrative skill, and we hope this AWS developer toolkit provides you with all the essential learning and interview preparation resources you require.

Talent500 is the platform that AWS developers can use to find career re-defining opportunities at global companies. Sign up here and be job ready.