cockroachdb / terraform-provider-cockroach

Terraform provider for CockroachDB Cloud
Apache License 2.0
56 stars 10 forks source link

Cannot create a SQL user after creating a dedicate cluster (right away) #34

Closed aindeev closed 1 year ago

aindeev commented 1 year ago

Since new clusters take about 30 minutes to provision, it is not actually possible to create a SQL user right away. Basically ends up with a 404 error until the provisioning is complete.

GKE suffers from slow start-up as well and typically we see terraform just waiting and checking for status update until considering that the cluster is fully up.

module.cockroach_global_user_service.cockroach_sql_user.user: Creating...
module.cockroach_global_user_service.google_secret_manager_secret_version.version: Creation complete after 1s [id=projects/664563636243/secrets/cockroach_sql_connection_global_user_service/versions/1]
╷
│ Error: Error creating sql user
│ 
│   with module.cockroach_global_user_service.cockroach_sql_user.user,
│   on ../modules/cockroach/main.tf line 23, in resource "cockroach_sql_user" "user":
│   23: resource "cockroach_sql_user" "user" {
│ 
│ Could not create sql user, unexpected error: &{404 Not Found 404 HTTP/2.0 2 0 map[Alt-Svc:[h3=":443"; ma=2592000,h3-29=":443"; ma=2592000] Cc-Version:[2022-03-31] Content-Length:[130]
│ Content-Security-Policy:[sandbox] Content-Type:[application/json] Date:[Fri, 14 Oct 2022 21:39:54 GMT] Strict-Transport-Security:[max-age=63072000; preload] Via:[1.1 google]] {{
│   "code": 5,
│   "message": "internal call failed: cluster '<<uuid-redacted>>' is not found",
│   "details": []
│ }} 130 [] false false map[] 0x14000396600 0x1400009f6b0} %!v(MISSING) 404 Not Found

TF Code:


resource "cockroach_cluster" "main" {
  name           = "test-name"
  cloud_provider = "GCP"
  create_spec = {
    dedicated = {
      region_nodes  = {
        us-west2 = 3
      }
      hardware = {
        machine_spec = {
          machine_type = "n1-standard-2"
        }
      }
    }
  }
}

resource "cockroach_sql_user" "user" {
  id       = cockroach_cluster.cluster.id
  name     = "test
  password = "test"
}
prafull01 commented 1 year ago

This has been resolved now as our TF provider always waits for the cluster provisioning and then proceeds to create other resources dependent on the cluster creation.

marksoper commented 1 year ago

Thanks @prafull01 . @aindeev this should be fixed now. Please let us know if now.