Use the rostran CLI tool to convert a Terraform template into a Resource Orchestration Service (ROS) template. This tutorial walks through a working example that provisions an Alibaba Cloud VPC and vSwitch.
How it works
rostran reads your Terraform HCL files and outputs an equivalent ROS JSON template. This lets you manage Alibaba Cloud infrastructure through native ROS tooling without rewriting your configuration from scratch.
For an overview of Terraform templates and how they relate to ROS, see
Step 1: Edit the source template files
A Terraform template consists of two files: main.tf and output.tf. Create these files with the following content.
-
main.tfDefines the provider and two resources: a VPC and a vSwitch that belongs to the VPC.
# Configure the AliCloud Provider provider "alicloud" {} # Create VPC and vSwitch resource "alicloud_vpc" "myvpc" { cidr_block = "172.16.0.0/12" name = "myvpc" } resource "alicloud_vswitch" "myvswitch" { vpc_id = alicloud_vpc.myvpc.id cidr_block = "172.16.0.0/21" availability_zone = "cn-beijing-g" name = "myvswitch" } -
output.tfDeclares the VPC ID and vSwitch ID as outputs so they can be referenced after deployment.
output "vpc_id" { value = alicloud_vpc.myvpc.id } output "vswitch_id" { value = alicloud_vswitch.myvswitch.id }
Step 2: Transform the template
Run one of the following commands. Both produce the same template.json output — choose the one that fits your workflow.
-
Method 1 (recommended for single-file input): Specify the entry point file directly and set the output format to JSON.
rostran transform templates/terraform/alicloud/main.tf --target-format jsonThis command converts
main.tf(and its companionoutput.tf) and writes a JSON-formatted ROS template namedtemplate.jsonto the current directory. -
Method 2 (recommended for directory input): Point to the directory containing all Terraform files and use
--source-format terraformto specify the source format.rostran transform templates/terraform/alicloud --source-format terraformThis command scans the specified directory for Terraform files — including
main.tf— and writestemplate.jsonto the current directory.
Step 3: Verify the transformed ROS template
Open template.json in the current directory to verify the conversion. The file contains the full ROS template in JSON format.
Key differences to note in the output:
Terraform resource references (
alicloud_vpc.myvpc.id) becomeFn::GetAttintrinsic function calls in ROS.The
availability_zonefield maps toZoneId.-
Terraform
outputblocks map directly to the ROSOutputssection.{ "ROSTemplateFormatVersion": "2015-09-01", "Resources": { "alicloud_vpc.myvpc": { "Properties": { "CidrBlock": "172.16.0.0/12", "VpcName": "myvpc" }, "Type": "ALIYUN::ECS::VPC" }, "alicloud_vswitch.myvswitch": { "Properties": { "CidrBlock": "172.16.0.0/21", "VSwitchName": "myvswitch", "VpcId": { "Fn::GetAtt": [ "alicloud_vpc.myvpc", "VpcId" ] }, "ZoneId": "cn-beijing-g" }, "Type": "ALIYUN::ECS::VSwitch" } }, "Outputs": { "vpc_id": { "Value": { "Fn::GetAtt": [ "alicloud_vpc.myvpc", "VpcId" ] } }, "vswitch_id": { "Value": { "Fn::GetAtt": [ "alicloud_vswitch.myvswitch", "VSwitchId" ] } } } }