pulumi / pulumi-rancher2

A Rancher2 Pulumi resource package, providing multi-language access to Rancher2
Apache License 2.0
9 stars 4 forks source link

Error when attempting to import existing namespace #597

Closed trondhindenes closed 1 week ago

trondhindenes commented 1 week ago

Describe what happened

I'm trying to import an existing namespace, but I'm getting an error "Cluster Client: cluster ID is nil". That doesn't make sense to me, there's nowehre either in the resource or on the provider to set a cluster ID as far as I can see.

Sample program

var testNamespace = new Rancher2.Namespace($"testNamespace-{managedCluster}", new Rancher2.NamespaceArgs
                {
                    Name = "testnamespace",
                    ProjectId = myprojectId,
                },
                new CustomResourceOptions
                {
                    Provider = rancherProvider,
                    ImportId = $"testnamespace-{managedCluster}"
                }
            );

Log output

"diagnostics": [
        {
            "urn": "urn:pulumi:prod::infrastructure-rancher::rancher2:index/namespace:Namespace::testNamespace-mycluster",
            "message": "error: Preview failed: importing testNamespace-mycluster: [ERROR] Rancher Cluster Client: cluster ID is nil\n",
            "severity": "error"
        },
        {
            "message": "error: preview failed\n",
            "severity": "error"
        }
    ],

Affected Resource(s)

No response

Output of pulumi about

Plugins
KIND      NAME          VERSION
resource  azure-native  2.67.0
resource  azuread       6.0.1
resource  command       1.0.1
language  dotnet        unknown
resource  kubernetes    4.18.1
resource  rancher2      7.1.2
resource  random        4.16.7

Dependencies:
NAME             VERSION
Pulumi.Rancher2  7.1.2

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

iwahbe commented 1 week ago

Hi @trondhindenes. Thanks for reporting an issue.

I think you need to import as

var testNamespace = new Rancher2.Namespace($"testNamespace-{managedCluster}", new Rancher2.NamespaceArgs
                {
                    Name = "testnamespace",
                    ProjectId = myprojectId,
                },
                new CustomResourceOptions
                {
                    Provider = rancherProvider,
                    ImportId = $"{myprojectId}.testNamespace" // Maybe $"{myprojectId}.testNamespace-{managedCluster}" 
                }
            );

The format for import is <project_id>.<namespaces_id>.

trondhindenes commented 1 week ago

oh, thanks. Let me test that right away!

trondhindenes commented 1 week ago

hm this is trickier than I thought since ImportId expects a string and not an input, and myprojectId is an output.

trondhindenes commented 1 week ago

I ended up wrapping the entire resource in an Apply statement to resolve project ID, but that's outside the scope of this issue I guess. The import works perfectly fine now. I would argue that the error message is a bit misleading tho.

btw how would I know what the format of the import would be? If I remove the importId and run a preview, when looking at the produced json there's no indication that I'd need the project id. Just trying to figure out how I can "see" what to do.

iwahbe commented 1 week ago

I looked the import section here: https://www.pulumi.com/registry/packages/rancher2/api-docs/namespace/#import. I agree that the error message wasn't great.

trondhindenes commented 6 days ago

Thanks!