All Products
Search
Document Center

Resource Orchestration Service:Create a Terraform stack

最終更新日:Dec 23, 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), and Microsoft Azure.

Scenario

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.

Procedure

  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. In this example, the China (Hangzhou) region is selected.

  4. On the Stacks page, click Create Stack.

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

  6. Set the Template Import Method parameter 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 main.tf 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 main.tf and click OK. A file named main.tf is created in the vpc folder.

      7. Click the main.tf 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 = "172.16.0.0/12"
        }
        output "vpc_id" {
          value = "${alicloud_vpc.vpc.id}"
        }
    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 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        = "172.16.0.0/21"
          availability_zone = "cn-shanghai-b"
        }
        output "vsw_id" {
          value = "${alicloud_vswitch.vsw.id}"
        }
        Note

        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, Tags, and RAM Role parameters. Then, click Next.

  10. In the Compliance Precheck step, click Next. The compliance precheck feature is not supported by Terraform templates.

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

    Note

    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.

References