Resource Orchestration Service (ROS) does not support propagation of native Terraform templates. This topic describes how to convert a native Terraform template into a Terraform template that is supported by ROS.
Prerequisites
alibabacloud-ros-tran is installed.
For more information, see ROS Template Transformer.
Terraform template overview
For more information about Terraform templates, see What is Terraform?
main.tf
# 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.tf
output "vpc_id" {
value = alicloud_vpc.myvpc.id
}
output "vswitch_id" {
value = alicloud_vswitch.myvswitch.id
}
Solution
You can run the following command to convert a native Terraform template into a Terraform template that is supported by ROS:
rostran transform templates/terraform/alicloud -S terraform --compatible
Parameters
templates/terraform/alicloud: the address of the on-premises Terraform template.
-S: the format of the original template file. In this example, the Terraform format is used. Valid values: auto, terraform, excel, and cloudformation. Default value: auto. By default, the format of the original template file is determined based on the suffix of the SOURCE_PATH value.
--compatible: specifies whether to use the compatibility mode. If the compatibility mode is used, the original Terraform template file is retained in the converted template. If the compatibility mode is not used, the original Terraform template file is converted based on the syntax of ROS templates. This parameter is applicable only to Terraform template files.
Converted Terraform template
The following sample code shows a ROS-compatible Terraform template that is converted from a native Terraform template. For more information, see Structure of Terraform templates.
ROSTemplateFormatVersion: '2015-09-01'
Transform: Aliyun::Terraform-v1.2
Workspace:
main.tf: |
# 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.tf: |
output "vpc_id" {
value = alicloud_vpc.myvpc.id
}
output "vswitch_id" {
value = alicloud_vswitch.myvswitch.id
}