rancher / terraform-provider-rancher2

Terraform Rancher2 provider
https://www.terraform.io/docs/providers/rancher2/
Mozilla Public License 2.0
263 stars 226 forks source link

[BUG] Namespace creation or import fails with error: "Bad project id format" #1417

Open nemobis opened 1 month ago

nemobis commented 1 month ago

Rancher Server Setup

Information about the Cluster

User Information

Provider Information

Describe the bug

Namespace creation or import fails with

│ Error: [ERROR] Getting clusted ID from project ID: Bad project id format p-ab1c2
│ 
│   with rancher2_namespace.observe_namespace,
│   on main.tf line 56, in resource "rancher2_namespace" "observe_namespace":
│   56: resource "rancher2_namespace" "observe_namespace" {

To Reproduce

Attempt to create the namespace with

resource "rancher2_namespace" "foo_namespace" {
  name       = "foo"
  project_id = "p-ab1c2"
  labels = {
    "owner"                       = "bar"
    "kubernetes.io/metadata.name" = "foo"
  }
}

or create it manually and then attempt import with

terraform import rancher2_namespace.foo_namespace c-defgh:p-ab1c2.foo

Actual Result

Error. The rest of the plan works just fine and workloads appear in the namespace/project.

Expected Result

The namespace is created or imported into the state.

nemobis commented 1 month ago

https://github.com/rancher/terraform-provider-rancher2/pull/1416/files is for the typo in the error message. Why is the provider even trying to look up the cluster ID (something for which it may or may not have sufficient permissions) when I've already provided it?

nemobis commented 1 month ago

Documentation says

[project_id](https://registry.terraform.io/providers/rancher/rancher2/latest/docs/resources/namespace#project_id) - (Required) The project id where assign namespace. It's on the form project_id=<cluster_id>:<id>. Updating <id> part on same <cluster_id> namespace will be moved between projects (string)

Some copyediting of these sentences would be welcome. I'm not super sure what they're expected to mean.