Skip to content

Latest commit

 

History

History
192 lines (144 loc) · 5.75 KB

delete-resources.md

File metadata and controls

192 lines (144 loc) · 5.75 KB
copyright lastupdated keywords subcollection
years
2020, 2023
2023-01-20
account resources, delete resource, delete instance
account

{{site.data.keyword.attribute-definition-list}}

Deleting resources

{: #delete-resource}

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. {: shortdesc}

Deleting resources in the console

{: #delete-resource-console} {: ui}

You can delete a resource in the console by using the following steps:

  1. From your dashboard, click View resources in the Resources summary widget.
  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

{: #delete-resource-cli} {: cli}

You can delete a resource by using the {{site.data.keyword.Bluemix}} 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

    {: codeblock}

  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]

    {: codeblock}

    For example, the following command deletes a resource service-instance that's named my-service-instance:

    ibmcloud resource service-instance-delete my-service-instance

    {: codeblock}

Deleting resource instances by using the API

{: #delete-resource-instance-api} {: 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{: external}.

curl -X DELETE \
https://resource-controller.cloud.ibm.com/v2/resource_instances/8d7af921-b136-4078-9666-081bd8470d94 \
  -H 'Authorization: Bearer <>'

{: pre} {: curl}

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());

{: codeblock} {: java}

const params = {
  id: instanceGuid,
  recursive: false,
};

resourceControllerService.deleteResourceInstance(params)
  .then(res => {
    console.log('deleteResourceInstance() response status code: ' + res.status);
  })
  .catch(err => {
    console.warn(err)
  });

{: codeblock} {: javascript}

response = resource_controller_service.delete_resource_instance(
    id=instance_guid,
    recursive=False
)

print('\ndelete_resource_instance() response status code: ',
      response.get_status_code())

{: codeblock} {: python}

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)

{: codeblock} {: go}

Deleting resource instances by using Terraform

{: #delete-resource-instance-terraform} {: 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"
     }
    }

    {: codeblock}

    For more information, see the argument reference details on the Terraform Resource Management{: external} page.

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

    terraform init

    {: pre}

  3. Provision the resources from the main.tf file. For more information, see Provisioning Infrastructure with Terraform{: external}.

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

      terraform plan

      {: pre}

    2. Run terraform apply to create the resources that are defined in the plan.

      terraform apply

      {: pre}

You can also delete a resource instance by running the following terraform destroy command.

terraform destroy -target RESOURCE_TYPE.NAME -target RESOURCE_TYPE2.NAME

{: pre}