IBM Cloud Docs
Deleting resources

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:

  1. From the IBM Cloud® console, click the Navigation Menu icon Navigation Menu icon > Resource list to view your list of resources.
  2. Expand the sections to locate the service instance that you want to delete.
  3. Click the Actions icon 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.

  1. Log in, and select the account.

    ibmcloud login
    
  2. Delete a service instance by running the ibmcloud resource service-instance-delete command, where NAME is the name of the service instance, exclusive with ID, and ID 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.

  1. 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.

  2. After you finish building your configuration file, initialize the Terraform CLI. For more information, see Initializing Working Directories.

    terraform init
    
  3. Provision the resources from the main.tf file. For more information, see Provisioning Infrastructure with Terraform.

    1. Run terraform plan to generate a Terraform execution plan to preview the proposed actions.

      terraform plan
      
    2. 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