Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraweek challenge day 1 completed #5

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions day01/Answers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Q-1) What is Terraform and how can it help you manage infrastructure as code?
Ans- Terraform, developed by HashiCorp, is an open-source Infrastructure as Code (IaC) tool.
It leverages a declarative language called HCL (HashiCorp Configuration Language) to define its resources.
If you prefer to add unnecessary complexity, you can also use JSON to define resources.

If you go back two decades, everyone uses those physical servers (produced by IBM, HP, and Cisco) which took weeks to setup correctly before we could run the applications on them.
Then came the time of virtualization, sharing computer resources across multiple OS installations using Huper V Virtualization technologies such as VMware.

Following that, AWS emerged and revolutionized the computing landscape, ushering in a new era of streamlined cloud computing.
Subsequently, other prominent tech giants like Microsoft and Google introduced their own cloud offerings, namely Azure and Google Cloud Platform, respectively

Within the cloud environment, it's effortless to deploy a server within minutes with a few simple clicks.
Initially, creating and handling a handful of servers was a straightforward task.
However, as the number of servers and their associated configurations increased, manual tracking became a difficult challenge.

Terraform can manage infrastructure on multiple cloud platforms.
The human-readable configuration language helps you write infrastructure code quickly.
Terraform's state allows you to track resource changes throughout your deployments.
You can commit your configurations to version control to safely collaborate on infrastructure.


Q-2) Why do we need Terraform and how does it simplify infrastructure provisioning?
Ans- Below are some challenges before IAC
1) Reproducibility and Disaster Recovery
2) Limited Collaboration and Managing Operations
3) Lack of Scalability and flexibility
4) Inconsistency and Configuration Drift
5) Lack of Visibility and Auditability
6) Manual and Error-prone Process

Introducing IAC - Infrastructure as Code
Infrastructure as Code(IAC) is a combination of standards, practices, tools, and processes to provision, configure, and manage computer infrastructure using code and other machine-readable files.

IAC solved all the above-mentioned challenges and added a ton of additional benefits.
Improved visibility, audibility, and security.
Scalability and Flexibility
Reusability
Faster Disaster Recovery
Improved Efficiency
Increased reliability
Improved Collaboration and agility

Q-3) How can you install Terraform and set up the environment for AWS, Azure, or GCP?
Ans- To install terraform as per you system configuration visit https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli

For Linux installation run these commands on the terminal
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform

Q-4) Explain the important terminologies of Terraform with the example at least (5 crucial terminologies).
Ans- Certainly! Here are five crucial terminologies in Terraform along with examples to help illustrate their significance:
1) Provider: A provider is a plugin that interacts with a specific infrastructure platform (e.g., AWS, Azure, or Google Cloud Platform) and exposes the resources and services provided by that platform to Terraform. It enables Terraform to manage resources on the target infrastructure. For example, the "aws" provider in Terraform allows you to provision and manage resources in Amazon Web Services (AWS).

2)Resource: A resource represents a tangible infrastructure component that you want to manage with Terraform. It could be a virtual machine, a network interface, a database instance, or any other entity provided by the infrastructure platform. For instance, an example of a resource in Terraform is an AWS EC2 instance:
resource "aws_instance" "example" {
ami = "ami-0c94855ba95c71c99"
instance_type = "t2.micro"
}


3) Module: A module is a self-contained and reusable Terraform configuration that encapsulates a set of resources and their dependencies. Modules promote code organization, reusability, and modular design principles. They allow you to encapsulate complex configurations and manage them independently. For example, you might create a module that provisions a complete web application stack, including compute instances, load balancers, and databases, which can be reused across multiple environments or projects.

4)Variable: Variables in Terraform allow you to parameterize your configurations, making them more flexible and reusable. They act as placeholders for values that can be provided externally when running Terraform commands. Variables can be defined at different levels, such as in the root module or within a module. Here's an example of defining and using a variable in Terraform:
variable "aws_region" {
description = "The AWS region where resources will be provisioned"
default = "us-west-2"
}

