IBM Cloud Docs
Managing resource groups

Managing resource groups

A resource group is a way for you to organize your account resources in customizable groupings so that you can quickly assign users access to multiple resources at a time. Any account resource that is managed by using IBM Cloud® Identity and Access Management (IAM) access control belongs to a resource group within your account. You can group resources and assign access to individual service instances or entire resource groups that use IAM.

To start managing your resource groups, in the IBM Cloud® console, go to Manage > Account > Account resources > Resource groups. You can create, view, and rename your resource groups, add resources and manage access to your resource groups. You can also delete any resource group only if it doesn't contain any resources, and it isn't the default resource group. The IBM Cloud account owner can add resources to any resource group, but other users must be granted access by using an IAM access policy.

For more information about working with resource groups, see Best practices for organizing resources and assigning access.

Creating a resource group

If you have a Pay-As-You-Go or Subscription account, you can create multiple resource groups to easily manage quota and view billing usage for a set of resources. You can also group resources to make it easier for you to assign users access to more than one instance at a time. You can have a maximum of 1000 resource groups per account. You must be assigned an IAM policy with the Administrator role on All Account Management services to create additional resource groups. If you have a Lite account or 30-day trial, you can't create extra resource groups, but you can rename your default resource group.

Creating a resource group in the console

  1. In the IBM Cloud console, go to Manage > Account > Account resources > Resource groups.
  2. Click Create.
  3. Enter a name for your resource group.
  4. Click Create.

Creating a resource group by using the CLI

You can create and rename a resource group, or view a resource in one by using the IBM Cloud® Command Line Interface. For detailed information about working with resources, see Working with resources and resource groups.

  1. Log in, and select the account.
    ibmcloud login
    
  2. Create a new resource group by running ibmcloud resource group-create command. For example, the following command creates a resource group that is named group2:
ibmcloud resource group-create group2

Creating a resource group by using the API

If you have a Pay-As-You-Go or Subscription account, you can create multiple resource groups to easily manage quota and view billing usage for a set of resources. You can also group resources to make it easier for you to assign users access to more than one instance at a time.

You must be assigned an IAM policy with the Administrator role on All Account Management services to create additional resource groups. If you have a Lite account or 30-day trial, you can't create extra resource groups, but you can rename your default resource group.

To create a resource group, call the IBM Cloud® Resource Manager API as shown in the following example:

curl -X POST https://resource-controller.cloud.ibm.com/v2/resource_groups -H 'Authorization: Bearer <IAM_TOKEN>'
  -H 'Content-Type: application/json' -d '{
      "account_id": "987d4cfd77b04e9b9e1a6asdcc861234",
      "name": "test"
    }'
CreateResourceGroupOptions createResourceGroupOptions = new CreateResourceGroupOptions.Builder()
        .accountId(exampleUserAccountId)
        .name("ExampleGroup")
        .build();
Response<ResCreateResourceGroup> response = resourceManagerService.createResourceGroup(createResourceGroupOptions).execute();
ResCreateResourceGroup resCreateResourceGroup = response.getResult();
System.out.println(resCreateResourceGroup);
const params = {
  accountId: exampleUserAccountId,
  name: "ExampleGroup"
};
resourceManagerService.createResourceGroup(params)
  .then(res => {
    resourceGroupId = res.result.id;
    console.log(JSON.stringify(res.result, null, 2));
  })
  .catch(err => {
    console.warn(err)
  });
res_create_resource_group = resource_manager_service.create_resource_group(
  account_id=example_user_account_id,
  name='ExampleGroup',
).get_result()
print(json.dumps(res_create_resource_group, indent=2))
createResourceGroupOptions := resourceManagerService.NewCreateResourceGroupOptions()
createResourceGroupOptions.SetAccountID(exampleUserAccountID)
createResourceGroupOptions.SetName("ExampleGroup")
resCreateResourceGroup, response, err := resourceManagerService.CreateResourceGroup(createResourceGroupOptions)
if err != nil {
  panic(err)
}
b, _ := json.MarshalIndent(resCreateResourceGroup, "", "  ")
fmt.Println(string(b))

Before you begin

Before you can manage resource groups 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.

Creating a resource group by using Terraform

Use the following steps to create a resource group by using Terraform:

  1. Create an argument in your main.tf file. The following example creates a resource group by using the ibm_resource_group resource, where name is a unique name to identify the resource group.

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

    You can specify tags associated with the resource group instance. 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
      

Renaming a resource group

Your first resource group is created and named Default for you. You can update the name of this group or any other groups that you create.

Renaming a resource group in the console

  1. In the IBM Cloud console, go to Manage > Account > Account resources > Resource groups.
  2. Click the Actions List of actions icon menu, and select Rename.
  3. Enter a unique name and click Save.

Renaming a resource group by using the CLI

  1. Log in, and select the account.
    ibmcloud login
    
  2. Rename a resource group by running the ibmcloud resource group-update command. For example, the following command renames the Default resource group to Admin:
ibmcloud resource group-update Default [-n, --name Admin]

Renaming a resource group by using the API

The variable name identifies the new name of the resource group. For m ore details, see the API.

curl -X PATCH https://resource-controller.cloud.ibm.com/v2/resource_groups/09f8c1c0742c493f80baaf7835212345 -H 'Authorization: Bearer <IAM_TOKEN>'
  -H 'Content-Type: application/json' -d '{
      "name": "test1"
    }'
UpdateResourceGroupOptions updateResourceGroupOptions = new UpdateResourceGroupOptions.Builder()
  .id(resourceGroupId)
  .name("RenamedExampleGroup")
  .state("ACTIVE")
  .build();
