Skip to content

Commit

Permalink
Allow creating API keys for non-clusters (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
luggage66 authored Jul 28, 2021
1 parent 163481e commit 65741b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
26 changes: 16 additions & 10 deletions ccloud/resource_api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
9 changes: 9 additions & 0 deletions examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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://", "")]
}
Expand Down

0 comments on commit 65741b0

Please sign in to comment.