Updated on 2024-07-11 GMT+08:00

Creating a Stack

On the Stacks page, click Create Stack in the upper right corner, as shown in Figure 1.

Figure 1 Creating a stack

Procedure:

  1. Select a template.
    There are two ways to select a template, as shown in Figure 2: (1) Enter a URL of an OBS template. (2) Upload a local template file. (3) Select a template from My Templates.
    Figure 2 Selecting a template

    You can upload template files in either .tf or .tf.json format.

    Sample of the .tf template for creating a VPC and an ECS:

    terraform {
        required_providers {
          huaweicloud = {
            source  = "huawei.com/provider/huaweicloud"
            version = "1.41.0"
          }
        }
      }
    
      provider "huaweicloud" {
        cloud     = "myhuaweicloud.com"
        endpoints = {
          iam = "iam.cn-north-4.myhuaweicloud.com"
        }
        insecure   = true
        region     = "cn-north-4"
        auth_url   = "https://iam.cn-north-4.myhuaweicloud.com:31943/v3"
      }
    
      variable "vpc_name" {
        type        = string
        description = "vpc name"
        default     = "rf_teststack_vpc"
        sensitive   = true
        nullable    = false
      }
    
      variable "subnet_name" {
        type        = string
        description = "subnet name"
        default     = "rf_teststack_subnet"
      }
    
      variable "ecs_name" {
        type        = string
        description = "ecs name"
        default     = "rf_teststack_ecs"
      }
    
      variable "ecs_admin_passwd" {
        type        = string
        description = "ecs passwd"
      }
    
      resource "huaweicloud_vpc" "rf_doc_vpc" {
        name   = var.vpc_name
        cidr   = "192.168.0.0/16"
      }
    
      resource "huaweicloud_vpc_subnet" "rf_doc_subnet" {
        name       = var.subnet_name
        vpc_id     = huaweicloud_vpc.rf_doc_vpc.id
        cidr       = "192.168.1.0/24"
        gateway_ip = "192.168.1.1"
      }
    
      resource "huaweicloud_compute_instance" "rf_doc_ecs" {
        name               = var.ecs_name
        flavor_id          = "c7.large.2"
        admin_pass         = var.ecs_admin_passwd
        image_id           = "cecc4bcf-b055-4d35-bd5f-693d4412eaef"
        network {
          uuid = huaweicloud_vpc_subnet.rf_doc_subnet.id
        }
        system_disk_type   = "SAS"
        system_disk_size   = 100
        stop_before_destroy = false
        delete_disks_on_termination = true
        charging_mode      = "postPaid"
        auto_renew         = false
      }
    
      output "ecs_address" {
        value = huaweicloud_compute_instance.rf_doc_ecs.access_ip_v4
        description = "The ecs private address."
      }
    
      output "ecs_id" {
        value = huaweicloud_compute_instance.rf_doc_ecs.id
        description = "The ecs resource id."
      }

    Sample of the .tf.json template for creating a VPC and an ECS:

    {
        "terraform": {
          "required_providers": {
            "huaweicloud": {
              "source": "huawei.com/provider/huaweicloud",
              "version": "1.41.0"
            }
          }
        },
        "provider": {
          "huaweicloud": {
            "cloud": "myhuaweicloud.com",
            "endpoints": {
              "iam":"iam.cn-north-4.myhuaweicloud.com"
            },
            "insecure": true,
            "region": "cn-north-4",
            "auth_url": "https://iam.cn-north-4.myhuaweicloud.com:31943/v3"
          }
        },
        "variable": {
          "vpc_name": {
            "type": "string",
            "description": "vpc name",
            "default": "rf_teststack_vpc",
            "sensitive": true,
            "nullable": false
          },
          "subnet_name": {
            "type": "string",
            "description": "subnet name",
            "default": "rf_teststack_subnet"
          },
          "ecs_name": {
            "type": "string",
            "description": "ecs name",
            "default": "rf_teststack_ecs"
          },
          "ecs_admin_passwd": {
            "type": "string",
            "description": "ecs passwd"
          }
        },
        "resource": {
          "huaweicloud_vpc": {
            "rf_doc_vpc": {
              "name": "${var.vpc_name}",
              "cidr": "192.168.0.0/16"
            }
          },
          "huaweicloud_vpc_subnet": {
            "rf_doc_subnet": {
              "name": "${var.subnet_name}",
              "vpc_id": "${huaweicloud_vpc.rf_doc_vpc.id}",
              "cidr": "192.168.1.0/24",
              "gateway_ip": "192.168.1.1"
            }
          },
          "huaweicloud_compute_instance": {
            "rf_doc_ecs": {
              "name": "${var.ecs_name}",
              "flavor_id": "c7.large.2",
              "admin_pass": "${var.ecs_admin_passwd}",
              "image_id": "cecc4bcf-b055-4d35-bd5f-693d4412eaef",
              "network": {
                "uuid": "${huaweicloud_vpc_subnet.rf_doc_subnet.id}"
              },
              "system_disk_type": "SAS",
              "system_disk_size": 100,
              "stop_before_destroy": false,
              "delete_disks_on_termination": true,
              "charging_mode": "postPaid",
              "auto_renew": false
            }
          }
        },
        "output": {
          "ecs_address": {
            "value": "${huaweicloud_compute_instance.rf_doc_ecs.access_ip_v4}",
            "description": "The ecs private address."
          },
          "ecs_id": {
            "value": "${huaweicloud_compute_instance.rf_doc_ecs.id}",
            "description": "The ecs resource id."
          }
        }
      }

    The sample template contains charged resources. Check whether resources need to be enabled before using the template.

    This template consists of five parts:

    1. huaweicloud_vpc in resource indicates VPC information.
    2. huaweicloud_vpc_subnet in resource indicates information about a subnet defined in the VPC. A subnet is a segment within the IP address range of the VPC.
    3. huaweicloud_compute_instance in resource indicates information about an ECS defined in the template.
    4. variable indicates variables defined by users in templates during stack creation and deployment.
    5. output defines the outputs of templates. After a stack is created, its output is generated based on the definition and displayed on the Outputs tab page.
  2. Configure parameters.

    Click Next to go to the Configure Parameters page, where you can modify the stack name and description, as shown in Figure 3.

    The stack name must start with a letter and can contain a maximum of 128 characters, including letters, digits, underscores (_), and hyphens (-). The name must be unique.

    A stack description can contain a maximum of 1,024 characters.

    Figure 3 Configuring parameters

    Parameters marked with a red asterisk (*) are mandatory. Set these parameters to valid values.

    If you enter an invalid value, the text box will turn red (as shown in Figure 4) and clicking Next will not redirect you to the next page.

    Figure 4 Text box with an invalid value

    Click Next. The Configure Stack page is displayed.

    If the stack name or description is imported using a URL and contains special characters, the characters must be encoded following the HTTP encoding rules first.

    Check whether the default VPC, subnet, and ECS names used on this page already exist on the corresponding consoles. If the names already exist, change them to unique ones to prevent creation failures.

  3. Configure the stack.
    Click Next to go to the Advanced Settings page, as shown in Figure 5.
    Figure 5 Configuring the stack

    Mandatory parameter (marked with *)

    Agency: An agency can clearly define operation permissions of RFS (such as creation, update, and deletion) on stack resources. If the agency permissions are insufficient, subsequent operations may fail.

    Optional parameters:

    Deletion Protection: prevents the stack from being deleted accidentally. After a stack is created, you can update this configuration by clicking Update in the Operation column.

    Auto-Rollback: Enabling auto-rollback will revert the stack to the last successful resource status in the event of a failed operation.

    Click Next to go to the Confirm Configurations page.

  4. Confirm the configurations.

    After you confirm the configurations, you can click either Create Execution Plan or Directly Deploy Stack.

    1. If you click Directly Deploy Stack, a confirmation dialog box will be displayed.
      Figure 6 Directly deploy stack
      Click Yes. A new stack is generated and its status is Deployment In Progress, as shown in Figure 7.
      Figure 7 Deployment in progress

      Then, the status changes to Deployment Complete, as shown in Figure 8.

      Figure 8 Deployment complete
    2. Clicking Create Execution Plan will open a dialog box where you can name and describe the execution plan, as shown in Figure 9.
      Figure 9 Create Execution Plan dialog box

      Click OK. The Execution Plans tab page is displayed.

      Wait until the execution plan is created and refresh the page. The execution plan status changes to Available, as shown in Figure 10.

      Figure 10 Available

      Return to the stack list page. The stack status is Creation Complete, as shown in Figure 11.
      Figure 11 Stack list

      Creating an execution plan can preview the resource attribute changes of the entire stack and evaluate the impact. If the execution plan meets your expectations, you can apply the plan. Creating an execution plan does not incur fees. The system changes your stack only when you execute the plan.

      Click Deploy in the Operation column of the execution plan to deploy it, as shown in Figure 12.

      Figure 12 Execution plan dialog box

      In the Execution Plan dialog box, click Execute. A message is displayed in the upper right corner, indicating that the execution plan is being deployed. Return to the stack list page. A new stack is generated and its status is Deployment In Progress, as shown in Figure 13.

      Figure 13 Deployment in progress

      Then, the stack status changes to Deployment Complete, as shown in Figure 14.

      Figure 14 Deployment complete

      On the Execution Plans tab page of the stack details page, the execution plan status is Applied, as shown in Figure 15.

      Figure 15 Applied

      Click the Events tab. The event list shows that resources of the stack are deployed, as shown in Figure 16.

      Figure 16 Resources deployed

      You can view details on the console of the corresponding cloud service.

      1. In the service list, locate and click Elastic Cloud Server. On the displayed page, view the deployed ECS, as shown in Figure 17.
        Figure 17 ECS

        Resources of the stack are deployed.