Use Terraform to manage Lindorm resources
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
AliyunLindormFullAccessandAliyunVPCFullAccesspermissions are granted to the RAM user.NoteThe
AliyunLindormFullAccesspermission 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
AliyunCloudShellFullAccesspermission 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.
Initialize and load required modules, such as the Provider module.
terraform initAfter the modules are loaded, the result shown in the following figure is returned.

Check whether the template syntax is valid.
terraform validateIf the template syntax is valid, the result shown in the following figure is returned.

Create an execution plan.
terraform planAfter the execution plan is created, the result shown in the following figure is returned.

Execute the template.
terraform applyAfter you run the command, enter
yesto change resources.
After the template is executed, the result shown in the following figure is returned.

The value of id in the result indicates the ID of the created Lindorm instance.
You can perform the following steps to view the created Lindorm instance.
Log on to the Lindorm console.
In the upper-left corner of the page, select the region where the instance is deployed.
On the Instances page, enter the instance ID in the search box to search for the created Lindorm instance.

