Deploying Terraform-tailored app via GitLab Kubernetes Agent

Hello, I am newbie of GitLab and I tried creating application running on GKE Autopilot Cluster. I noticed the GitLab’s feature to connect to Kubernetes via Agent and obtain kubeconfig. So I created a group, in the group I created a repository for setting up GitLab Kubernetes Agent, where also registered Front-End App project for CI/CD Tunnel. OK, as far as good, everything just worked. In Front-End App Repo’s Pipelines I had KUBECONFIG env variable which pointed to existing file. Nice.

But troubles came. I just have echo’ed, copied and pasted the kube config file path into kubernetes provider in Front-End App Terraform files. For test I wanted to create empty namespace. It resulted in error below:

My .gitlab-ci.yaml file:

include:
  - template: Terraform/Base.gitlab-ci.yml

variables:
  TF_STATE_NAME: default
  TF_CACHE_KEY: default
  TF_ROOT: terraform

stages:
  - init
  - validate
  - build
  - deploy

init:
  extends: .init

validate:
  extends: .validate

build:
  extends: .build

deploy:
  extends: .deploy
  dependencies:
    - build

My main.tf file:

terraform {
  backend "http" {}

  required_providers {
    kubernetes = {
      source = "hashicorp/kubernetes"
      version = "2.7.1"
    }
  }
}

provider "kubernetes" {
  config_path = "/builds/ozone-school/momentum/front-end/user-app.tmp/KUBECONFIG"
}

resource "kubernetes_namespace" "example" {
  metadata {
    name = "example"
  }
}

Anyone knows what am I doing wrong?

1 Like