Kodekloud Terraform Challenge 2 solution | Implement LAMP stack using terraform and docker

Ticker

6/recent/ticker-posts

Kodekloud Terraform Challenge 2 solution | Implement LAMP stack using terraform and docker

Question : Welcome to the terraform challenge series.

In this challenge we will implement a simple LAMP stack using terraform and docker.
Utilize /root/code/terraform-challenges/challenge2 directory to store your Terraform configuration files.

Inspect the requirements in detail by clicking on the icons of the interactive architecture diagram on the right and complete the tasks. Once done click on the Check button to validate your work.


 1. Install terraform binary version=1.1.5 on iac-server

 2. Docker provider has already been configured using kreuzwerker/docker provider.

Check out the provider.tf given at /root/code/terraform-challenges/challenge2
 3. Create a terraform resource named php-httpd-image for building docker image with following specifications:
  • Image name: php-httpd:challenge

  • Build context: lamp_stack/php_httpd

  • Labels: challenge: second

4. Create a terraform resource named mariadb-image for building docker image with following specifications:

  • Image name: mariadb:challenge

  • Build context: lamp_stack/custom_db

  • Labels: challenge: second

5.  Define a terraform resource phpmyadmin for docker container with following configurations:

  • Container Name: db_dashboard

  • Image Used: phpmyadmin/phpmyadmin

  • Hostname: phpmyadmin

  • Attach the container to network my_network

  • Publish a container's port(s) to the host:
    Hostport: 0.0.0.0:8081
    containerPort: 80

  • Labels: challenge: second

  • Establish link based connectivity between db and db_dashboard containers (Deprecated)

  • Explicitly specify a dependency on mariadb terraform resource

6. Create a terraform resource named mariadb_volume creating a docker volume with name=mariadb-volume


Solution:  

1. Check Terraform version and download the ZIP file and extract it

iac-server $ which terraform

iac-server $ 

iac-server $  curl -L -o /tmp/terraform_1.1.5_linux_amd64.zip https://releases.hashicorp.com/terraform/1.1.5/terraform_1.1.5_linux_amd64.zip

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100 17.8M  100 17.8M    0     0  47.3M      0 --:--:-- --:--:-- --:--:-- 47.1M

iac-server $ 

iac-server $  ls /tmp

systemd-private-5071cf89ade64486af492fb231f3fc6b-systemd-resolved.service-6WiyzM  terraform_1.1.5_linux_amd64.zip

iac-server $ 

iac-server $  unzip -d /usr/local/bin /tmp/terraform_1.1.5_linux_amd64.zip

Archive:  /tmp/terraform_1.1.5_linux_amd64.zip

  inflating: /usr/local/bin/terraform  

iac-server $ 

iac-server $ which terraform

/usr/local/bin/terraform

iac-server $ 

iac-server $ terraform --version

Terraform v1.1.5

on linux_amd64

Your version of Terraform is out of date! The latest version

is 1.6.6. You can update by downloading from https://www.terraform.io/downloads.html

iac-server $ 


2. Docker provider has already been configured using kreuzwerker/docker provider.
Check out the provider.tf 

iac-server $ ls   /root/code/terraform-challenges/challenge2/

lamp_stack  provider.tf

iac-server $ 

iac-server $ cat /root/code/terraform-challenges/challenge2/provider.tf 

terraform {

  required_providers {

    docker = {

      source = "kreuzwerker/docker"

      version = "2.16.0"

    }

  }

}


provider "docker" {}

iac-server $ 


3. Create terraform resources 

php-httpd-image , mariadbimage phpmyadmin  for docker container 

Created  TF files with all the parameters, Kindly clone repo or you can copy from GitLab 

git clone https://gitlab.com/nb-tech-support/devops.git

 Refer Below Video for more clarity )

iac-server $ docker ps

CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                    NAMES

6eebadf066e4        phpmyadmin/phpmyadmin   "/docker-entrypoint.…"   23 seconds ago      Up 12 seconds       0.0.0.0:8081->80/tcp     db_dashboard

61a952f908f8        php-httpd:challenge     "docker-php-entrypoi…"   23 seconds ago      Up 8 seconds        0.0.0.0:80->80/tcp       webserver

b9128280a207        mariadb:challenge       "docker-entrypoint.s…"   2 minutes ago       Up 2 minutes        0.0.0.0:3306->3306/tcp   db

iac-server $ 



Happy Learning!!!!


Apart from this if you need more clarity,  I have made a  tutorial video on this , please go through and share your comments. Like and share the knowledge





Post a Comment

0 Comments

Latest Posts

KodeKloud Kubernetes Security CKS  Lab Challenge 4 |  Audit-policy | Install & configure falco utility | Inspect the API server audit logs and identify the user