KodeKloud - Terraform - PT1

The Level 1 Terraform Modules from KodeKloud's engineering practice platform serves as a foundational learning resource which is based around the fictious Nautilus DevOps team as they undertake a strategic migration to AWS cloud infrastructure.

KodeKloud's practice environment is built to allow a learner to gain confidence and competency with Infrastructure as Code principles, AWS resource provisioning, and Terraform configuration best practices. These introductory Terraform exercises reinforce the principle of breaking down complex infrastructure deployments into smaller, manageable units that can be systematically implemented and validated.

Each exercise in the Level 1 module represents a deliberate step in my learning progression, allowing me to gain confidence and expertise before tackling more sophisticated multi-layer architectures and advanced deployment scenarios. By mastering these foundational concepts and skills, I'm hoping I will be able to apply them to AWS DevOps positions.

There are 40 modules in total, with what looks like a good overlap of skills. I will be featuring them in an eight part series, with five tasks presented in each.


Overall Scenario Objective:

The Nautilus DevOps team is strategizing the migration of a portion of their infrastructure to the AWS cloud. Recognizing the scale of this undertaking, they have opted to approach the migration in incremental steps rather than as a single massive transition. To achieve this, they have segmented large tasks into smaller, more manageable units. This granular approach enables the team to execute the migration in gradual phases, ensuring smoother implementation and minimising disruption to ongoing operations. By breaking down the migration into smaller tasks, the Nautilus DevOps team can systematically progress through each stage, allowing for better control, risk mitigation, and optimization of resources throughout the migration process.

Note - These are all standalone exercises with the provider.tf file pre-populated (this contains the AWS region to be used). In each instance, a new main.tf is created, the contents are stand-alone, ie, they do not carry over from one task to the next.

Task 1 - Create a Key Pair using Terraform

For this task, create a key pair using Terraform with the following requirements:

Name of the key pair should be devops-kp.
Key pair type must be rsa.
The private key file should be saved under /home/bob/devops-kp.pem.
The Terraform working directory is /home/bob/terraform.

resource "tls_private_key" "datacenter-kp"{
    algorithm = "RSA"
    rsa_bits = 4096
}

resource "aws_key_pair" "datacenter-kp"{
    key_name = "datacenter-kp"
    public_key = tls_private_key.datacenter-kp.public_key_openssh
}

resource "local_file" "datacenter-kp_private_key"{
    content = tls_private_key.datacenter-kp.private_key_pem
    filename -"/home/bob/datacenter-kp.pem"
}

Task 2 - Create a Security Group Using Terraform

Use Terraform to create a security group under the default VPC with the following requirements:

  1. The name of the security group must be devops-sg.
  2. The description must be Security group for Nautilus App Servers.
  3. Add an inbound rule of type HTTP, with a port range of 80, and source CIDR range 0.0.0.0/0.
  4. Add another inbound rule of type SSH, with a port range of 22, and source CIDR range 0.0.0.0/0.

Ensure that the security group is created in the us-east-1 region using Terraform. The Terraform working directory is /home/bob/terraform.

resource "aws_security_group" "devops-sg" {
  name        = "devops-sg"
  description = "Security group for Nautilus App Servers"

  ingress {
    description = "HTTP"
    from_port   = 80
    to_port     = 80
    protocol     = "HTTP"
    cidr_blocks = ["0.0.0.0/0"]
  }

  ingress {
    description = "SSH"
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

Task 3 - Create VPC Using Terraform

Create a VPC named xfusion-vpc in region us-east-1 with any IPv4 CIDR block through terraform. The Terraform working directory is /home/bob/terraform.

resource "aws_vpc" "xfusion" {
  cidr_block           = "10.0.0.0/16"
  enable_dns_hostnames = true
  enable_dns_support   = true

  tags = {
    Name = "xfusion-vpc"
  }
}

Task 4 - Create VPC with CIDR Using Terraform

This task is essentially the same as Task 3:

The Nautilus DevOps team is strategically planning the migration of a portion of their infrastructure to the AWS cloud. Acknowledging the magnitude of this endeavor, they have chosen to tackle the migration incrementally rather than as a single, massive transition. Their approach involves creating Virtual Private Clouds (VPCs) as the initial step, as they will be provisioning various services under different VPCs.

Create a VPC named xfusion-vpc in us-east-1 region with 192.168.0.0/24 IPv4 CIDR using terraform.

resource "aws_vpc" "xfusion-vpc" {
  cidr_block           = "192.168.0.0/24"
  enable_dns_hostnames = true
  enable_dns_support   = true

  tags = {
    Name = "xfusion-vpc"
  }
}

Task 5 - Create a VPC with IPv6 Using Terraform

As above except using IPV6. For this task, create a VPC named nautilus-vpc in the us-east-1 region with the Amazon-provided IPv6 CIDR block using terraform.

resource "aws_vpc" "nautilus" {
  cidr_block                       = "10.0.0.0/16"
  assign_generated_ipv6_cidr_block = true
  enable_dns_hostnames             = true
  enable_dns_support               = true

  tags = {
    Name = "nautilus-vpc"
  }
}