In order to have dependency between a kuberentes_namespace resource and another resource that uses this namespace, such as kubernetes_pod, kuberentes_namespace resource should expose a name output.
The diff below describes the difference between the current way of using a kubernetes namespace in terraform and the way I propose to use a kubernetes namespace:
resource "kubernetes_namespace" "default" {
metadata {
name = "my-namespace"
}
}
resource "kubernetes_pod" "my-pod" {
metadata {
name = "pod1"
- namespace = "my-namespace"
+ namespace = "${kubernetes_namespace.default.name}"
}
spec {
...
}
- depends_on = ["kubernetes_namespace.default"]
}
I'm sorry, I can get it with the "id" output of the namespace resource:
resource "kubernetes_namespace" "default" {
metadata {
name = "my-namespace"
}
}
resource "kubernetes_pod" "my-pod" {
metadata {
name = "pod1"
namespace = "${kubernetes_namespace.default.id}"
}
spec {
...
}
}
Most helpful comment
I'm sorry, I can get it with the "id" output of the namespace resource: