Is there a way to get a list of all ns assigne to a rancher project using rancher2-provider data sources?
I found kubernetes_all_namespaces
to get all ns. As the project id is an annotation in the ns, one can grab that info. Below will create a map with all ns, which are assigned to a project
data "kubernetes_all_namespaces" "allns" {}
data "kubernetes_namespace" "ns" {
for_each = toset(data.kubernetes_all_namespaces.allns.namespaces)
metadata {
name = "${each.value}"
}
}
locals {
ns = {
for key,value in data.kubernetes_namespace.ns :
key=>{
projectid = lookup(value.metadata[0].annotations, "field.cattle.io/projectId", null)
if (lookup(value.metadata[0].annotations, "field.cattle.io/projectId", null)) != null
}