Response<ResourceGroup> response = resourceManagerService.updateResourceGroup(updateResourceGroupOptions).execute();
ResourceGroup resourceGroup = response.getResult();
System.out.println(resourceGroup);
const params = {
  id: resourceGroupId,
  state: 'ACTIVE',
  name: 'RenamedExampleGroup'
};
resourceManagerService.updateResourceGroup(params)
  .then(res => {
    console.log(JSON.stringify(res.result, null, 2));
  })
  .catch(err => {
    console.warn(err)
  });
resource_group = resource_manager_service.update_resource_group(
  id=resource_group_id,
  name='RenamedExampleGroup',
  state='ACTIVE',
).get_result()
print(json.dumps(resource_group, indent=2))
updateResourceGroupOptions := resourceManagerService.NewUpdateResourceGroupOptions(
  resourceGroupID,
)
updateResourceGroupOptions.SetName("RenamedExampleGroup")
updateResourceGroupOptions.SetState("ACTIVE")
resourceGroup, response, err := resourceManagerService.UpdateResourceGroup(updateResourceGroupOptions)
if err != nil {
  panic(err)
}
b, _ := json.MarshalIndent(resourceGroup, "", "  ")
fmt.Println(string(b))

Renaming a resource group by using Terraform

You can rename a resource group by using Terraform.

  1. To install the Terraform CLI and configure the IBM Cloud Provider plug-in for Terraform, follow 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.

  2. Create a Terraform configuration file that is named main.tf. In this file, you add the configuration to rename a resource group by using HashiCorp Configuration Language. For more information, see the Terraform documentation.

    You can rename the resource group by updating name with a new value in the following example.

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

    For more information, see the argument reference details on the Terraform Resource Management page.

  3. Initialize the Terraform CLI.

    terraform init
    
  4. Run terraform plan to generate a Terraform execution plan to preview the proposed actions. The Terraform execution plan summarizes all the actions that need to be run to rename the resource group.

    terraform plan
    
  5. Rename the resource group.

    terraform apply
    

Adding resources to a resource group

Services that are managed with IAM belong to a resource group. When you create an instance of one of these services from the catalog, you're prompted to assign the instance to a resource group. Be sure to plan how you want to organize resources in your account before you assign them to a resource group. Your resource group selection at the time of creating the instance is final and can't be changed.

Your resource group selection at the time of creating the instance is final and can't be changed.

The IBM Cloud account owner can add resources to any resource group, but other users must be granted access by using an IAM access policy. Users in your account must be assigned two access policies to create resources from the catalog and add them to a resource group:

  • A policy with viewer role or higher on the resources group itself
  • A policy with editor role or higher on the service in the account

To add the resources to a resource group, complete the following steps:

  1. In the IBM Cloud console, go to Manage > Account > Account resources > Resource groups.
  2. Click the Actions List of actions icon menu, and select Add resources.
  3. From here, you are directed to the catalog. You can search the products or filter based on a specific category, provider, pricing plan, type of compliance, or release type. Examples of resources include apps, service instances, container clusters, storage volumes, virtual servers, and software.

Adding resources to a resource group by using the API

See Managing catalog settings to set the visibility of the IBM Cloud® catalog and to control access to products in the public catalog and private catalogs for users in your account.

Viewing resources in a resource group

To easily view the resources that are assigned to a resource group, go to the Navigation Menu icon Navigation Menu icon > Resource list. Then, filter by resource group.

If you can't find your classic infrastructure resource on the Resource list page, check the Device list by clicking Navigation Menu icon Navigation Menu icon > Classic infrastructure > Device list.

Viewing resources in a resource group by using the CLI

  1. Log in, and select the account.

    ibmcloud login
    
  2. View the resources that are assigned to a specific resource group by running the ibmcloud resource service-instances command. For example, the following command lists all the resources that are in the Default resource group:

ibmcloud resource service-instances -g Default

Viewing resources in a resource group by using the API

To view resources in a resource group, call the IBM Cloud® Resource Controller API as shown in the following example:

curl -X GET https://resource-controller.cloud.ibm.com/v2/resource_instances -H 'Authorization: Bearer <>'
ListResourceInstancesOptions listResourceInstancesOptions = new ListResourceInstancesOptions.Builder()
  .name(resourceInstanceName)
  .build();
Response<ResourceInstancesList> response = service.listResourceInstances(listResourceInstancesOptions).execute();
ResourceInstancesList resourceInstancesList = response.getResult();
System.out.printf("listResourceInstances() response:\n%s\n", resourceInstancesList.toString());
const params = {
  name: resourceInstanceName,
};
resourceControllerService.listResourceInstances(params)
  .then(res => {
    console.log('listResourceInstances() response:\n' + JSON.stringify(res.result, null, 2));
  })
  .catch(err => {
    console.warn(err)
  });
resource_instances_list = resource_controller_service.list_resource_instances(
    name=resource_instance_name
).get_result()
print('\nlist_resource_instances() response:\n',
      json.dumps(resource_instances_list, indent=2))
listResourceInstancesOptions := resourceControllerService.NewListResourceInstancesOptions()
listResourceInstancesOptions = listResourceInstancesOptions.SetName(resourceInstanceName)
resourceInstancesList, response, err := resourceControllerService.ListResourceInstances(listResourceInstancesOptions)
if err != nil {
  panic(err)
}
b, _ := json.MarshalIndent(resourceInstancesList, "", "  ")
fmt.Printf("\nListResourceInstances() response:\n%s\n", string(b))

Deleting a resource group by using the console

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.

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