Resources
The detailed information of resources, including configurations and dependencies.
Resourcescan referenceParameters,Mappings, andFunctions.Resourcescan be referenced by otherResourcesandOutputs.
Syntax
Each resource consists of a logical UUID and a description.
- All resource descriptions are enclosed in braces
{ }. - Multiple resources are separated with commas
,.
The key fields of
Resources are as follows.| Key Field | Description | Required | Example |
|---|---|---|---|
| Type | The type of the resource that is being
declared. Options:
|
Yes |
|
| Properties | The resource properties that specify parameters for resource creation. | Yes | For more information, see Properties |
| DependsOn | Specifies that the creation of a specific resource follows another. | No |
|
| DeletionPolicy |
|
No |
|
| Description | The string that describes the resource. | No |
|
Example
The following example shows the
Parameters
syntax."Resources" : {
"UUID-1" : {
"Description" : "The resource description",
"Type" : "The resource type",
"Properties" : {
The resource properties
}
},
"UUID-2" : {
"Description" : "The resource description"
"Type" : "The resource type",
"Properties" : {
The resource properties
},
"DependsOn":"The dependent resource. Take UUID-1 for example. Note that this dependent resource should be contained in the context.",
"DeletionPolicy":"The deletion policy"
}
}In this example, two resources are declared in
Resources. The
description of key fields are as follows:Resource UUIDUUID-1andUUID-2are the resource UUIDs. Both of them are variables.- You can use the resource UUID to reference the resource in other parts of the template.
- The resource UUID is unique in a template.
Type- The type of the resource that is being declared, including the
Resourcetype andActiontype. - For example,
"Type": "ZStack::Resource::VmInstance"indicates that the resource is a VM instance."Type": "ZStack::Action::AddIpRange"indicates the IP range to be added. - For more information about the resource types supported by CloudFormation, see the Resource Index topic.
- The type of the resource that is being declared, including the
Properties- The resource properties that specify parameters for resource creation.
- The following example shows the
Propertiessyntax."Resources" : { "InstanceOffering" : { "Type" : "ZStack::InstanceOffering", "Properties" : { "cpuNum" : "1", "cpuSpeed" : "1", "memorySize" : "1073741824", "name" : "instance-offering", "type" : "UserVm", "sortKey": 0, "allocatorStrategy": "LeastVmPreferredHostAllocatorStrategy" } } } - The rules of defining resource property values are as follows:
- Property values can be text strings, string lists, boolean values, references, or return values of functions.
- Text strings are enclosed with double quotation marks
"". - String lists are enclosed with brackets
[]. - Return values of intrinsic functions and references are
enclosed with braces
{}. - The preceding rules also apply when property values are the combinations of text strings, string lists, references, and return values of functions.
- The following example shows how to declare different types
of
properties.
"Properties" : { "String" : "string", "LiteralList" : [ "value1", "value2" ], "Boolean" : "true" "ReferenceForOneValue" : { "Ref" : "ResourceID" } , "FunctionResultWithFunctionParams" : { "Fn::Join" : [ "%", [ "Key=", { "Ref" : "SomeParameter" } ] ] } }
- If the resource does not require you to declare a property, this part can be skipped.
DependsOn- With the
DependsOnattribute, you can specify that the creation of a specific resource follows another. - When you add a
DependsOnattribute to a resource, the resource is created only after the creation of the resource specified in theDependsOnattribute. - The following example shows the
DependsOnsyntax.{ "ZStackTemplateFormatVersion" : "2018-06-18", "Resources" : { "WebServer": { "Type": "ZStack::Resource::VmInstance", "DependsOn": "DatabseServer" }, "DatabseServer": { "Type": "ZStack::Resource::VmInstance", "Properties": { "name": {"Fn::Join":["-",[{"Ref":"ZStack::StackName"},"VM"]]}, "instanceOfferingUuid": {"Ref":"InstanceOfferingUuid"}, "imageUuid":{"Ref":"ImageUuid"}, "l3NetworkUuids":[{"Ref":"PrivateNetworkUuid"}], "dataDiskOfferingUuids":[{"Ref":"DiskOfferingUuid"}], "hostUuid":{"Ref":"HostUuid"} } } } }This example indicates that WebServer is created only after DatabaseServer is created.
- With the
DeletionPolicyDeletionPolicyspecifies whether to retain a resource after its stack is deleted.DeletionPolicyhas two options:RetainandDelete.Delete: The default value, which indicates that after a resource stack is deleted, all resources in the stack will be deleted.Retain: If theDeletionPolicyattribute is set toRetain, the specific resource will be retained after its stack is deleted. Furthermore, the dependent resource of the resource will also be retained. (The system automatically retains the dependent resource.)The following example shows that the VM instance is retained after the template-based resource stack is deleted."Resources" : { "VMInstance" : { "Type" : "ZStack::Resource::VmInstance", "Properties": { "name": {"Fn::Join":["-",[{"Ref":"ZStack::StackName"},"VM"]]}, "instanceOfferingUuid": {"Ref":"InstanceOfferingUuid"}, "imageUuid":{"Ref":"ImageUuid"}, "l3NetworkUuids":[{"Ref":"PrivateNetworkUuid"}], "dataDiskOfferingUuids":[{"Ref":"DiskOfferingUuid"}], "hostUuid":{"Ref":"HostUuid"} }, "DeletionPolicy" : "Retain" } }