All Products
Document Center

Resource Orchestration Service:Create a Terraform stack

Last Updated:Feb 02, 2024

Terraform is available as a managed service in Resource Orchestration Service (ROS). You can create Terraform stacks in ROS to orchestrate resources of Alibaba Cloud, Amazon Web Services (AWS), or Microsoft Azure.


If you want to create and manage resources across cloud platforms such as AWS and Microsoft Azure, or across on-premises platforms, you can create Terraform stacks to orchestrate and manage the resources on the platforms in a centralized manner.

Background information

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


  1. Log on to the ROS console.

  2. In the left-side navigation pane, click Stacks.

  3. In the top navigation bar, select the region where you want to create a stack from the region drop-down list. For example, you can select China (Hangzhou).

  4. On the Stacks page, click Create Stack and select Use Terraform from the drop-down list.

  5. In the Specify Template section of the Select Template step, select Select an Existing Template.

  6. Set Template Import Method to Enter Template Content. In the Template Content section, click the Terraform tab.

  7. Create a Terraform template and click Next.

    The following section provides an example on how to create a Terraform template. In this example, a vSwitch is created in a virtual private cloud (VPC).

    1. Create a file named in the modules/vpc/ directory and enter the file content to create a VPC.

      1. In the upper-right corner of the Directory section, click the + icon and select Create Folder.

      2. In the Create Folder dialog box, enter modules and click OK. A folder named modules is created in the Directory section.

      3. Move the pointer over the modules folder, click the + icon on the right side, and then select Create Folder.

      4. In the Create Folder dialog box, enter vpc and click OK. A folder named vpc is created in the modules folder.

      5. Move the pointer over the vpc folder, click the + icon on the right side, and then select Create File.

      6. In the Create File dialog box, enter and click OK. A file named is created in the vpc folder.

      7. Click the file and enter the following code in the right-side code editor to create a VPC:

        resource "alicloud_vpc" "vpc" {
          name       = "tf_test"
          cidr_block = ""
        output "vpc_id" {
          value = "${}"
    2. Edit the file in the root directory to create a vSwitch in the VPC.

      1. Click the file in the root directory.

      2. In the right-side code editor, 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        = ""
          availability_zone = "cn-shanghai-b"
        output "vsw_id" {
          value = "${}"

        You must set the availability_zone parameter in the template to a zone within the region where the stack resides.

  8. In the Configure Parameters step, specify the Stack Name parameter.

  9. In the Configure Stack Settings section, configure the Timeout Period, Deletion Protection, and Tags parameters. Then, click Next.

  10. In the Compliance Precheck step, complete the compliance precheck and click Next.


    The compliance precheck feature is available only for specific resources. For more information, see Compliance precheck of ROS.

    1. In the Evaluate Rules section, add compliance rules.

      You can add compliance rules based on the cloud resources in the ROS template.

    2. Click Evaluate.

      You can modify the template content based on the suggestions that are provided to remediate invalid resources to ensure the compliance of the resources.

  11. In the Check and Confirm step, click Create.


    After the stack is created, you can view the details of the stack by performing the following operations: In the left-side navigation pane of the console, click Stacks. On the Stacks page, find the stack and click the stack ID. On the stack management page, view the stack details, such as the basic information, events, resources, outputs, and template.