IBM Cloud Docs
Creating resources

Creating resources

A resourceA physical or logical component that can be provisioned or reserved for an application or service instance. Examples of resources can include storage, processors, memory, clusters, and VMs. is anything that you can create from the catalog that is managed by and contained within a resource group. You can create and manage resources by going to your resource list in the IBM Cloud® console or by using the command-line interface (CLI).

Services that are managed by using IBM Cloud Identity and Access Management (IAM) access control and belong to a resource group have several benefits. Because resource groups are not scoped by location, you can create apps and services from different locations in the same resource group. You can also use fine-grained access control down to an individual instance within a resource group.

Required access for creating resources

For users in your account to be able to create resources from the catalog and assign them to a resource group, they must be assigned two access policies:

  • 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

Creating resources in the console

Use the following steps to create a resource in the console:

  1. From the IBM Cloud® console, click the Navigation Menu icon Navigation Menu icon > Resource list to view your list of resources.
  2. Click Create resource. 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.

After you create the resource, it is displayed in your list of resources on the Resource list page.

Creating resources by using the CLI

You can create a resource 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 an organization by running the ibmcloud resource service-instance-create command.

In this command,NAME is the name of the service instance, SERVICE_NAME or SERVICE_ID is the name or ID of the service, SERVICE_PLAN_NAME or SERVICE_PLAN_IDis the name or ID of the service plan, and LOCATIONis the target location or environment to create the service instance.

ibmcloud resource service-instance-create NAME (SERVICE_NAME | SERVICE_ID) SERVICE_PLAN_NAME LOCATION [-d, --deployment DEPLOYMENT_NAME] [-p, --parameters @JSON_FILE | JSON_STRING ] [-g RESOURCE_GROUP] [--service-endpoints SERVICE_ENDPOINTS_TYPE] [--allow-cleanup] [--lock]

To list services, use the ibmcloud catalog service-marketplace command.

For example, the following command creates a service instance that is named my-service-instance, uses service plan test- service-plan of service test-service on location eu-gb:

ibmcloud resource service-instance-create my-service-instance test-service test-service-plan eu-gb

Creating new resource instances by using the API

You can programmatically create a new 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 POST \
  https://resource-controller.cloud.ibm.com/v2/resource_instances \
  -H 'Authorization: Bearer <>' \
  -H 'Content-Type: application/json' \
    -d '{
    "name": "my-instance",
    "target": "bluemix-global",
    "resource_group": "5g9f447903254bb58972a2f3f5a4c711",
    "resource_plan_id": "0be5ad401ae913d8ff665d92680664ed",
    "tags": [
      "my-tag"
    ]
  }'
CreateResourceInstanceOptions createResourceInstanceOptions = new CreateResourceInstanceOptions.Builder()
  .name(resourceInstanceName)
  .target(targetRegion)
  .resourceGroup(resourceGroup)
  .resourcePlanId(resourcePlanId)
  .build();

Response<ResourceInstance> response = service.createResourceInstance(createResourceInstanceOptions).execute();
ResourceInstance resourceInstance = response.getResult();

System.out.printf("createResourceInstance() response:\n%s\n", resourceInstance.toString());
const params = {
  name: resourceInstanceName,
  target: targetRegion,
  resourceGroup: resourceGroupGuid,
  resourcePlanId: resourcePlanId,
};

resourceControllerService.createResourceInstance(params)
  .then(res => {
    instanceGuid = res.result.guid;
    console.log('createResourceInstance() response:\n' + JSON.stringify(res.result, null, 2));
  })
  .catch(err => {
    console.warn(err)
   });
resource_instance = resource_controller_service.create_resource_instance(
    name=resource_instance_name,
    target=target_region,
    resource_group=resource_group,
    resource_plan_id=resource_plan_id
).get_result()

print('\ncreate_resource_instance() response:\n',
      json.dumps(resource_instance, indent=2))
createResourceInstanceOptions := resourceControllerService.NewCreateResourceInstanceOptions(
  resourceInstanceName,
  targetRegion,
  resourceGroup,
  resourcePlanID,
)

resourceInstance, response, err := resourceControllerService.CreateResourceInstance(createResourceInstanceOptions)
if err != nil {
  panic(err)
}

b, _ := json.MarshalIndent(resourceInstance, "", "  ")
fmt.Printf("\nCreateResourceInstance() response:\n%s\n", string(b))

Creating new resource instances by using Terraform

Before you can create new resource instances 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.

You can create new resource instances by using Terraform.

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

    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"
     }
    }
    

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