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
Log on to the ROS console.
In the left-side navigation pane, click Stacks.
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.
On the Stacks page, click Create Stack.
In the Specify Template section of the Select Template step, select Select an Existing Template.
Set the Template Import Method parameter to Enter Template Content. In the Template Content section, click the Terraform tab.
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).
Create a file named main.tf in the
modules/vpc/
directory and enter the file content to create a VPC.In the upper-right corner of the Directory section, click the + icon and select Create Folder.
In the Create Folder dialog box, enter modules and click OK. A folder named modules is created in the Directory section.
Move the pointer over the modules folder, click the + icon on the right side, and then select Create Folder.
In the Create Folder dialog box, enter
vpc
and click OK. A folder namedvpc
is created in the modules folder.Move the pointer over the
vpc
folder, click the + icon on the right side, and then select Create File.In the Create File dialog box, enter main.tf and click OK. A file named main.tf is created in the
vpc
folder.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}" }
Edit the main.tf file in the root directory to create a vSwitch in the VPC.
Click the main.tf file in the root directory.
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}" }
NoteYou must set the
availability_zone
parameter in the template to a zone within the region where the stack resides.
In the Configure Parameters step, specify the Stack Name parameter.
In the Configure Stack Settings section, configure the Timeout Period, Deletion Protection, Tags, and RAM Role parameters. Then, click Next.
In the Compliance Precheck step, click Next. The compliance precheck feature is not supported by Terraform templates.
In the Check and Confirm step, click Create.
NoteAfter 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.