From 65741b04fd002bfb5b0b6140b47c87895d507ac8 Mon Sep 17 00:00:00 2001 From: Donald Mull Jr Date: Wed, 28 Jul 2021 11:50:15 -0400 Subject: [PATCH] Allow creating API keys for non-clusters (#89) --- ccloud/resource_api_key.go | 26 ++++++++++++++++---------- examples/main.tf | 9 +++++++++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/ccloud/resource_api_key.go b/ccloud/resource_api_key.go index 6a741b6..0e3b66f 100644 --- a/ccloud/resource_api_key.go +++ b/ccloud/resource_api_key.go @@ -111,18 +111,24 @@ func apiKeyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) return diag.FromErr(err) } - log.Printf("[INFO] Created API Key, waiting for it become usable") - stateConf := &resource.StateChangeConf{ - Pending: []string{"Pending"}, - Target: []string{"Ready"}, - Refresh: clusterReady(c, clusterID, accountID, key.Key, key.Secret), - Timeout: 300 * time.Second, - Delay: 10 * time.Second, - PollInterval: 5 * time.Second, - MinTimeout: 20 * time.Second, + if len(clusterID) > 0 { + log.Printf("[INFO] Created API Key, waiting for it become usable") + + stateConf := &resource.StateChangeConf{ + Pending: []string{"Pending"}, + Target: []string{"Ready"}, + Refresh: clusterReady(c, clusterID, accountID, key.Key, key.Secret), + Timeout: 300 * time.Second, + Delay: 10 * time.Second, + PollInterval: 5 * time.Second, + MinTimeout: 20 * time.Second, + } + + _, err = stateConf.WaitForStateContext(context.Background()) + } else { + log.Printf("[INFO] Created API Key") } - _, err = stateConf.WaitForStateContext(context.Background()) if err != nil { return diag.FromErr(fmt.Errorf("Error waiting for API Key (%s) to be ready: %s", d.Id(), err)) } diff --git a/examples/main.tf b/examples/main.tf index b88f5c8..20c4966 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -38,11 +38,20 @@ resource "confluentcloud_schema_registry" "test" { depends_on = [confluentcloud_kafka_cluster.test] } +# api key for a kafka cluster resource "confluentcloud_api_key" "provider_test" { cluster_id = confluentcloud_kafka_cluster.test.id environment_id = confluentcloud_environment.environment.id } +# api key for schema registry +resource "confluentcloud_api_key" "schema-registry" { + logical_clusters = [ + confluentcloud_schema_registry.test.id + ] + environment_id = confluentcloud_environment.environment.id +} + locals { bootstrap_servers = [replace(confluentcloud_kafka_cluster.test.bootstrap_servers, "SASL_SSL://", "")] }