resource "rancher2_project" "myproject" {
count = var.enable_namespace ? 1 : 0
name = "myproject"
...
}
resource "rancher2_namespace" "mynamespace" {
count = var.enable_namespace ? 1 : 0
name = "mynamespace"
project_id = rancher2_project.myproject.id
...
}
So both the project and the namespace depend on var.enable_namespace
, in theory this could work. But in reality if var.enable_namespace
is false terraform says that rancher2_project.myproject.id
is not defined.
I thought about dynamic blocks, but I guess they are just for inside a resource block. If not, I have no idea how to define it for resources.
So is there any way to do this?