copyright | lastupdated | keywords | subcollection | ||
---|---|---|---|---|---|
|
2023-01-20 |
account resources, delete resource, delete instance |
account |
{{site.data.keyword.attribute-definition-list}}
{: #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}
{: #delete-resource-console} {: ui}
You can delete a resource in the console by using the following steps:
- From your dashboard, click View resources in the Resources summary widget.
- Expand the sections to locate the service instance that you want to delete.
- Click the Actions icon > Delete for the row.
{: #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.
-
Log in, and select the account.
ibmcloud login
{: codeblock}
-
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]
{: 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}
{: #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}
{: #delete-resource-instance-terraform} {: 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" } }
{: codeblock}
For more information, see the argument reference details on the Terraform Resource Management{: external} page.
-
After you finish building your configuration file, initialize the Terraform CLI. For more information, see Initializing Working Directories{: external}.
terraform init
{: pre}
-
Provision the resources from the
main.tf
file. For more information, see Provisioning Infrastructure with Terraform{: external}.-
Run
terraform plan
to generate a Terraform execution plan to preview the proposed actions.terraform plan
{: pre}
-
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}