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

Ensure that it is possible to import current Ably configuration into Terraform state #16

Open kavalerov opened 2 years ago

kavalerov commented 2 years ago

We should make sure that such way exists, it is easy and straightforward to do (to the extent Terraform allows it), and it is well documented.

┆Issue is synchronized with this Jira Task by Unito

sync-by-unito[bot] commented 2 years ago

➤ Ivan Kavalerov commented:

All resources we are creating support importing, so closing.

Israphel commented 1 year ago

➤ Ivan Kavalerov commented:

All resources we are creating support importing, so closing.

but what are the commands to import? I don't see it in the current docs

kavalerov commented 1 year ago

Hi @Israphel ! Apologies for a delay in getting back to you.

In order to import a resource, you need to add the resource to your terraform file, and then use import command as described in Terraform docs: https://www.terraform.io/cli/import

For example, if you want to import an Ably app, you need to add something like the following to your terraform file:

resource "ably_app" "app0" {
  name     = "ably-tf-provider-app-0000"
  status   = "enabled"
  tls_only = true
}

and then run terraform import ably_app.app0 ably-tf-provider-app-0000.

This will import the corresponding Ably app into your state file.

It is a great idea to add example of this to the docs - we will add example of importing a resource to the docs with the next release to Terraform Registry!

Israphel commented 1 year ago

So apps are imported via name, understood. Thanks!

Israphel commented 1 year ago

doesn't work. I think you import by ID and not by name

terraform import 'module.ably-app["stage-us"].ably_app.app' 'stage-us'

terraform plan

Terraform v1.0.11
on linux_amd64
module.ably-app["stage-us"].ably_app.app: Modifying... [id=stage-us]
╷
│ Error: Error updating Resource
│ 
│   with module.ably-app["stage-us"].ably_app.app,
│   on .terraform/modules/ably-app/main.tf line 2, in resource "ably_app" "app":
│    2: resource "ably_app" "app" {
│ 
│ Could not update resource, unexpected error: /apps/stage-us: Could not find
│ app with id 'stage-us': code 40400: status code: 404 see:
│ https://help.ably.io/error/40400

Tried again with:

terraform import 'module.ably-app["stage-us"].ably_app.app' '5Y9M9Q'

and it worked.

kavalerov commented 1 year ago

@Israphel apologies for a late response, and thanks for highlighting this. This is actually interesting, I am now kind of surprised that my code worked for me because you are correct. Let me investigate this further - and then update the docs accordingly.

sync-by-unito[bot] commented 1 year ago

➤ Automation for Jira commented:

The link to the corresponding Jira issue is https://ably.atlassian.net/browse/SDK-3017