labd / terraform-provider-commercetools

Terraform provider for commercetools
https://registry.terraform.io/providers/labd/commercetools/latest/docs
Mozilla Public License 2.0
64 stars 68 forks source link

How to import resources to terraform state #483

Closed muhammedneswine closed 3 months ago

muhammedneswine commented 4 months ago

I have been trying to import resources to my terraform state which is already created in CT. I found this document on how to import existing resources to state. https://registry.terraform.io/providers/labd/commercetools/latest/docs/guides/state-import But this doesn't seem to work for me.

For example,

I have a resource created in CT called sample_product_type. I can see the product type via API.

resource "commercetools_product_type" "sample_product_type"{ ... }

And based on the documentation I mentioned above, I tried to import the state like below. terraform import commercetools_tax_category.standard [id from API]

Is this the way to import the state? Because this is missing from the documentation in TF.

Right now I am getting Cannot import non-existent remote object error.

demeyerthom commented 4 months ago

Hi @muhammedneswine Just to be sure, the command you were trying to execute should look something like this:

terraform import commercetools_product_type.sample_product_type 55063af1-5bf3-41b4-a30c-dbd02da9f667 and you are running it in the directory with your terraform code?

If that is the case it might be a permissions issue, as this error is generally shown if terraform tries to import a resource with the given ID but cannot find it, or reach it.

Setting TF_LOG=debug might also help you find more information: https://developer.hashicorp.com/terraform/internals/debugging

muhammedneswine commented 3 months ago

Hi @demeyerthom Thanks for the help. I think it was issue the API client we used. I created a client with full permission and it worked perfectly. Thanks for the support 👍