ably / terraform-provider-ably

Ably's Terraform Provider, enabling you to manage your Ably account programmatically.
https://registry.terraform.io/providers/ably/ably
Apache License 2.0
11 stars 2 forks source link

Following instructions for importing configuration doesn't work #181

Closed kavalerov closed 1 day ago

kavalerov commented 2 months ago

I have prepared the following main.tf:

terraform {

  required_providers {
    ably = {
      source = "ably/ably"
    }
  }
}

provider "ably" {
  token = "control api token"
}

resource "ably_app" "app0" {
  name   = "prod"
  status = "enabled"
}

And then I do the following when try to import configuration (basically copied from the guide on Terraform website:

image

❯ terraform import ably_app.app0 prod
ably_app.app0: Importing from ID "prod"...
ably_app.app0: Import prepared!
  Prepared ably_app for import
ably_app.app0: Refreshing state... [id=prod]
╷
│ Error: Cannot import non-existent remote object
│
│ While attempting to import an existing object to "ably_app.app0", the provider detected that no object exists with the given id. Only pre-existing objects can be imported; check that the id is correct and that it is associated with the provider's
│ configured region or endpoint, or use "terraform apply" to create a new remote object for this resource.

It looks like it tries to use name that I provided as appid, which is not correct.

kavalerov commented 2 days ago

@graham-russell I was wondering if you had any time to look at this by any chance?

graham-russell commented 1 day ago

Hey @kavalerov - I just had a look. You need to import the app using it's app id rather than name.

I got the account id from the Ably dashboard - https://ably.com/accounts/12345/apps/12345/edit. There are other ways to do that as well.

Running import ably_app.app0 {APP_ID} worked for me.

I'm currently using OpenTofu but Terraform will work the same way:

> tofu import ably_app.app0 XXXXXX                                                                                                                                                                               09:34:49
ably_app.app0: Importing from ID "XXXXXX"...
ably_app.app0: Import prepared!
  Prepared ably_app for import
ably_app.app0: Refreshing state... [id=XXXXXX]

Import successful!

The resources that were imported are shown above. These resources are now in
your OpenTofu state and will henceforth be managed by OpenTofu.
kavalerov commented 1 day ago

Yes, this makes sense actually - I think we just need to update the instructions on the docs page - right now it is a bit misleading

kavalerov commented 1 day ago

Added PR to address this: https://github.com/ably/terraform-provider-ably/pull/186 , closing this issue for now.