Deleting resources
When you don't need a resource in your account anymore, or if a user in your account created a resource that you don't want them to use, you can delete the instance from your account.
Deleting resources in the console
You can delete a resource in the console by using the following steps:
- From the IBM Cloud® console, click the Navigation Menu icon > Resource list to view your list of resources.
- Expand the sections to locate the service instance that you want to delete.
- Click the Actions icon > Delete for the row.
Deleting resources by using the CLI
You can delete a resource by using the IBM Cloud® Command Line Interface. For detailed information about managing IBM Cloud resources, see Working with resources and resource groups.
-
Log in, and select the account.
ibmcloud login
-
Delete a service instance by running the
ibmcloud resource service-instance-delete
command, whereNAME
is the name of the service instance, exclusive with ID, andID
is the ID of the service instance, exclusive with NAME.ibmcloud resource service-instance-delete (NAME|ID) [-f, --force] [--recursive]
For example, the following command deletes a resource service-instance that's named
my-service-instance
:ibmcloud resource service-instance-delete my-service-instance
Deleting resource instances by using the API
You can programmatically delete a resource instance by calling the Resource Controller API as shown in the following sample request. For detailed information about the API, see Resource Controller API.
curl -X DELETE \
https://resource-controller.cloud.ibm.com/v2/resource_instances/8d7af921-b136-4078-9666-081bd8470d94 \
-H 'Authorization: Bearer <>'
DeleteResourceInstanceOptions deleteResourceInstanceOptions = new DeleteResourceInstanceOptions.Builder()
.id(instanceGuid)
.recursive(false)
.build();
Response<Void> response = service.deleteResourceInstance(deleteResourceInstanceOptions).execute();
System.out.printf("deleteResourceInstance() response status code: %d\n", response.getStatusCode());
const params = {
id: instanceGuid,
recursive: false,
};
resourceControllerService.deleteResourceInstance(params)
.then(res => {
console.log('deleteResourceInstance() response status code: ' + res.status);
})
.catch(err => {
console.warn(err)
});
response = resource_controller_service.delete_resource_instance(
id=instance_guid,
recursive=False
)
print('\ndelete_resource_instance() response status code: ',
response.get_status_code())
deleteResourceInstanceOptions := resourceControllerService.NewDeleteResourceInstanceOptions(
instanceGUID,
)
deleteResourceInstanceOptions.SetRecursive(false)
response, err := resourceControllerService.DeleteResourceInstance(deleteResourceInstanceOptions)
if err != nil {
panic(err)
}
fmt.Printf("\nDeleteResourceInstance() response status code: %d\n", response.StatusCode)
Deleting resource instances by using Terraform
Use the following steps to delete resource instances by using Terraform.
-
You can delete a resource instance by removing the following code block from your terraform file. You must have created the
resource_instance
using the terraform file.data "ibm_resource_group" "group" { name = "test" } resource "ibm_resource_instance" "resource_instance" { name = "test" service = "cloud-object-storage" plan = "lite" location = "global" resource_group_id = data.ibm_resource_group.group.id tags = ["tag1", "tag2"] //User can increase timeouts timeouts { create = "15m" update = "15m" delete = "15m" } }
For more information, see the argument reference details on the Terraform Resource Management page.
-
After you finish building your configuration file, initialize the Terraform CLI. For more information, see Initializing Working Directories.
terraform init
-
Provision the resources from the
main.tf
file. For more information, see Provisioning Infrastructure with Terraform.-
Run
terraform plan
to generate a Terraform execution plan to preview the proposed actions.terraform plan
-
Run
terraform apply
to create the resources that are defined in the plan.terraform apply
-
You can also delete a resource instance by running the following terraform destroy
command.
terraform destroy -target RESOURCE_TYPE.NAME -target RESOURCE_TYPE2.NAME