Resources

The detailed information of resources, including configurations and dependencies.
  • Resources can reference Parameters, Mappings, and Functions.
  • Resources can be referenced by other Resources and Outputs.

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:
  • Resource
  • Action
Yes
  • "Type": "ZStack::Resource::VmInstance"
  • "Type": "ZStack::Action::AddIpRange"
  • For more information, see Type
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
  • "DependsOn": [{"Ref": "WebServer1"}]
  • For more information, see DependsOn
DeletionPolicy
  • Specifies whether to retain a resource after its stack is deleted. Options:
    • Retain
    • Delete
  • If this field is set to Retain, a specific resource and its dependent resource will be retained. (The system automatically retains the dependent resource.)
  • The default value is Delete.
No
Description The string that describes the resource. No
  • "Description" : "attach ip range to l3 network"

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 UUID
    • UUID-1 and UUID-2 are 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 Resource type and Action type.
    • 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.
  • Properties
    • The resource properties that specify parameters for resource creation.
    • The following example shows the Properties syntax.
      "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 DependsOn attribute, you can specify that the creation of a specific resource follows another.
    • When you add a DependsOn attribute to a resource, the resource is created only after the creation of the resource specified in the DependsOn attribute.
    • The following example shows the DependsOn syntax.
      {
          "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.

  • DeletionPolicy
    • DeletionPolicy specifies whether to retain a resource after its stack is deleted.
    • DeletionPolicy has two options: Retain and Delete.
      • Delete: The default value, which indicates that after a resource stack is deleted, all resources in the stack will be deleted.
      • Retain: If the DeletionPolicy attribute is set to Retain, 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"
          }
        }