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

Key resource returns API key itself only on the first apply, only empty string after #101

Closed kavalerov closed 2 years ago

kavalerov commented 2 years ago

From Rambatino and his comment:

I think if you create an api key resource with incorrect capabilities, then correct it, when you try and access the key it doesn't appear:

> ably_api_key.api_key
{
  "app_id" = "I0_Xlw"
  "capabilities" = tomap({
    "*" = tolist([
      "publish",
    ])
  })
  "created" = 1662626917401
  "id" = "M-RG2A"
  "key" = ""
  "modified" = 1662626917401
  "name" = "master-key"
  "status" = 0
}

I'm going out on a limb here and saying that it could be due to the missing Key here: https://github.com/ably/terraform-provider-ably/blob/main/internal/provider/resource_ably_key.go#L219

I haven't tested that theory out. Also the read() func doesn't assign the Key param either so not sure.

Eitherway, I ended up with a state of the resource whereby I wasn't able to access the key.

(on deleting and recreating it did fix the issue)

Actually, it does appear that only on the initial creation of the resource are you able to access the key. On re-applies, it returns an empty string: value = "I0_Xlw.isIMNw:CE...4dhYmRD3lXeIWXfhsF05Hsjk" -> null

┆Issue is synchronized with this Jira Task by Unito

kavalerov commented 2 years ago

@Rambatino thanks for raising this!

Just to confirm - when you are saying that you can't access key, does it also include exposing it as output?

kavalerov commented 2 years ago

Actually, I just checked it myself and see that the problem remains, you are right.

I have created the following output:

output "api_key" {
  value = ably_api_key.api_key_1.key
}

And it only returned the key on the first apply. It just returns empty string (consistent with @Rambatino findings).

kavalerov commented 2 years ago

@Rambatino this should work now - but please let us know if you will have any other problems or issues!

Rambatino commented 2 years ago

Thank you!

Rambatino commented 2 years ago

Hello, are you able to do a new release?

kavalerov commented 2 years ago

Ah, my apologies, I forgot to mention that this is currently not the version on the Registry.

Yes, we will make a new release, most likely tomorrow (UK time).

Rambatino commented 2 years ago

Brilliant, thank you :)

kavalerov commented 2 years ago

@Rambatino the new version is in the Terraform Registry, so all should be working now :)

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-2994