Managing Tag Defaults

This topic describes how to you can specify tags to be automatically applied to resources at creation time.

Overview of Tag Defaults

Tag defaults let you specify tags that are applied automatically to all resources at the time of creation in a specific compartment. This feature allows you to ensure that appropriate tags are applied at resource creation without requiring the user creating the resource to have access to the tag namespaces. Consider the following example:

Alice is a finance administrator and has access to the restricted tag namespace Finance. Alice can set up a tag default to apply the Finance.CostCenter tag with a value of W1234 to all resources. Eli can create resources but does not have access to the Finance tag namespace. When Eli creates a resource, the Finance.CostCenter tag is automatically applied with a value of W1234. Eli cannot change this tag, and Alice is confident that it is always applied correctly and not changed by the users who create or edit resources.

Tag defaults allow tenancy administrators to create secure permissions boundaries between users concerned with governance and users who need to create and administer resources.

Where to Manage Tag Defaults

Tag defaults are defined for a specific compartment. In the Console, you manage tag defaults on the Compartment Details page.

This screenshot shows the Compartment Details page in the Console

Required Permissions for Working with Tag Defaults

To create or edit a tag default for a compartment, you must be granted the following combination of permissions:

  • manage tag-defaults access on the compartment where you are adding the tag default
  • use tag-namespaces access on the compartment where the tag namespace resides
  • inspect tag-namespaces access on the tenancy

For the full mapping of permissions to API operations, see Details for IAM.

For example, assume you created a set of tag namespaces in CompartmentA. To give a group named TagAdmins access to add tag defaults to CompartmentA, write a policy with the following statements:

Allow group TagAdmins to manage tag-defaults in compartment CompartmentA
Allow group TagAdmins to use tag-namespaces in compartment CompartmentA
Allow group TagAdmins to inspect tag-namespaces in tenancy

Now assume you also want to allow TagAdmins to create tag defaults in CompartmentA using tag namespaces that reside in CompartmentZ. Add a statement to allow TagAdmins to use tag namespaces in CompartmentZ:

Allow group TagAdmins to use tag-namespaces in compartment CompartmentZ

Now when TagAdmins create tag defaults in CompartmentC, they can use tag namespaces that reside in either CompartmentA or CompartmentZ.

Important

See this known issue for information about the policy statements required for using tag defaults with Compute instance pools and cluster networks.

Working with Tag Defaults

You can only use tag defaults with defined tags. Free-form tags are not supported for tag defaults.

You can define up to 5 tag defaults per compartment.

After a tag default is created in a compartment:

  • The default tag is applied to any new resources created in that compartment.
  • Previously existing resources in the compartment are not tagged retro-actively.
  • If you change the default value of the tag default, existing occurrences are not updated.

Deleting Tag Defaults

  • If you delete the tag default from the compartment, existing occurrences of the tag are not removed from resources.
  • When you delete a tag key definition, existing tag defaults based on that tag key definition are not removed from the compartment. Until you delete the tag default in the compartment, the tag default continues to count against your limit of 5 tag defaults per compartment.

Required Tag Values

For tag defaults, you must include a tag value, but you have a choice about how the value is applied.

  • Default value
  • User-applied value

If you use a default value, then you must create it. This value is applied to all resources.

If you specify that a user-applied value is required, then the user creating the resource must enter the value for the tag at the time of resource creation. Users cannot create resources without entering a value for the tag.

Tip

You can use predefined values and user-applied values to ensure that users only apply a value that you trust. See Using Predefined Values.

Tag Inheritance

The default tag is applied to all resources created in the compartment, including child compartments and the resources created in the child compartments.

Example:

  • In CompartmentA, you create a tag default, TagA.

    Resources (and compartments) created in CompartmentA are automatically tagged with TagA.

    • In the subcompartment, CompartmentB, you create tag default, TagB.

      Resources and compartments created in CompartmentB are automatically tagged with TagA and TagB.

      • In the sub-subcompartment, CompartmentC, you create tag default TagC.

        Resources created in CompartmentC are automatically tagged with TagA, TagB, and TagC.

