Skip to content

Commit 2385dd5

Browse files
committed
Welcome to StackSimplify
1 parent f9ad926 commit 2385dd5

File tree

685 files changed

+31335
-201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

685 files changed

+31335
-201
lines changed

.gitignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/ADDITIONAL-TOPICS
2+
FUTURE-TOPICS
3+
#.gitignore
4+
5+
# macOS Files
6+
.DS_Store
7+
8+
# Ignore .sh files
9+
#*.sh
10+
11+
# Terraform Files and Folders
12+
.terraform
13+
*.tfstate
14+
*.tfstate.backup
15+
#.terraform.lock.hcl
16+
#*.tfvars
17+
18+
# Ignore .pem files
19+
#*.pem
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Infrastructure as Code Basics
2+
3+
## Step-01: Understand Problems with Traditional way of Managing Infrastructure
4+
- Time it takes for building multiple environments
5+
- Issues we face with different environments
6+
- Scale-Up and Scale-Down On-Demand
7+
8+
## Step-02: Discuss how IaC with Terraform Solves them
9+
- Visibility
10+
- Stability
11+
- Scalability
12+
- Security
13+
- Audit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Terraform & AWS CLI Installation
2+
3+
## Step-01: Introduction
4+
- Install Terraform CLI
5+
- Install AWS CLI
6+
- Install VS Code Editor
7+
- Install HashiCorp Terraform plugin for VS Code
8+
9+
10+
## Step-02: MACOS: Terraform Install
11+
- [Download Terraform MAC](https://www.terraform.io/downloads.html)
12+
- [Install CLI](https://learn.hashicorp.com/tutorials/terraform/install-cli)
13+
- Unzip the package
14+
```
15+
# Copy binary zip file to a folder
16+
mkdir /Users/<YOUR-USER>/Documents/terraform-install
17+
COPY Package to "terraform-install" folder
18+
19+
# Unzip
20+
unzip <PACKAGE-NAME>
21+
unzip terraform_0.14.3_darwin_amd64.zip
22+
23+
# Copy terraform binary to /usr/local/bin
24+
echo $PATH
25+
mv terraform /usr/local/bin
26+
27+
# Verify Version
28+
terraform version
29+
30+
# To Uninstall Terraform (NOT REQUIRED)
31+
rm -rf /usr/local/bin/terraform
32+
```
33+
34+
## Step-03: MACOS: IDE for Terraform - VS Code Editor
35+
- [Microsoft Visual Studio Code Editor](https://code.visualstudio.com/download)
36+
- [Hashicorp Terraform Plugin for VS Code](https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform)
37+
38+
39+
### Step-04: MACOS: Install AWS CLI
40+
- [AWS CLI Install](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html)
41+
- [Install AWS CLI - MAC](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-mac.html#cliv2-mac-install-cmd)
42+
43+
```
44+
# Install AWS CLI V2
45+
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
46+
sudo installer -pkg AWSCLIV2.pkg -target /
47+
which aws
48+
aws --version
49+
50+
# Uninstall AWS CLI V2 (NOT REQUIRED)
51+
which aws
52+
ls -l /usr/local/bin/aws
53+
sudo rm /usr/local/bin/aws
54+
sudo rm /usr/local/bin/aws_completer
55+
sudo rm -rf /usr/local/aws-cli
56+
```
57+
58+
59+
## Step-05: MACOS: Configure AWS Credentials
60+
- **Pre-requisite:** Should have AWS Account.
61+
- [Create an AWS Account](https://portal.aws.amazon.com/billing/signup?nc2=h_ct&src=header_signup&redirect_url=https%3A%2F%2Faws.amazon.com%2Fregistration-confirmation#/start)
62+
- Generate Security Credentials using AWS Management Console
63+
- Go to Services -> IAM -> Users -> "Your-Admin-User" -> Security Credentials -> Create Access Key
64+
- Configure AWS credentials using SSH Terminal on your local desktop
65+
```
66+
# Configure AWS Credentials in command line
67+
$ aws configure
68+
AWS Access Key ID [None]: AKIASUF7DEFKSIAWMZ7K
69+
AWS Secret Access Key [None]: WL9G9Tl8lGm7w9t7B3NEDny1+w3N/K5F3HWtdFH/
70+
Default region name [None]: us-east-1
71+
Default output format [None]: json
72+
73+
# Verify if we are able list S3 buckets
74+
aws s3 ls
75+
```
76+
- Verify the AWS Credentials Profile
77+
```
78+
cat $HOME/.aws/credentials
79+
```
80+
81+
## Step-06: WindowsOS: Terraform & AWS CLI Install
82+
- [Download Terraform](https://www.terraform.io/downloads.html)
83+
- [Install CLI](https://learn.hashicorp.com/tutorials/terraform/install-cli)
84+
- Unzip the package
85+
- Create new folder `terraform-bins`
86+
- Copy the `terraform.exe` to a `terraform-bins`
87+
- Set PATH in windows
88+
- Install [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html)
89+
90+
## Step-07: LinuxOS: Terraform & AWS CLI Install
91+
- [Download Terraform](https://www.terraform.io/downloads.html)
92+
- [Linux OS - Terraform Install](https://learn.hashicorp.com/tutorials/terraform/install-cli)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Terraform Command Basics
2+
3+
## Step-01: Introduction
4+
- Understand basic Terraform Commands
5+
- terraform init
6+
- terraform validate
7+
- terraform plan
8+
- terraform apply
9+
- terraform destroy
10+
11+
## Step-02: Review terraform manifest for EC2 Instance
12+
- **Pre-Conditions-1:** Ensure you have **default-vpc** in that respective region
13+
- **Pre-Conditions-2:** Ensure AMI you are provisioning exists in that region if not update AMI ID
14+
- **Pre-Conditions-3:** Verify your AWS Credentials in **$HOME/.aws/credentials**
15+
```t
16+
# Terraform Settings Block
17+
terraform {
18+
required_providers {
19+
aws = {
20+
source = "hashicorp/aws"
21+
#version = "~> 3.21" # Optional but recommended in production
22+
}
23+
}
24+
}
25+
26+
# Provider Block
27+
provider "aws" {
28+
profile = "default" # AWS Credentials Profile configured on your local desktop terminal $HOME/.aws/credentials
29+
region = "us-east-1"
30+
}
31+
32+
# Resource Block
33+
resource "aws_instance" "ec2demo" {
34+
ami = "ami-04d29b6f966df1537" # Amazon Linux in us-east-1, update as per your region
35+
instance_type = "t2.micro"
36+
}
37+
```
38+
39+
## Step-03: Terraform Core Commands
40+
```t
41+
# Initialize Terraform
42+
terraform init
43+
44+
# Terraform Validate
45+
terraform validate
46+
47+
# Terraform Plan to Verify what it is going to create / update / destroy
48+
terraform plan
49+
50+
# Terraform Apply to Create EC2 Instance
51+
terraform apply
52+
```
53+
54+
## Step-04: Verify the EC2 Instance in AWS Management Console
55+
- Go to AWS Management Console -> Services -> EC2
56+
- Verify newly created EC2 instance
57+
58+
59+
60+
## Step-05: Destroy Infrastructure
61+
```t
62+
# Destroy EC2 Instance
63+
terraform destroy
64+
65+
# Delete Terraform files
66+
rm -rf .terraform*
67+
rm -rf terraform.tfstate*
68+
```
69+
70+
## Step-08: Conclusion
71+
- Re-iterate what we have learned in this section
72+
- Learned about Important Terraform Commands
73+
- terraform init
74+
- terraform validate
75+
- terraform plan
76+
- terraform apply
77+
- terraform destroy
78+
79+
80+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Terraform Settings Block
2+
terraform {
3+
required_providers {
4+
aws = {
5+
source = "hashicorp/aws"
6+
#version = "~> 3.21" # Optional but recommended in production
7+
}
8+
}
9+
}
10+
11+
# Provider Block
12+
provider "aws" {
13+
profile = "default" # AWS Credentials Profile configured on your local desktop terminal $HOME/.aws/credentials
14+
region = "us-east-1"
15+
}
16+
17+
# Resource Block
18+
resource "aws_instance" "ec2demo" {
19+
ami = "ami-0533f2ba8a1995cf9" # Amazon Linux in us-east-1, update as per your region
20+
instance_type = "t2.micro"
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Terraform Configuration Language Syntax
2+
3+
## Step-01: Introduction
4+
- Understand Terraform Language Basics
5+
- Understand Blocks
6+
- Understand Arguments, Attributes & Meta-Arguments
7+
- Understand Identifiers
8+
- Understand Comments
9+
10+
11+
12+
## Step-02: Terraform Configuration Language Syntax
13+
- Understand Blocks
14+
- Understand Arguments
15+
- Understand Identifiers
16+
- Understand Comments
17+
- [Terraform Configuration](https://www.terraform.io/docs/configuration/index.html)
18+
- [Terraform Configuration Syntax](https://www.terraform.io/docs/configuration/syntax.html)
19+
```t
20+
# Template
21+
<BLOCK TYPE> "<BLOCK LABEL>" "<BLOCK LABEL>" {
22+
# Block body
23+
<IDENTIFIER> = <EXPRESSION> # Argument
24+
}
25+
26+
# AWS Example
27+
resource "aws_instance" "ec2demo" { # BLOCK
28+
ami = "ami-04d29b6f966df1537" # Argument
29+
instance_type = var.instance_type # Argument with value as expression (Variable value replaced from varibales.tf
30+
}
31+
```
32+
33+
## Step-03: Understand about Arguments, Attributes and Meta-Arguments.
34+
- Arguments can be `required` or `optional`
35+
- Attribues format looks like `resource_type.resource_name.attribute_name`
36+
- Meta-Arguments change a resource type's behavior (Example: count, for_each)
37+
- [Additional Reference](https://learn.hashicorp.com/tutorials/terraform/resource?in=terraform/configuration-language)
38+
- [Resource: AWS Instance](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance)
39+
- [Resource: AWS Instance Argument Reference](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#argument-reference)
40+
- [Resource: AWS Instance Attribute Reference](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#attributes-reference)
41+
- [Resource: Meta-Arguments](https://www.terraform.io/docs/language/meta-arguments/depends_on.html)
42+
43+
## Step-04: Understand about Terraform Top-Level Blocks
44+
- Discuss about Terraform Top-Level blocks
45+
- Terraform Settings Block
46+
- Provider Block
47+
- Resource Block
48+
- Input Variables Block
49+
- Output Values Block
50+
- Local Values Block
51+
- Data Sources Block
52+
- Modules Block
53+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#####################################################################
2+
# Block-1: Terraform Settings Block
3+
terraform {
4+
required_version = "~> 0.14"
5+
required_providers {
6+
aws = {
7+
source = "hashicorp/aws"
8+
version = "~> 3.0"
9+
}
10+
}
11+
# Adding Backend as S3 for Remote State Storage with State Locking
12+
backend "s3" {
13+
bucket = "terraform-stacksimplify"
14+
key = "dev2/terraform.tfstate"
15+
region = "us-east-1"
16+
17+
# For State Locking
18+
dynamodb_table = "terraform-dev-state-table"
19+
}
20+
}
21+
#####################################################################
22+
# Block-2: Provider Block
23+
provider "aws" {
24+
profile = "default" # AWS Credentials Profile configured on your local desktop terminal $HOME/.aws/credentials
25+
region = "us-east-1"
26+
}
27+
#####################################################################
28+
# Block-3: Resource Block
29+
resource "aws_instance" "ec2demo" {
30+
ami = "ami-04d29b6f966df1537" # Amazon Linux
31+
instance_type = var.instance_type
32+
}
33+
#####################################################################
34+
# Block-4: Input Variables Block
35+
variable "instance_type" {
36+
default = "t2.micro"
37+
description = "EC2 Instance Type"
38+
type = string
39+
}
40+
#####################################################################
41+
# Block-5: Output Values Block
42+
output "ec2_instance_publicip" {
43+
description = "EC2 Instance Public IP"
44+
value = aws_instance.my-ec2-vm.public_ip
45+
}
46+
#####################################################################
47+
# Block-6: Local Values Block
48+
# Create S3 Bucket - with Input Variables & Local Values
49+
locals {
50+
bucket-name-prefix = "${var.app_name}-${var.environment_name}"
51+
}
52+
#####################################################################
53+
# Block-7: Data sources Block
54+
# Get latest AMI ID for Amazon Linux2 OS
55+
data "aws_ami" "amzlinux" {
56+
most_recent = true
57+
owners = ["amazon"]
58+
59+
filter {
60+
name = "name"
61+
values = ["amzn2-ami-hvm-*"]
62+
}
63+
64+
filter {
65+
name = "root-device-type"
66+
values = ["ebs"]
67+
}
68+
69+
filter {
70+
name = "virtualization-type"
71+
values = ["hvm"]
72+
}
73+
74+
filter {
75+
name = "architecture"
76+
values = ["x86_64"]
77+
}
78+
79+
}
80+
#####################################################################
81+
# Block-8: Modules Block
82+
# AWS EC2 Instance Module
83+
84+
module "ec2_cluster" {
85+
source = "terraform-aws-modules/ec2-instance/aws"
86+
version = "~> 2.0"
87+
88+
name = "my-modules-demo"
89+
instance_count = 2
90+
91+
ami = data.aws_ami.amzlinux.id
92+
instance_type = "t2.micro"
93+
key_name = "terraform-key"
94+
monitoring = true
95+
vpc_security_group_ids = ["sg-08b25c5a5bf489ffa"] # Get Default VPC Security Group ID and replace
96+
subnet_id = "subnet-4ee95470" # Get one public subnet id from default vpc and replace
97+
user_data = file("apache-install.sh")
98+
99+
tags = {
100+
Terraform = "true"
101+
Environment = "dev"
102+
}
103+
}
104+
#####################################################################

0 commit comments

Comments
 (0)