I have a .env that is used to create k8s secrets as a file. Before creating the secret, I have to set the values in it as per the environment for the respective keys. I am trying to use Terraform's Kubernetes provider for secret creation. Outside of Terraform, we have ways like scripting to set the.env file, and then pass it for the secret creation. However, is there a way of setting up a .env file using terraform?
Terraform secret construct
data "kubernetes_secret" "test-env" {
metadata {
name = "app-env"
}
data = {
"app.env" = filebase64("./tomcat/app.env")
}
}
resource "kubernetes_secret" "test-env" {
metadata {
name = "app-env"
namespace = "test-deployment"
}
type = "Opaque"
data = "{data.kubernetes_secret.test-env.template}"
}
app.env (*_value to be replaced before the secret creation)
JAVA_OPTS ="java_opts_value"
NGINX_VERSION="nginx_version_value"
TOMCAT_VERSION="tomcat_version_value"
POSTGRES_VERSION="postgres_version_value"
I am new to Terraform and any guidance would be appreciated.
You can use local-exec to perform any custom processing of files in your TF script.