@@ -52,7 +52,7 @@ func resourceKeyspaceCreate(ctx context.Context, d *schema.ResourceData, meta in
5252 client := meta .(astraClients ).astraClient .(* astra.ClientWithResponses )
5353
5454 databaseID := d .Get ("database_id" ).(string )
55- // keyspaceName := d.Get("name").(string) TODO uncomment
55+ keyspaceName := d .Get ("name" ).(string )
5656
5757 //Wait for DB to be in Active status
5858 if err := retry .RetryContext (ctx , d .Timeout (schema .TimeoutCreate ), func () * retry.RetryError {
@@ -77,30 +77,30 @@ func resourceKeyspaceCreate(ctx context.Context, d *schema.ResourceData, meta in
7777 // Success fetching database
7878 db := res .JSON200
7979 switch db .Status {
80- // case astra.ERROR, astra.TERMINATED, astra.TERMINATING: TODO uncomment
81- // // If the database reached a terminal state it will never become active
82- // return retry.NonRetryableError(fmt.Errorf("database failed to reach active status: status=%s", db.Status))
83- // case astra.ACTIVE:
84- // keyspaceMutex.Lock()
85- // resp, err := client.AddKeyspaceWithResponse(ctx, astra.DatabaseIdParam(databaseID), astra.KeyspaceNameParam(keyspaceName))
86- // keyspaceMutex.Unlock()
87- // if err != nil {
88- // return retry.NonRetryableError(fmt.Errorf("error calling add keyspace (not retrying) %s", err))
89- // } else if resp.StatusCode() == 409 {
90- // // DevOps API returns 409 for concurrent modifications, these need to be retried.
91- // return retry.RetryableError(fmt.Errorf("error adding keyspace to database (retrying): %s", string(resp.Body)))
92- // } else if resp.StatusCode() == 401 {
93- // // DevOps API returns 401 Unauthorized for requests without the keyspace create permission
94- // return retry.NonRetryableError(fmt.Errorf("error adding keyspace to database (insufficient permissions, role missing 'db-keyspace-create')"))
95- // } else if resp.StatusCode() >= 400 {
96- // return retry.NonRetryableError(fmt.Errorf("error adding keyspace to database (not retrying): %s", string(resp.Body)))
97- // }
98- //
99- // if err := setKeyspaceResourceData(d, databaseID, keyspaceName); err != nil {
100- // return retry.NonRetryableError(fmt.Errorf("error setting keyspace data (not retrying) %s", err))
101- // }
102- //
103- // return nil
80+ case astra .ERROR , astra .TERMINATED , astra .TERMINATING :
81+ // If the database reached a terminal state it will never become active
82+ return retry .NonRetryableError (fmt .Errorf ("database failed to reach active status: status=%s" , db .Status ))
83+ case astra .ACTIVE :
84+ keyspaceMutex .Lock ()
85+ resp , err := client .AddKeyspaceWithResponse (ctx , astra .DatabaseIdParam (databaseID ), astra .KeyspaceNameParam (keyspaceName ))
86+ keyspaceMutex .Unlock ()
87+ if err != nil {
88+ return retry .NonRetryableError (fmt .Errorf ("error calling add keyspace (not retrying) %s" , err ))
89+ } else if resp .StatusCode () == 409 {
90+ // DevOps API returns 409 for concurrent modifications, these need to be retried.
91+ return retry .RetryableError (fmt .Errorf ("error adding keyspace to database (retrying): %s" , string (resp .Body )))
92+ } else if resp .StatusCode () == 401 {
93+ // DevOps API returns 401 Unauthorized for requests without the keyspace create permission
94+ return retry .NonRetryableError (fmt .Errorf ("error adding keyspace to database (insufficient permissions, role missing 'db-keyspace-create')" ))
95+ } else if resp .StatusCode () >= 400 {
96+ return retry .NonRetryableError (fmt .Errorf ("error adding keyspace to database (not retrying): %s" , string (resp .Body )))
97+ }
98+
99+ if err := setKeyspaceResourceData (d , databaseID , keyspaceName ); err != nil {
100+ return retry .NonRetryableError (fmt .Errorf ("error setting keyspace data (not retrying) %s" , err ))
101+ }
102+
103+ return nil
104104 default :
105105 return retry .RetryableError (fmt .Errorf ("expected database to be active but is %s" , db .Status ))
106106 }
@@ -144,7 +144,7 @@ func resourceKeyspaceDelete(ctx context.Context, d *schema.ResourceData, meta in
144144 client := meta .(astraClients ).astraClient .(* astra.ClientWithResponses )
145145
146146 databaseID := d .Get ("database_id" ).(string )
147- // keyspaceName := d.Get("name").(string) TODO uncomment
147+ keyspaceName := d .Get ("name" ).(string )
148148
149149 //Wait for DB to be in Active status
150150 if err := retry .RetryContext (ctx , d .Timeout (schema .TimeoutCreate ), func () * retry.RetryError {
@@ -169,27 +169,27 @@ func resourceKeyspaceDelete(ctx context.Context, d *schema.ResourceData, meta in
169169 // Success fetching database
170170 db := res .JSON200
171171 switch db .Status {
172- // case astra.ERROR, astra.TERMINATED, astra.TERMINATING: TODO uncomment
173- // // If the database reached a terminal state it will never become active
174- // return retry.NonRetryableError(fmt.Errorf("database failed to reach active status: status=%s", db.Status))
175- // case astra.ACTIVE:
176- // keyspaceMutex.Lock()
177- // resp, err := client.DropKeyspaceWithResponse(ctx, astra.DatabaseIdParam(databaseID), astra.KeyspaceNameParam(keyspaceName))
178- // keyspaceMutex.Unlock()
179- // if err != nil {
180- // return retry.NonRetryableError(fmt.Errorf("error calling drop keyspace (not retrying) %s", err))
181- // } else if resp.StatusCode() == 409 {
182- // // DevOps API returns 409 for concurrent modifications, these need to be retried.
183- // return retry.RetryableError(fmt.Errorf("error dropping keyspace from database (retrying): %s", string(resp.Body)))
184- // } else if resp.StatusCode() == 401 {
185- // // DevOps API returns 401 Unauthorized for requests without the keyspace drop permission
186- // return retry.NonRetryableError(fmt.Errorf("error adding keyspace to database (insufficient permissions, role missing 'db-keyspace-drop')"))
187- // } else if resp.StatusCode() >= 400 {
188- // return retry.NonRetryableError(fmt.Errorf("error dropping keyspace from database (not retrying): %s", string(resp.Body)))
189- // }
190- //
191- // d.SetId("")
192- // return nil
172+ case astra .ERROR , astra .TERMINATED , astra .TERMINATING :
173+ // If the database reached a terminal state it will never become active
174+ return retry .NonRetryableError (fmt .Errorf ("database failed to reach active status: status=%s" , db .Status ))
175+ case astra .ACTIVE :
176+ keyspaceMutex .Lock ()
177+ resp , err := client .DropKeyspaceWithResponse (ctx , astra .DatabaseIdParam (databaseID ), astra .KeyspaceNameParam (keyspaceName ))
178+ keyspaceMutex .Unlock ()
179+ if err != nil {
180+ return retry .NonRetryableError (fmt .Errorf ("error calling drop keyspace (not retrying) %s" , err ))
181+ } else if resp .StatusCode () == 409 {
182+ // DevOps API returns 409 for concurrent modifications, these need to be retried.
183+ return retry .RetryableError (fmt .Errorf ("error dropping keyspace from database (retrying): %s" , string (resp .Body )))
184+ } else if resp .StatusCode () == 401 {
185+ // DevOps API returns 401 Unauthorized for requests without the keyspace drop permission
186+ return retry .NonRetryableError (fmt .Errorf ("error adding keyspace to database (insufficient permissions, role missing 'db-keyspace-drop')" ))
187+ } else if resp .StatusCode () >= 400 {
188+ return retry .NonRetryableError (fmt .Errorf ("error dropping keyspace from database (not retrying): %s" , string (resp .Body )))
189+ }
190+
191+ d .SetId ("" )
192+ return nil
193193 default :
194194 return retry .RetryableError (fmt .Errorf ("expected database to be active but is %s" , db .Status ))
195195 }
0 commit comments