Terraform is an open source tool for automated resource orchestration. ROS hosts Terraform as a managed service. Create Terraform templates and stacks to orchestrate Alibaba Cloud, Amazon Web Services (AWS), and Microsoft Azure resources through ROS API-compatible operations.
Limits
Terraform supports a subset of ROS features and resources. Features and resources supported by Terraform in ROS.
Development methods
Write and test Terraform code using any of the following methods:
-
Use an on-premises environment.
-
Use the Terraform online debugging tool (Alibaba Cloud resources only).
-
(Recommended) Create a Terraform stack in the ROS console, then continue or update it as needed. Create a Terraform stack, Continue to create a stack, Update a stack.
Benefits of using Terraform in ROS
ROS adds the following capabilities beyond Terraform CLI:
-
Same console experience
The ROS console manages Terraform templates with the same experience as native ROS templates, centralizing all resource management.
On the Create Stack page in the ROS console, enter a Stack Name, select a Region such as China (Hangzhou), and load your Terraform template.
The console renders template variables as a visual form with drop-down options and default values for parameters such as VPC Configuration, vSwitch, Instance Type, and Security Group.
$ terraform plan Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create # alicloud_vpc.default will be created + resource "alicloud_vpc" "default" { + cidr_block = "10.0.0.0/8" + vpc_name = (known after apply) } Plan: 6 to add, 0 to change, 0 to destroy.$ terraform apply alicloud_vpc.default: Creating... alicloud_vpc.default: Creation complete after 6s [id=vpc-bp1...] alicloud_vswitch.default[0]: Creating... alicloud_vswitch.default[0]: Creation complete after 5s [id=vsw-bp1...] Apply complete! Resources: 6 added, 0 changed, 0 destroyed. -
Dynamic queries and selection of parameters and properties
-
Dynamically queries valid parameter values.
-
References a single parameter across multiple properties.
-
Displays parameters in a GUI with selectable values. AssociationProperty and AssociationPropertyMetadata.
When you configure parameters, fields such as Virtual Private Cloud (VPC) and Security Group display a drop-down list of available resources in the current region, dynamically filtered by previously selected parameters.
In a template's Parameters section, specify
AssociationPropertyto query regional resources andAssociationPropertyMetadatato add filter conditions. The ROS console then displays selectable values for these parameters.You can then select existing resources from drop-down lists instead of manually entering resource IDs.
-
-
Price inquiries for template resources
Before deployment, ROS calculates and displays estimated resource prices from your Terraform template for budget planning.
The Price Details dialog lists estimated costs by Resource Type (such as ECS and RDS instances), Specifications, Region, Quantity, and Billing Method. The total Prepaid Monthly Fee is displayed at the top.
-
Service activation and role checks
-
Automatic checks: ROS checks whether services in the template are activated and required roles exist before deployment. If a service like Transit Router is not activated, a Dependency Check dialog appears, indicating the number of issues and providing an Activation Link to the service's activation page.
-
Hint and guidance: If a required service is not activated or a role is missing, ROS provides guidance to complete the configuration.
Clicking the activation link redirects you to the service page (such as Transit Router) where you accept the Service Agreement to activate it.
-
-
Risk detection
ROS detects potential risks before you execute operations, such as deleting a security group.
When you delete a stack, the Delete Stack dialog displays a Risk Alert listing resources with dependencies (such as a security group referenced by an ECS instance). You must select a Deletion Method (retain resources or release resources) and confirm the Stack Name to proceed.
-
Template version management and sharing
ROS provides version control for Terraform templates. View Template Details (ID, sharing status, timestamps), switch versions with the Template Version selector, view Template Content (such as HCL code in a main.tf file) online, share via Share Template, or deploy with Create Stack.
-
Tag and resource group propagation
Propagate tags and resource groups to all template resources in one operation.
Scenarios
Create a Terraform stack
To orchestrate and manage resources across cloud platforms (AWS, Azure) or on-premises environments in a centralized manner, create a Terraform stack. Create a Terraform stack.
Create a Terraform template
To manage third-party cloud resources (AWS, Azure) from Alibaba Cloud, define them with dependency relationships in a Terraform template. Create a Terraform template.
Template structure
Define resources, parameters, and dependency relationships in Terraform templates to orchestrate Alibaba Cloud, AWS, and Azure resources. Structure of Terraform templates, What is Alibaba Cloud Terraform?
Development suggestions
Follow these best practices when developing Terraform code for ROS. Methods and suggestions for Terraform code development.
-
Refine variable definitions.
-
Specify the provider version.
-
Use pseudo parameters to obtain stack information.
-
Control the input mode of parameters and variables in the console.
-
Use Aliyun::Terraform-v1.0 or later.
-
Use Metadata to control the display of parameters and variables in the console.
-
Save on-premises code to the files whose names end with .debug.tf.
-
Do not declare the Alibaba Cloud provider (alicloud) in the .tf file.
-
Use ROS parameters other than .tfvars files to pass variable values.