Resource Orchestration Service (ROS) allows you to manage resources by using Terraform. You can create Terraform templates to define Alibaba Cloud, AWS, and Azure resources, specify resource parameters, and configure dependencies between resources.

Background information

For more information about the structure of Terraform templates, see Terraform template structure.

Procedure

  1. Log on to the ROS console.
  2. In the left-side navigation pane, choose Templates > My Templates.
  3. On the My Templates page, click Create Template.
  4. In the Create Template dialog box, set Template Name and Template Description.
  5. Set Template Import Method to Enter Template Content and set Template Content to Terraform.
  6. Write a Terraform template.

    In the following example, a VSwitch is created within a VPC to show how to write a Terraform template.

    1. Create a file named main.tf in the modules/vpc/ directory and edit its content to create a VPC.
      1. Click the + icon to the right of Directory, and then select Create Folder.create
      2. In the Create Folder dialog box, enter modules and click OK. A folder named modules is displayed in the directory.
      3. Move the pointer over the modules folder, click the + icon to its right, and then select Create Folder.
      4. In the Create Folder dialog box, enter vpc and click OK. A folder named vpc is displayed under the modules folder.
      5. Move the pointer over the vpc folder, click the + icon to its right, and then select Create File.3
      6. In the Create File dialog box, enter main.tf and click OK. A file named main.tf is displayed under the vpc folder.
      7. Click main.tf, and then enter the following code in the right-side field to create a VPC:
        resource "alicloud_vpc" "vpc" {
          name       = "tf_test"
          cidr_block = "172.16.0.0/12"
        }
        output "vpc_id" {
          value = "${alicloud_vpc.vpc.id}"
        }
        1
    2. Edit the main.tf file in the root directory to create a VSwitch in the VPC.
      1. Click the main.tf file in the root directory.
      2. Enter the following code in the right-side field to create a VSwitch:
        module "my_vpc" {
          source      = "./modules/vpc"
        }
        resource "alicloud_vswitch" "vsw" {
          vpc_id            = "${module.my_vpc.vpc_id}"
          cidr_block        = "172.16.0.0/21"
          availability_zone = "cn-shanghai-b"
        }
        output "vsw_id" {
          value = "${alicloud_vswitch.vsw.id}"
        }
        2
  7. Click OK.