Deleting a workspace
After you destroy all associated VPC resources, if you don't need the workspace anymore, you can also delete the Schematics workspace.
Make sure that you delete the resources in the workspace before you delete the workspace. If you delete the workspace without cleaning up the related resources, the resources would still be left behind and might have to be cleaned up individually.
Deleting a workspace by using the UI
- In the IBM Cloud console on the Schematics > Workspaces page, select Actions > Delete workspace to delete the schematics workspace.
- Confirm the action by entering the workspace name in the text box and click Delete workspace.
Deleting a workspace by using the CLI
Run the following command to delete your workspace:
ibmcloud schematics workspace delete --id <WORKSPACE_ID>
You can monitor the log files to view the deletion progress of your workspace.
Deleting a workspace by using the API
-
To delete a workspace by using the IBM Cloud Schematics Python APIs, create a Python file and provide a name of your choice, for example,
schematics_delete_workspace.py. -
Copy and paste the Delete a workspace using Schematics Python API example request to your Python file.
-
Change the following parameters as part of the request:
- Replace your IBM Cloud key to the
authenticator = IAMAuthenticator('<ibm-api-key>')variable. - Change the API endpoint to the endpoint mentioned in API endpoints according to the location that you want your Schematics
workspace to reside, for example,
schematics_service.set_service_url('https://us.schematics.cloud.ibm.com').
- Replace your IBM Cloud key to the
-
Inside the
schematics_service.delete_workspacefunction, provide the following parameters:-
Provide the workspace ID that you generated in the Creating a workspace task, for example
us-south.workspace.Terraform-Schematics-Python-Workspace.b3bbc9f5. -
Export your IBM Cloud API key by using the following command:
export IBMCLOUD_API_KEY =”<ibm-cloud-api-key>” -
Run the following curl command to create a refresh token:
curl -X POST "https://iam.cloud.ibm.com/identity/token" -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=$IBMCLOUD_API_KEY" -u bx:bx -
If you want to destroy the resources as well as delete the workspace, then set the
destroy_resourcesparameter value toTrue. In this case, the resources are deleted first, and then the workspace is deleted. -
If you want to delete the workspace but not the resources, then remove the
destroy_resourcesparameter completely or set thedestroy_resourcesparameter toFalse. If resources are already deleted, and if thedestroy_resourcesparameter value is set toTrue, then the RESOURCE DELETE action is in the FAILED state.
-
-
Run the Python script by using
python3 <python-file-name>to delete the workspace. -
You get the status
Started Deleting Schematic WorkspaceandCompleted Deleting Schematic Workspacein response if the parameters passed as part of the request are valid. You should be able to see that the workspace is deleted in the Schematics that you created. If you don’t get a successful response, the error response contains the errors that you need to resolve. Resolve those errors and run the script until you are able to get a valid response and the workspace is deleted.
Example Python request
# Delete a workspace using Schematics Python API
import json, logging
from ibm_schematics.schematics_v1 import SchematicsV1
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
logging.basicConfig()
logging.root.setLevel(logging.NOTSET)
logging.basicConfig(level=logging.NOTSET)
authenticator = IAMAuthenticator('<ibmcloud-api-key>')
schematics_service = SchematicsV1(authenticator = authenticator)
schematics_service.set_service_url('https://us.schematics.cloud.ibm.com')
logging.info("Started Deleting Schematic Workspace")
workspace_delete_response = schematics_service.delete_workspace(
w_id='<workspace id>',
refresh_token='<refresh-token>',
destroy_resources= True,
).get_result()
print(json.dumps(workspace_delete_response, indent=2))
logging.info("Completed Deleting Schematic Workspace")
Example Python response
INFO:root:Started Deleting Schematic Workspace
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): iam.cloud.ibm.com:443
DEBUG:urllib3.connectionpool:https://iam.cloud.ibm.com:443 "POST /identity/token HTTP/1.1" 200 987
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): us.schematics.cloud.ibm.com:443
DEBUG:urllib3.connectionpool:https://us.schematics.cloud.ibm.com:443 "DELETE /v1/workspaces/us-south.workspace.Schematic-Sunil-Test-Workspace.5a4cbf11?destroy_resources=true HTTP/1.1" 200 2
""
INFO:root:Completed Deleting Schematic Workspace