Terraform is available as a managed service in Resource Orchestration Service (ROS). You can create Terraform templates to define Alibaba Cloud, Amazon Web Services (AWS), or Microsoft Azure resources, specify resource parameters, and configure dependency relationships for resources.
Scenario
If you want to create and manage resources of a third-party cloud platform such as AWS or Microsoft Azure on Alibaba Cloud, you can define the third-party resources and configure dependency relationships for the resources in a Terraform template. This helps you manage resources across cloud platforms in a convenient 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, choose Templates > My Templates.
On the My Templates page, click Create Template.
From the ROS drop-down list, select Terraform.
Create a Terraform template.
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}" }
In the upper-right corner of the Create Template page, choose .
In the Save as My Template dialog box, configure the Template Name, Template Description, Resource Group, and Tag parameters.
Click OK.