IBM Cloud Docs
Deleting a resource group

Deleting a resource group

You can't delete the default resource group that's added to your account. Besides the default one, you can only delete a resource group if it doesn't contain any resources.

Deleting a resource group in the console

To delete a resource group that doesn't contain resources and is not your default, complete the following steps:

  1. In the IBM Cloud console, go to Manage > Account > Account resources > Resource groups.
  2. Click the Actions icon Actions icon > Delete.

Deleting a resource group by using the CLI

To delete a resource group that doesn't contain resources and is not your default, run the ibmcloud resource group-delete. For example, delete resource group example-group:

ibmcloud resource group-delete example-group -f

Deleting a resource group by using the API

You can programmatically delete a resource group by calling the Resource Manager API as shown in the following sample request. For detailed information about the API, see Resource Manager API.

curl -X DELETE \
  https://resource-controller.cloud.ibm.com/v2/resource_groups/09f8c1c0742c493f80baaf7835212345 \
  -H 'Authorization: Bearer <IAM_TOKEN>'
  -H 'Content-Type: application/json'
String id = '09f8c1c0742c493f80baaf7835212345';
DeleteResourceGroupOptions options = new DeleteResourceGroupOptions.Builder().id(id).build();
Response<Void> response = service.deleteResourceGroup(options).execute();
System.out.println(response):
const params = {
    id: '09f8c1c0742c493f80baaf7835212345'
};
service.deleteResourceGroup(params).then(response => {
    console.log(response)
}).catch(err => {});
delete_resource_group(self,
        id: str,
        **kwargs
    ) -> DetailedResponse
ID := "09f8c1c0742c493f80baaf7835212345"
deleteResourceGroupOptionsModel := service.NewDeleteResourceGroupOptions(ID)
detailedResponse, err := service.DeleteResourceGroup(deleteResourceGroupOptionsModel)

Deleting a resource group by using Terraform

Before you can delete a resource group by using Terraform, make sure that you have completed the following:

  • Install the Terraform CLI and configure the IBM Cloud Provider plug-in for Terraform. For more information, see the tutorial for Getting started with Terraform on IBM Cloud®. The plug-in abstracts the IBM Cloud APIs that are used to complete this task.
  • Create a Terraform configuration file that is named main.tf. In this file, you define resources by using HashiCorp Configuration Language. For more information, see the Terraform documentation.

Use the following steps to delete a resource group:

The resource group can be deleted only if there are no resources in it.

  1. You can delete the resource group by removing the following code block from your Terraform main.tf file. You must have created the resourceGroup using the Terraform file.

    resource "ibm_resource_group" "resourceGroup" {
     name     = "prod"
    }
    

    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 group by running the following terraform destroy command.

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