Using Attributes
Edit your Oracle Cloud Stack template, and use the runtime attributes of resources to configure other resources within the same template.
For an introduction, see What are Attributes.
The GetAtt Function
While provisioning a stack, Oracle Cloud Stack uses REST endpoints to collect the specified resource attributes. For example, the response payload for the endpoint View a Service Instance describes the available attributes for an Oracle Database Cloud Service resource.
Refer to the REST documentation for a specific resource type in order to identify its list of attributes. See List of Resource Types.
Use the GetAtt
function in your template to retrieve an attribute from a resource:
Fn::GetAtt: [resourceName, attributeName]
For example:
parameters:
dbURL: { "Fn::GetAtt": [mydb, connect_descriptor] }
clusterSize: { "Fn::GetAtt": [mydb, num_nodes] }
Nested Attributes
The JSON response payload from a REST endpoint may include a hierarchy of attributes. For example:
{
"keyComponentInstance": "mysql",
"adminHostName": "mytestinstance-mysql-1",
"components": {
"mysql": {
"attributes": {
"CONNECT_STRING": {
"displayName": "Connect Descriptor",
"type": "STRING",
"value": "142.114.43.1:3306\/mytestinstance"
}
}
}
}
}
The attribute name input for the GetAtt
function supports a dot notation in order to access nested attributes within a JSON payload. For example, to access the highlighted attribute in the previous JSON response:
parameters:
dbURL: { "Fn::GetAtt": [mydb, components.mysql.attributes.CONNECT_STRING.value] }
Stack Attributes
When you monitor running stacks from the CLI or REST API, Oracle Cloud Stack returns a set of standard runtime attributes for each stack, such as who created the stack. But a template can also define custom stack attributes.
Define attributes within the attributes
node of your template file. Give each attribute a name and an optional description. For example:
attributes:
OraConnectString:
description: Connection string for Oracle database
Assign a value to each attribute. Use the GetAtt
function to retrieve the value of a resource’s attribute. For example:
attributes:
OraConnectString:
value: { "Fn::GetAtt": [mydb, components.mysql.attributes.CONNECT_STRING.value] }
description: Connection string for Oracle database