resource "aws_instance" "example" {
ami = "ami-0c94855ba95c71c99"
instance_type = "t2.micro"
region = var.aws_region
}

5)Output: Outputs in Terraform allow you to extract and display information from your infrastructure after it has been provisioned. They provide a way to expose values of interest, such as IP addresses, resource identifiers, or connection details, for reference or further processing. Here's an example of defining an output in Terraform:
output "instance_ip" {
description = "The public IP address of the instance"
value = aws_instance.example.public_ip
}
135 changes: 135 additions & 0 deletions day02/Answers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
TerraWeek Day 2

# Learn about HCL blocks, parameters, and arguments ?

- In Terraform, the HashiCorp Configuration Language (HCL) is used to define infrastructure resources and their configurations. The main building block in HCL is the block.

## Block
- A block in HCL consists of a block type, block labels, and block arguments. It has the following syntax:

block_type block_label {
argument_name = argument_value
...
}

## Parameters:
- Parameters are generally used to refer to the inputs or variables that are defined in a Terraform module or configuration.

## Arguments:
- Arguments are the actual values provided to the parameters or block attributes within a Terraform module or configuration.


# Terraform provides several types of resources and data sources that you can use to define and interact with different infrastructure components. Here are some commonly used types:

## Resource Types:

1) aws_instance: Represents an EC2 instance in Amazon Web Services (AWS).
2) azurerm_virtual_machine: Represents a virtual machine in Microsoft Azure.
3) google_compute_instance: Represents a virtual machine in Google Cloud Platform (GCP).
4) docker_container: Represents a Docker container.
5) kubernetes_deployment: Represents a deployment in Kubernetes.
6) aws_s3_bucket: Represents an S3 bucket in AWS.
7) google_storage_bucket: Represents a storage bucket in GCP.
8) aws_lambda_function: Represents an AWS Lambda function.
9) google_cloudfunctions_function: Represents a Google Cloud Function.

## Data Sources:

1) aws_ami: Fetches information about an Amazon Machine Image (AMI) in AWS.
2) azurerm_virtual_machine: Retrieves details about a virtual machine in Azure.
3) google_compute_network: Retrieves information about a network in GCP.
4) docker_image: Fetches information about a Docker image.
5) github_repository: Retrieves information about a GitHub repository.
6) local_file: Retrieves content from a local file.
7) terraform_remote_state: Retrieves outputs from a remote Terraform state.

# Variables and Data Types

variable "my_string_variable" {
type = string
default = "Hello, World!"
}

variable "my_number_variable" {
type = number
default = 42
}

variable "my_boolean_variable" {
type = bool
default = true
}

variable "my_list_variable" {
type = list
default = ["item1", "item2", "item3"]
}

variable "my_map_variable" {
type = map
default = {
key1 = "value1"
key2 = "value2"
}
}

variable "my_object_variable" {
type = object({
attribute1 = string
attribute2 = number
})
default = {
attribute1 = "Hello"
attribute2 = 123
}
}


# Create a variables.tf file and define a variable Use the variable in a main.tf file to create a "local_file" resource

## variabel.tf file
variable "path" {
type = string
default = "/home/ubuntu/terraform-course-TWS/terraform-variables/auto_generated_file.txt"
}

## main.tf file
resource "local_file" "my_local_file" {
filepath = var.path
content = "this file uses variable"
}

## HCL code to create ec2 instance

terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = " ~> 4.16"
}
}
required_version = ">= 1.2.0"
}

provider "aws" {
region = "us-east-1"
}

resource "aws_instance" "my_ec2_instance" {
count = 3
ami = "ami-053b0d53c279acc90"
instance_type = "t2.micro"
tags = {
Name = "terraform_TWS_challenge_instance"
}
}
output "ec2_public_ips" {
value = aws_instance.my_ec2_instance[*].public_ip
}
resource "aws_s3_bucket" "my_s3_bucket" {
bucket = "terraweek-challenge-s3bucket-2301"
tags = {
Name = "terraweek-challenge-s3bucket-2301"
Envieonment = "dev"
}
}