Mongey / terraform-provider-confluentcloud

A Terraform provider for managing resource in confluent.cloud
MIT License
109 stars 47 forks source link

Crash when creating api_key #106

Open michalbogacz opened 3 years ago

michalbogacz commented 3 years ago

I tried to create API Key for Schema Registry using Service Account.

...
resource "confluentcloud_service_account" "service_account" {
  name        = local.service-account-name
  description = "default service_account"
}

resource "confluentcloud_api_key" "kafka_schema_registry_api_key" {
  cluster_id     = confluentcloud_schema_registry.schema_registry.id
  environment_id = confluentcloud_environment.env.id
  description    = "Service Account Schema Registry API Key"
  user_id        = confluentcloud_service_account.service_account.id
}

I expected similar result as doing ccloud api-key create --service-account {sa-...} --resource {lsrc-..}

But after apply, I got error:

confluentcloud_api_key.kafka_schema_registry_api_key: Still creating... [10s elapsed]
╷
│ Error: Plugin did not respond
│ 
│   with confluentcloud_api_key.kafka_schema_registry_api_key,
│   on kafka.tf line 36, in resource "confluentcloud_api_key" "kafka_schema_registry_api_key":
│   36: resource "confluentcloud_api_key" "kafka_schema_registry_api_key" {
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵

Stack trace from the terraform-provider-confluentcloud_v0.0.12 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0xea36e8]

goroutine 14 [running]:
github.com/Mongey/terraform-provider-confluentcloud/ccloud.clusterReady.func1(0xc000299ee0, 0xc000299ea0, 0x0, 0x0, 0x2, 0x1)
        /home/runner/work/terraform-provider-confluentcloud/terraform-provider-confluentcloud/ccloud/resource_kafka_cluster.go:200 +0xc8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource.(*StateChangeConf).WaitForStateContext.func1(0xc000458900, 0xc000124460, 0xc0000412c0, 0xc0005ccf00, 0xc0001ae7b8, 0xc0001ae7b0)
        /home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.7.0/helper/resource/state.go:110 +0x2e9
created by github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource.(*StateChangeConf).WaitForStateContext
        /home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/v2@v2.7.0/helper/resource/state.go:83 +0x1c6

Error: The terraform-provider-confluentcloud_v0.0.12 plugin crashed!
Matt-S6 commented 3 years ago

@michalbogacz what was your work-around for this? Are schema registry api keys not yet supported?

michalbogacz commented 3 years ago

@Matt-S6 I didn't found work-around

Brianbrifri commented 3 years ago
resource "confluentcloud_api_key" "schema_registry_api_key" {
  logical_clusters = [
    var.schema_registry_id
  ]
  environment_id = var.environment_id
  description    = "Schema Registry API Key for domain ${var.domain}"
  user_id        = confluentcloud_service_account.service_account.id

  depends_on = [confluentcloud_service_account.service_account]
}

This is what worked for me.

samjpv commented 2 years ago

The exact same thing occurs when trying to create a KSQL cluster api key the standard way. I didn't expect it to work given that this provider supports no KSQL-related resources, but it would be helpful to have a more informative error on failure.

Unfortunately, the workaround above gave me the same error as before.