Oracle Cloud Infrastructure Documentation

Using Tag Variables

You can use a variable to set the value of a defined tag. When you add the tag to a resource, the variable resolves to the data it represents. You can use tag variables in defined tags and default tags. You cannot use tag variables in free-form tags.

Required IAM Policy

Tag variables are a feature of defined tags. To allow users to work with tag variables, use the same IAM policy for working with managing tag namespaces and tags. For more information, see Required Permissions for Working with Defined Tags.

If you're new to policies, see Getting Started with Policies and Common Policies. If you want to dig deeper into writing policies for groups or other IAM components, see Details for IAM.

Working with Tag Variables

Consider the following example:

Operations.CostCenter="${iam.principal.name} at ${oci.datetime}"

Operations is the namespace, CostCenter is the tag key, and the tag value contains two tag variables ${iam.principal.name} and ${oci.datetime}. When you add this tag to a resource, the variable resolves to your user name (the name of the principal that applied the tag) and a time date stamp for when you added the tag.

user_name at 2019-06-18T18:00:57.604Z

The variable is replaced with data at the time you apply the tag. If you later edit the tag, the variable is gone and only the data remains. You can edit the tag value in all the ways you would edit any other tag value.

To create a tag variable, you must use a specific format.

${<variable>}

Type a dollar sign followed by open and close curly brackets. The tag variable goes between the curly brackets. You can use tag variables with other tag variables and with string values.

Supported Tag Variables

The following tag variables are supported.

Variable Description
${iam.principal.name} The name of the principal that tagged the resource.
${iam.principal.type} The type of principal that tagged the resource.
${oci.datetime} The date and time that the tag was created.