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

"Error creating Resource" for API key when following README example #164

Closed dbougan closed 1 year ago

dbougan commented 1 year ago

Hello. I just started using Ably and absolutely love the service. I am trying to integrate it into my Terraform project but I encountered an error which I recreated following the example in the README.

Terraform Ably Provider: 0.4.3 Terraform CLI: Terraform v1.2.8 on windows_386 (also tested with v1.4.2)

terraform {
  required_providers {
    ably = {
      source  = "ably/ably"
      version = "0.4.3"
    }
  }
}

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

# Add a key
resource "ably_api_key" "api_key_0" {
  app_id = ably_app.app0.id
  name   = "key-0000"
  capabilities = {
    "channel2"  = ["publish"],
    "channel3"  = ["subscribe"],
    "channel33" = ["subscribe"],
  }
}

# Configure a queue
resource "ably_queue" "example_queue" {
  app_id     = ably_app.app0.id
  name       = "queue_name"
  ttl        = 60
  max_length = 10000
  region     = "us-east-1-a"
}

When running terraform apply, the resources above are all created correctly in Ably, however the API Key resource is not saved to state due to the following error:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # module.pub_sub.ably_api_key.api_key_0 will be created
  + resource "ably_api_key" "api_key_0" {
      + app_id       = (known after apply)
      + capabilities = {
          + "channel2"  = [
              + "publish",
            ]
          + "channel3"  = [
              + "subscribe",
            ]
          + "channel33" = [
              + "subscribe",
            ]
        }
      + created      = (known after apply)
      + id           = (known after apply)
      + key          = (known after apply)
      + modified     = (known after apply)
      + name         = "key-0000"
      + status       = 0
    }

  # module.pub_sub.ably_app.app0 will be created
  + resource "ably_app" "app0" {
      + account_id                = (known after apply)
      + apns_use_sandbox_endpoint = false
      + id                        = (known after apply)
      + name                      = "ably-tf-provider-app-0000"
      + status                    = "enabled"
      + tls_only                  = true
    }

  # module.pub_sub.ably_queue.example_queue will be created
  + resource "ably_queue" "example_queue" {
      + amqp_queue_name            = (known after apply)
      + amqp_uri                   = (known after apply)
      + app_id                     = (known after apply)
      + deadletter                 = (known after apply)
      + deadletter_id              = (known after apply)
      + id                         = (known after apply)
      + max_length                 = 10000
module.pub_sub.ably_queue.example_queue: Creating...
module.pub_sub.ably_queue.example_queue: Creation complete after 1s [id=BXBd9g:us-east-1-a:queue_name]
╷
│ Error: Error creating Resource
│
│   with module.pub_sub.ably_api_key.api_key_0,
│   on modules\pub-sub\main.tf line 33, in resource "ably_api_key" "api_key_0":
│   33: resource "ably_api_key" "api_key_0" {
│
│ Could not create resource, unexpected error: json: cannot unmarshal number 1679582644401 into Go struct field Key.created of type int
╵

Even though the API Key is successfully created in Ably, the error means it is not saved to state and prevents me from injecting it as a variable into my other Terraform resources.

dbougan commented 1 year ago

Apologies, I am closing this issue. This problem is that I was using the windows_386 version of the Terraform executable. This limitation is correctly mentioned on the Supported Platforms section of the README, but I overlooked that detail.

I realized when browsing the ably-control-go repo that the Key.created property is type "int": https://github.com/ably/ably-control-go/blob/67578f1e1eaa44e80877d5c8c0f8746c8dc0708a/keys.go#L19

As you'd expect, since I was using the 386 executable, it appears that type "int" was an alias for "int32" and could not store the created timestamp.