Create a Terraform stack

更新时间:
复制 MD 格式

ROS provides managed Terraform support for orchestrating resources across Alibaba Cloud, AWS, or Azure.

Use cases

Create a Terraform stack to create and manage resources centrally across cloud platforms such as AWS and Azure, or in on-premises environments.

Background

The Structure of Terraform templates topic describes the template syntax.

Procedure

  1. Log on to the ROS console.

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

  3. In the top navigation bar, select a region for the stack, such as China (Hangzhou).

  4. On the Stacks page, click Create Stack.

  5. On the Select Template page, in the Specify Template section, select Select an Existing Template.

  6. Set Template Import Method to Enter Template Content, and for Template Content, select Terraform.

  7. Write the Terraform template and click Next.

    The following Terraform template creates a vSwitch in a VPC.

    1. Create the modules/vpc/main.tf file to define a VPC.

      1. Click the + icon to the right of the directory, then click Create Folder.

      2. In the Create Folder dialog box, enter modules.

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

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

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

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

      7. Click main.tf and enter the following code 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 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

        The availability_zone value must match the region of the stack.

  8. On the Configure Parameters page, specify the Stack Name.

  9. In the Configure Stack Settings section, configure properties such as Timeout Period, Deletion Protection, Tags, and RAM Role. Then, click Next.

  10. On the Compliance Precheck page, click Next. Compliance precheck does not apply to Terraform templates.

  11. On the Check and Confirm page, click Create.

    Note

    After the stack is created, click Stacks. On the Stacks page, click a stack ID to view details such as Basic Information, Events, Resources, Outputs, and Template.

Related documents