Creates a template.

In this example, a template named MyTemplate is created in the China (Hangzhou) region. The template body is set to {"ROSTemplateFormatVersion": "2015-09-01"}.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

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 located in an HTTP or HTTPS web server or an Alibaba Cloud OSS bucket. Examples: oss://ros/template/demo and oss://ros/template/demo?RegionId=cn-hangzhou. The template can be up to 524,288 bytes in length. If the region of the OSS bucket is not specified, the RegionId value is used.

Note You must specify only one of the TemplateBody and TemplateURL parameters.
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 template body. The template body must be 1 to 524,288 bytes in length. If the length of the template body exceeds the maximum length, we recommend that you add the extra parameters to the body of the HTTP POST request. This prevents request failures caused by extremely long URLs.

Note You must specify only one of the TemplateBody and TemplateURL parameters.

You can create a Terraform template based on your needs. Example:


{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Transform": "Aliyun::Terraform-v1.0",
  "Workspace": {
    "main.tf": "variable  \"name\" {  default = \"auto_provisioning_group\"}"
  },
  "Outputs": {}
}

For more information about how to use Terraform, see Terraform template structure.

TemplateName String Yes MyTemplate

The name of the parameter template.

The name can be up to 255 characters in length, and can contain digits, letters, hyphens (-), and underscores (_). It 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 What is a resource group?

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.

HttpCode

Error code

Error message

Description

400

InvalidSchema

{reason}.

The error message returned because the template format is invalid. reason indicates the specific reason.

400

InvalidTemplateAttribute

The Referenced Attribute ({resource} {name}) is incorrect.

The error message returned because the resource property referenced in the Outputs section of the template is invalid. 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 specific reason.