Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rancher2_namespace_project_assignment resource #891

Open
giskou opened this issue Mar 18, 2022 · 3 comments
Open

Add rancher2_namespace_project_assignment resource #891

giskou opened this issue Mar 18, 2022 · 3 comments

Comments

@giskou
Copy link

giskou commented Mar 18, 2022

It would be very helpful to add a rancher2_namespace_project_assignment resource to move a namespace into a project.

For imported clusters that already have namespaces, you can't create rancher2_namespace on top of the existing ones.

@kspradheep
Copy link

+1

@gkdante
Copy link

gkdante commented Sep 12, 2022

+1

Anybody found any workaround for this? I got four K8s clusters to import with LOTS of namespaces in them.

@kspradheep
Copy link

kspradheep commented Sep 13, 2022

I have used rancher cli in null_resource provisioner
`
output "cluster_id" {
value = rancher2_cluster.imported.id
}
resource "rancher2_project" "project_namespace" {
name = var.namespace
cluster_id = var.cluster_id
}

resource "null_resource" "project_namespace_assignment" {
triggers = {
policy_sha1 = "${sha1(file("${path.module}/scripts/k8s-rancher-namespace.sh"))}"
rancher_cli2json = var.rancher_cli2json
namespace = var.namespace
project_id = rancher2_project.project_namespace.id
}
provisioner "local-exec" {
command = "bash ${path.module}/scripts/k8s-rancher-namespace.sh"

environment = {
  rancher_cli2json = var.rancher_cli2json
  namespace        = var.namespace
  project_id       = rancher2_project.project_namespace.id
}

}
depends_on = [
rancher2_project.project_namespace
]
}
rancher_cli2json = base64encode(jsonencode({
Servers = {
rancherDefault = {
accessKey = local.platform_tools_secret.rancher_access_key
secretKey = local.platform_tools_secret.rancher_secret_key
tokenKey = "${local.platform_tools_secret.rancher_access_key}:${local.platform_tools_secret.rancher_secret_key}"
url = local.rancher_url
project = rancher2_cluster.imported.default_project_id
}
}
CurrentServer = "rancherDefault"
}))`

#scripts/k8s-rancher-namespace.sh
`#/bin/bash!
set -e
set -u
set -o pipefail

set -x

DIR=/tmp/$project_id
mkdir -p $DIR
FILE=$DIR/cli2.json

echo $rancher_cli2json | base64 --decode > $FILE

rancher --config $DIR namespace move $namespace $project_id

rm -rf $DIR`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants