Using Maps

Not Oracle Cloud at Customer This topic does not apply to Oracle Cloud at Customer.

Edit your Oracle Cloud Stack template file to define and use data structures.

Maps allow you to define static values within a template and refer to these values within other template components such as resources. You organize the data within a map as follows:

  • A map contains one or more submaps.

  • A submap contains one or more key-value pairs.

Defining Maps

Define maps within the mappings node of your template file. Within this node, add one or more map nodes.

mappings:
  map1:
    ...
  map2:
  ...

Within each map node, add one or more submap nodes. Each submap contains a JSON object with one or more key-value pairs.

mappings:
  map1:
    submap1: {"key1":"value1","key2":"value2", ...}
    submap2: ...
    ...

For example:

mappings:
  shapeMap:
    database: {"dev":"oc3","prod":"oc4"}

Using Map Values

Retrieve a value within a map by using the FindInMap function, which takes three arguments:

  • The name of the map

  • The name of the submap

  • The key whose value you want to use

For example, suppose you want to retrieve the value for the prod key in the following map:

mappings:
  shapeMap:
    database: {"dev":"oc3","prod":"oc4"}

Running FindInMap with the following arguments results in the value oc4:

"Fn::FindInMap": ["shapeMap", "database", "prod"]

Any of these three arguments can be determined dynamically through the use of other functions. For example, if the key name (dev or prod) is supplied by the user as a template parameter, use the GetParam function:

"Fn::FindInMap": ["shapeMap", "database", {"Fn::GetParam": stage}]