Terraform Challenge 1

Hi all,

I am having trouble finishing the first Terraform Challenge. Currently, I have finished 3 out of 4 tasks. Only the ‘kubernetes provider’ task is giving me somehow an incomplete status.

I have the following in provider.tf:

provider "kubernetes" {
  config_path = "/root/.kube/config"
}

terraform {
  required_providers {
    kubernetes = {
      version = "2.11.0"
    }
  }
}

What am I missing here.

Hi @jimmysmits ,
You are missing the source location.

Regards,
KodeKloud Support

Thanks! This resolved the issue :slight_smile:

Hi Jimmy, I am very beginner in terraform and try to solve challenge. Actually I got the provider.tf file syntax from your post but not able to complete onward tasks in challenge one. Can you help me out?

Hi
On terrafom challege 1
for frontend deployment,

I created main.tf (then renamed to frontend.tf) and also added resource code inside provider.tf
, but nothing seems to be recognising, what is the solution here.

code :

resource “kubernetes_deployment” “frontend” {
metadata {
name = “frontend”
labels = {
name = “frontend”
}
}

spec {
replicas = 4

selector {
  match_labels = {
    name = "webapp"
  }
}

template {
  metadata {
    labels = {
      name = "webapp"
    }
  }

  spec {
    container {
      image = "kodekloud/webapp-color:v1"
      name  = "simple-webapp"
      port: 8080

[email protected] ~/terraform_challenge via :diamond_shape_with_a_dot_inside: default ➜

1 Like

I have the issue with frontend. I have green 3 others squares but frontend square is red and none of the requirements are green. Below my frontend.tf file content:

resource "kubernetes_deployment" "frontend" {
  metadata {
    name = "frontend"
    labels = {
      name = "frontend"
    }
  }

  spec {
    replicas = 4

    selector {
      match_labels = {
        name = "webapp"
      }
    }

    template {
      metadata {
        labels = {
          name = "webapp"
        }
      }

      spec {
        container {
          image = "kodekloud/webapp-color:1"
          name  = "simple-webapp"
          port {
            container_port = 8080
          }
        }
      }
    }
  }
}

image

I checked with “kubectl get all” and later with pod logs. The issue was typo in images. There should be v1.

About @grasajjan issue. You need to correct container port syntax. Check my code above.

I have same kind of issue with service and deployment tf code any help here?

webapp-service.tf

resource "kubernetes_service" "webapp-service" {
  metadata {
    name = "webapp-service"
  }
  spec {
    selector = {
      name = frontend
      #name = webapp
    }
    port {
      port        = 8080
      target_port = 8080
      node_port = 30080
    }

    type = "NodePort"
  }
}

deployment.tf

resource "kubernetes_deployment" "frontend" {
  metadata {
    name = "frontend"
    labels = {
      name = "frontend"
    }
  }

  spec {
    replicas = 4

    selector {
      match_labels = {
        name = "webapp"
      }
    }

    template {
      metadata {
        labels = {
          name = "webapp"
        }
      }
    }
    spec {
        container {
          image = "kodekloud/webapp-color:v1"
          name  = "simple-webapp"
          port {
            container_port = 8080
          }
     }
    }

how to verify terraform version installed on controlplane ?

Hello,
Just run the command ( terraform --version ) to check the version of terraform.

Hello,
Can you please explain you issue to be able to support you?

image

please guide me through the installation process for terraform. it seams that there is no terraform installed in the environment.

resource "kubernetes_deployment" "frontend" {
  metadata {
    name = "frontend"
    labels = {
      name = "frontend"
    }
  }

  spec {
    replicas = 4
    selector {
      match_labels = {
        name = "webapp"
      }
    }
    template {
      metadata {
        labels = {
          name = "webapp"
        }
      }
      spec {
        container {
          image = "kodekloud/webapp-color:v1"
          name  = "simple-webapp"
          port {
            container_port = 8080
          }
        }
      }
    }
  }
}

this is the deployment code that i’ve been using to create deployment but i was not able to complete it.
@Ayman

Hi @gopicn45,
First, you need to install the given terraform version on the controlplane.

You can find that version here - Terraform Versions | HashiCorp Releases

Regards,

1 Like

thank you able to complete the task. @Tej-Singh-Rana

Awesome, :innocent:

Hope you liked challenge!! :smiley:

1 Like

Hi,

I have some trouble with this challenge. I’m trying to apply al the code with the command terrafom apply, but I receive this message:

kubernetes_deployment.frontend: Creating…

│ Error: Failed to create deployment: Post “http://localhost/apis/apps/v1/namespaces/default/deployments”: dial tcp 127.0.0.1:80: connect: connection refused

│ with kubernetes_deployment.frontend,
│ on frontend.tf line 1, in resource “kubernetes_deployment” “frontend”:
│ 1: resource “kubernetes_deployment” “frontend” {


Any idea about what could be the issue?
Whay I could do to solved it?

Thanks in advances! :slight_smile:

Hi @Richardbmk

I’ve checked the lab. It’s working fine.

If you are stuck, the solution to this challenge is here: terraform-challenges/challenge-1 at master · kodekloudhub/terraform-challenges · GitHub

I have also got the same error I followed the github link provided by alistair