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
-
Log on to the ROS console.
-
In the left-side navigation pane, click Stacks.
-
In the top navigation bar, select a region for the stack, such as China (Hangzhou).
-
On the Stacks page, click Create Stack.
-
On the Select Template page, in the Specify Template section, select Select an Existing Template.
-
Set Template Import Method to Enter Template Content, and for Template Content, select Terraform.
-
Write the Terraform template and click Next.
The following Terraform template creates a vSwitch in a VPC.
-
Create the
modules/vpc/main.tffile to define a VPC.-
Click the + icon to the right of the directory, then click Create Folder.
-
In the Create Folder dialog box, enter modules.
-
Hover over the modules folder, click the + icon on the right, and then click Create Folder.
-
In the Create Folder dialog box, enter
vpcto create a folder namedvpcin the modules folder. -
Hover over the
vpcfolder, click the + icon on the right, and then click Create File. -
In the Create File dialog box, enter main.tf to create the main.tf file in the
vpcfolder. -
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 }
-
-
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 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 }NoteThe
availability_zonevalue must match the region of the stack.
-
-
-
On the Configure Parameters page, specify the Stack Name.
-
In the Configure Stack Settings section, configure properties such as Timeout Period, Deletion Protection, Tags, and RAM Role. Then, click Next.
-
On the Compliance Precheck page, click Next. Compliance precheck does not apply to Terraform templates.
-
On the Check and Confirm page, click Create.
NoteAfter 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.