Use Terraform to manage Lindorm resources

Updated at:

This topic describes how to call the API operation of Lindorm as a RAM user in Terraform to create a Lindorm instance.

Prerequisites

  • A RAM user is created and the AliyunLindormFullAccess and AliyunVPCFullAccess permissions are granted to the RAM user.

    Note
    • The AliyunLindormFullAccess permission is granted to the RAM user in this example for demonstration purposes. Grant a fine-grained permission to the RAM user based on your requirements in your actual business. For more information about the RAM permissions policies available for Lindorm, see System policies for Lindorm.

    • If you connect to Terraform by using Cloud shell, you must also grant the AliyunCloudShellFullAccess permission to the RAM user.

  • Terraform is installed and configured. For more information, see Create resources with Terraform and Install and configure Terraform.

Procedure

Create a template

Create a file named main.tf, enter the following content in the file, and then save the file in the current execution directory.

provider "alicloud" {
  region = local.region
}
variable "name" {
  default = "lindormtest"
}

locals {
  region  = "cn-guangzhou"
 zone_id = "cn-guangzhou-a"
}

resource "alicloud_vpc" "vpc" {
vpc_name = var.name
cidr_block = "172.16.0.0/16"
}

resource "alicloud_vswitch" "vswitch" {
vpc_id = alicloud_vpc.vpc.id
cidr_block = "172.16.0.0/24"
zone_id = local.zone_id
vswitch_name = var.name
}

resource "alicloud_lindorm_instance" "default" {
  disk_category              = "cloud_efficiency"
  payment_type               = "PayAsYouGo"
  vpc_id                     = alicloud_vpc.vpc.id
  vswitch_id                 = alicloud_vswitch.vswitch.id
  instance_name              = var.name
  table_engine_specification = "lindorm.g.xlarge"
  table_engine_node_count    = "2"
  instance_storage           = "80"
}

Execute the template

In this topic, Cloud Shell is used to execute the template as an example. The commands vary with the operating system that you use.

  1. Initialize and load required modules, such as the Provider module.

    terraform init

    After the modules are loaded, the result shown in the following figure is returned.

    image

  2. Check whether the template syntax is valid.

    terraform validate

    If the template syntax is valid, the result shown in the following figure is returned.

    image

  3. Create an execution plan.

    terraform plan

    After the execution plan is created, the result shown in the following figure is returned.

    image

  4. Execute the template.

    terraform apply

    After you run the command, enter yes to change resources.image

    After the template is executed, the result shown in the following figure is returned.

    image

    The value of id in the result indicates the ID of the created Lindorm instance.

  5. You can perform the following steps to view the created Lindorm instance.

    1. Log on to the Lindorm console.

    2. In the upper-left corner of the page, select the region where the instance is deployed.

    3. On the Instances page, enter the instance ID in the search box to search for the created Lindorm instance.image