This example is illustrated in the following graphic:

This image shows an example of nested compartments and how default tags are inherited

Overriding Tag Defaults

Tag defaults can be overridden at the time of resource creation by users who have the appropriate permissions to both create the resource and to use the tag namespace.

Example: CompartmentA has a tag default defined to apply CostCenter.Operations="42". Pradeep belongs to a group that grants him permissions to create instances in CompartmentA and also to use tag namespaces in CompartmentA. He creates an instance in CompartmentA, and in the Create Instance dialog, he applies the tag CostCenter.Operations="50". Because he has the appropriate permissions, when the instance is created, the tag default is overridden, and the instance is tagged with CostCenter.Operations="50".

After a resource is created and tagged, users with the appropriate permissions to both update the resource and to use the tag namespace can modify the default tags that were applied at resource creation.

Tag Defaults and Retired Tags

Retired tags can't be applied to new resources. Therefore, if the tag namespace or tag key specified in a tag default is retired, when new resources are created, the retired tag is not applied. As a best practice, you should delete the tag default that specifies the retired tag.

Tag Defaults and Tag Variables

You can use tag variables in tag defaults. Tag variables dynamically resolve at resource creation time. For example, you enter a tag variable for principal name as the tag default in a particular compartment.

Operations.CostCenter="${iam.principal.name}"

Davis and Garcia each create buckets in that compartment. The buckets that Davis creates include default tags that contain his name as the value, while the buckets that Garcia creates have his name.

Operations.CostCenter="Davis"

Operations.CostCenter="Garcia"

Meanwhile, the tag default still contains the original variables. See Using Tag Variables.

Limits on Tag Defaults

A maximum of 5 tag defaults can be defined per compartment.

Note

When you delete a tag key definition, existing tag defaults based on that tag key definition are not removed from the compartment. Until you delete the tag default in the compartment, the tag default continues to count against your limit of 5 tag defaults per compartment.

See Limits on Tags for more limits on tags.

Using the Console

Caution

Avoid entering confidential information when assigning descriptions, tags, or friendly names to your cloud resources through the Oracle Cloud Infrastructure Console, API, or CLI.
To create a tag default
  1. Open the navigation menu. Under Governance and Administration, go to Identity and click Compartments.

    A list of the compartments that you have access to displays.

  2. In the list, click the name of the compartment to which you want to add a tag default.

  3. On the compartment details page, click Tag Defaults.

    The list of existing tag defaults displays.

  4. Click Create Tag Default.
  5. Enter the following (all fields are required):
    • Tag Namespace: Select the tag namespace for the tag default.
    • Tag Key: Select the tag key.
  6. Specify the type of value you want this tag to have: 
    • Default Value: Enter the value you want this tag to have.
    • User-applied Value: Users that create resources must enter the value as resources are created.
  7. Click Create Tag Default.
To update the default value of a tag default
  1. Open the navigation menu. Under Governance and Administration, go to Identity and click Compartments.

    A list of the compartments that you have access to displays.

  2. In this list, click the name of the compartment that has the tag default that you want to update.

  3. On the compartment details page, click Tag Defaults.

    The list of existing tag defaults displays.

  4. Find the tag default you want to update. Go to the the Actions icon (three dots) and click Edit.
  5. Specify the type of value you want this tag to have: 
    • Default Value: Enter the value you want this tag to have.
    • User-applied Value: Users that create resources must enter the value as resources are created.
  6. Click Save Changes.
To delete a tag default
  1. Open the navigation menu. Under Governance and Administration, go to Identity and click Compartments.

    A list of the compartments that you have access to displays.

  2. In the list, click the name of the compartment that has the tag default that you want to delete.

  3. On the compartment details page, click Tag Defaults.

    The list of existing tag defaults displays.

  4. Find the tag default that you want to delete. Go to the the Actions icon (three dots) and click Delete.
  5. Confirm when prompted.