Creates a template.
This topic provides an example on how to create a template. In this example, a template
named MyTemplate
is created in the China (Hangzhou)
region. The TemplateBody
parameter is set to {"ROSTemplateFormatVersion": "2015-09-01"}
.
Debugging
Request parameters
Parameter | Type | Required | Example | Description |
---|---|---|---|---|
Action | String | Yes | CreateTemplate |
The operation that you want to perform. Set the value to CreateTemplate. |
TemplateURL | String | No | oss://ros/template/demo |
The URL of the file that contains the template body. The URL must point to a template that is located on an HTTP or HTTPS web server or in an Alibaba Cloud Object Storage Service (OSS) bucket, such as oss://ros/stack-policy/demo or oss://ros/stack-policy/demo?RegionId=cn-hangzhou. The template body must be 1 to 1,024 bytes in length. If you do not specify the region of the OSS bucket, the value of the RegionId parameter is used. Note You must specify the TemplateBody or TemplateURL parameter.
|
Description | String | No | It is a demo. |
The description of the template. The description can be up to 256 characters in length. |
TemplateBody | String | No | {"ROSTemplateFormatVersion":"2015-09-01"} |
The structure that contains the template body. The template body must be 1 to 524,288 bytes in length. If the length of the template body exceeds the upper limit, we recommend that you add parameters to the HTTP POST request body to prevent request failures caused by excessively long URLs. Note You must specify the TemplateBody or TemplateURL parameter.
You can create a Terraform template based on your business requirements. The following sample code provides an example on how to create a Terraform template:
For more information about Terraform templates, see Structure of Terraform templates. |
TemplateName | String | Yes | MyTemplate |
The name of the template. The name can be up to 255 characters in length, and can contain digits, letters, hyphens (-), and underscores (_). The name must start with a digit or letter. |
ResourceGroupId | String | No | rg-acfmxazb4ph6aiy**** |
The ID of the resource group. For more information about resource groups, see the "Resource Group" section of What is Resource Management? |
Tags.N.Key | String | Yes | usage |
The key of tag N that you want to add to the template. Note The Tags parameter is optional. If you specify the Tags parameter, you must specify
the Tags.N.Key parameter.
|
Tags.N.Value | String | No | test |
The value of tag N that you want to add to the template. |
For more information about common request parameters, see Common parameters.
Response parameters
Parameter | Type | Example | Description |
---|---|---|---|
RequestId | String | 8C5D90E1-66B6-496C-9371-3807F8DA80A8 |
The ID of the request. |
TemplateId | String | 5ecd1e10-b0e9-4389-a565-e4c15efc**** |
The ID of the template. |
Examples
Sample requests
http(s)://ros.aliyuncs.com/?Action=CreateTemplate
&TemplateName=MyTemplate
&TemplateBody={"ROSTemplateFormatVersion":"2015-09-01"}
&<Common request parameters>
Sample success responses
XML
format
HTTP/1.1 200 OK
Content-Type:application/xml
<CreateTemplateResponse>
<RequestId>8C5D90E1-66B6-496C-9371-3807F8DA80A8</RequestId>
<TemplateId>5ecd1e10-b0e9-4389-a565-e4c15efc****</TemplateId>
</CreateTemplateResponse>
JSON
format
HTTP/1.1 200 OK
Content-Type:application/json
{
"RequestId" : "8C5D90E1-66B6-496C-9371-3807F8DA80A8",
"TemplateId" : "5ecd1e10-b0e9-4389-a565-e4c15efc****"
}
Error codes
For a list of error codes, visit the API Error Center.
HTTP status code |
Error code |
Error message |
Description |
---|---|---|---|
400 |
InvalidSchema |
{reason}. |
The error message returned because the template format is invalid. reason indicates the cause of the error. |
400 |
InvalidTemplateAttribute |
The Referenced Attribute ({resource} {name}) is incorrect. |
The error message returned because the template contains an invalid reference of the resource property in the Outputs section. resource indicates the resource name. name indicates the property name. |
400 |
InvalidTemplatePropertyType |
The specified value type of ({resource} {section}) is incorrect. |
The error message returned because the type of the resource property that is defined in a section of the template is invalid. resource indicates the resource name. section indicates the section name. |
400 |
InvalidTemplateReference |
The specified reference "{name}" (in {referencer}) is incorrect. |
The error message returned because the template contains an invalid reference. name indicates the reference name. referencer indicates the referencer name. |
400 |
InvalidTemplateSection |
The template section is invalid: {section}. |
The error message returned because the template contains an invalid section. section indicates the section name. |
400 |
InvalidTemplateVersion |
The template version is invalid: {reason}. |
The error message returned because the template version is invalid. reason indicates the cause of the error. |