stackitcloud / terraform-provider-stackit

The official Terraform provider for STACKIT
https://registry.terraform.io/providers/stackitcloud/stackit
Apache License 2.0
35 stars 13 forks source link

Migration from community provider SchwarzIT/stackit towards stackitcloud/stackit #286

Closed JanGrosse closed 6 months ago

JanGrosse commented 6 months ago

Hi,

we are using the community provider for now. But now we want to follow the deprecation message and switch to the official provider. I saw the Migration guide with the import mechanic but would rather go another way and wanted to clarify if this will work.

You mentioned that the ID (and some resource names) have changed. I updated the resource names accordingly and when I now run terraform plan it wants to create all ressources (naturally). Now if I would add the (usually optional read-only field) ID to every resource, would this work ? I saw that the ID has changed to ",".

Thank you very much in advance :-) Greetings, JanGrosse

vicentepinto98 commented 6 months ago

Hello @JanGrosse, It is not possible to add the ID field to the resources because it is a read-only field.

However you can manually import all of your existing resources into the new ones by using terraform import. See the documentation.

You just need to make sure all of the resource and field names are correct for our provider (for which you can always check each resource documentation). You probably also need to create a new configuration for the new provider, if you remove the old one terraform might try to delete the resources, unless you remove them from your state

Example:

If you need further support let me know :)

JanGrosse commented 6 months ago

Hi @vicentepinto98, thank you for the fast response. Okay, I will try to use the import functionality. You are totally right it makes no sense to try to set a read-only field.

It worked for the SKE Cluster initially

❯ terraform import stackit_ske_cluster.management-stm01-cluster 2b636579-1468-4c5d-b51a-c66ff29faa1c,mgmt-stm01
stackit_ske_cluster.management-stm01-cluster: Importing from ID "2b636579-1468-4c5d-b51a-c66ff29faa1c,mgmt-stm01"...
stackit_ske_cluster.management-stm01-cluster: Import prepared!
  Prepared stackit_ske_cluster for import
stackit_ske_cluster.management-stm01-cluster: Refreshing state...

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

But when I tried to check the terraform state it failed

❯ terraform state list
Failed to load state: Unable to access object "terraform-state-workspaces-stm01" in S3 bucket "terraform-state-bucket-stm01": operation error S3: GetObject, https response error StatusCode: 403, RequestID: 1709721138825151, HostID: 12385447, api error AccessDenied: V4 authentication signed header not found: range

And now all requests keep failing with the same error as above.

❯ terraform import stackit_objectstorage_bucket.terraform-state-bucket-stm01 2b636579-1468-4c5d-b51a-c66ff29faa1c,terraform-state-bucket-stm01
╷
│ Error: error loading state: Unable to access object "terraform-state-workspaces-stm01" in S3 bucket "terraform-state-bucket-stm01": operation error S3: GetObject, https response error StatusCode: 403, RequestID: 1709722722367643, HostID: 12679388, api error AccessDenied: V4 authentication signed header not found: range

I don't think this is related to the provider but maybe you have seens this error before and know how to get it to work again.

vicentepinto98 commented 6 months ago

It looks like some error authenticating to the S3 bucket that you are using for the backend, but I'm not sure what is the exact issue. Double check your backend configuration (tf files and object storage buckets).