Terraform - How to create an API object in kubernetes using a manifest

Using Terraform you can easily create a Kubernetes API object using a manifest. The resource you are looking for is the kubernetes_manifest. Using this resource you can create objects like deployments, ingress, configmaps, namespaces and many more. Below is a simple example of how to create a namespace for argocd:

provider "kubernetes" {
  config_path    = "${path.module}/.kube/config"
  config_context = "<config_context>"
}

resource "kubernetes_manifest" "argocd" {
  manifest = {
    "apiVersion" = "v1"
    "kind"       = "Namespace"
    "metadata" = {
      "name"      = "argocd"
    }
  }
}

The format of the manifest (HCL) follows the yaml, for example the above would be written as the following in YAML:

apiVersion: v1
kind: Namespace
metadata:
  name: argocd

You can convert a YAML into HCL format using the yamldecode function.

I hope you found this helpful, let me know what you think down in the comments below!