Create a Terraform template

更新时间:
复制 MD 格式

Resource Orchestration Service (ROS) is a managed service for Terraform. You can create Terraform templates to define resources from Alibaba Cloud, AWS, or Azure, configure resource parameters, and set dependencies between resources.

Scenarios

To manage resources from multiple cloud platforms, such as AWS and Azure, on Alibaba Cloud, you can define the resources and their dependencies in a template. This method simplifies resource management in a multicloud environment.

Background information

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

Procedure

  1. Log on to the ROS console.

  2. In the navigation pane on the left, choose Templates > My Templates.

  3. On the My Templates page, click Create Template.

  4. For Template Type, select Terraform.

  5. Create a Terraform template.

    The following example shows how to create a vSwitch in a virtual private cloud (VPC).

    1. Create the modules/vpc/main.tf file and add content to the file to create a VPC.

      1. To the right of the directory, click + and then click Create Folder.image

      2. In the Create Folder dialog box, enter modules to create a folder named modules.

      3. Hover the pointer over the modules folder, click + on the right, and then click Create Folder.

      4. In the Create Folder dialog box, enter vpc to create a subfolder named vpc in the modules folder.

      5. Hover the pointer over the vpc folder, click + on the right, and then click Create File.

      6. In the Create File dialog box, enter main.tf to create a main.tf file in the vpc folder.

      7. Click main.tf and enter the following code in the editor on the right 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}"
        }

        image

    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. In the editor on the right, enter the following code 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}"
        }

        image

  6. In the lower-left corner of the Create Template page, choose Save Template > Save as My Template.

  7. In the Save as My Template dialog box, set the Template Name, Template Description, Resource Group, and Tags.

  8. Click OK.

References