I can show you 2 methods in order to create kubernetes components using terraform
1st method:
you can use this provider
kubectl terraform provider
You need add this block to your providers.tf file
terraform {
required_providers {
kubectl = {
source = "gavinbunney/kubectl"
version = "1.16.0"
}
}
}
// you need to configure the kubectl provider section in order to enable terraform to authenticate to your cluster
provider "kubectl" {
host =
cluster_ca_certificate =
token =
}
After configuring the provider you just need to create a file named for example secret.yml
For example we going to fill it with:
apiVersion: v1
kind: Secret
metadata:
name: secret-sa
namespace: test
type: kubernetes.io/service-account-token
data:
extra: YmFyCg==
In order to deploy to secret.yml file you just need to add file name secret.tf that contain
resource "kubectl_manifest" "dapr_secret" {
yaml_body = file("./secret.yml")
}
Finaly run:
terraform apply
2nd method:
you can use this provider
kubernetes terraform provider
You need to add this block to your providers.tf file
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.34.0"
}
}
}
// you need to configure the kubernetes provider section in order to enable terraform to authenticate to your cluster
provider "kubernetes" {
host =
cluster_ca_certificate =
token =
}
Create a file named secret.tf and copy this config
In case your wondering where did I found this config
resource "kubernetes_secret" "example" {
metadata {
name = "secret-sa"
namespace ="test"
}
data = {
"extra" = "base64secret"
}
type = "kubernetes.io/service-account-token"
}
In case your wondering where did I found this config
Kubernetes secret terraform