Mongey / terraform-provider-confluentcloud

A Terraform provider for managing resource in confluent.cloud
MIT License
110 stars 47 forks source link

Error: get cluster - Terraform Import #64

Closed prabhakarank87 closed 3 years ago

prabhakarank87 commented 3 years ago

@Mongey When import the existing cluster using terraform import, getting the below error

Command for Import $terraform import confluentcloud_kafka_cluster.test lkc-x2yvk

Output:- confluentcloud_kafka_cluster.test: Importing from ID "lkc-x2yvk"... confluentcloud_kafka_cluster.test: Import prepared! Prepared confluentcloud_kafka_cluster for import confluentcloud_kafka_cluster.test: Refreshing state... [id=lkc-x2yvk]

Error: get cluster: Oops, something went wrong

rojopolis commented 3 years ago

I just hit this as well. Debug / Trace logs don't seem to shed any light.

benweint commented 3 years ago

We hit this as well when trying to import an existing cluster. I think this is happening because the cluster resource type is usingImportStatePassthroughContext here, but the Read function here needs both the cluster ID and the environment ID in order to load the cluster.

According to this doc from Hashicorp:

This function requires the Read function to be able to refresh the entire resource with d.Id() ONLY.

So I think in order to support importing existing clusters, this resource type would need to do the thing described here:

More likely though, if the resource requires multiple attributes and they are not already in the resource ID, Importer State will require a custom function implementation beyond using schema.ImportStatePassthrough, seen below. The ID passed into terraform import should be parsed so d.Set() can be called the required attributes to make the Read function properly operate. The resource ID should also match the ID set during the resource Create function via d.SetId().

benweint commented 3 years ago

I opened a PR that should address this here: https://github.com/Mongey/terraform-provider-confluentcloud/pull/74