Configuring Tag Defaults

A tag default is a defined tag that is automatically applied to resources that are created in the specified compartment.

Tag defaults have the following characteristics:

  • The tag default is applied to all new resources that are created in that compartment, including in child compartments.

  • The tag default is not applied to resources that already existed before the tag default was created.

  • Tag defaults cannot be changed by creating or editing resources. With permission to use the tag namespace, you can change the value of the tag when you create or modify a resource. To change the tag default that will be applied to all new resources in the compartment, you must update the tag default on the compartment.

  • If you change the default value of the tag default, existing occurrences of that tag default on resources are not updated.

  • If you change a value of a tag key definition whose value is a defined list, or if you delete a tag key definition, existing occurrences of a tag default that is based on that tag key definition are not updated. Tag default values must be separately updated.

See Creating and Managing Tag Key Definitions for information about the effect on tag defaults of retiring or deleting tag key definitions. For more information about tag defaults, see "Tag Defaults" in the Tagging Overview in the Oracle Private Cloud Appliance Concepts Guide.

Creating a Tag Default

To create a tag default, specify a compartment, a tag key definition, and a value. If the value of the selected tag key definition is Static Value, then you can select User-Defined Value for the value of the tag default.

A compartment can have at most five tag defaults.

Using the Compute Web UI

  1. In the navigation menu, click Identity, and then click Compartments.

  2. If the compartment where you want to add a tag default is not listed, navigate to the correct compartment.

    Click the name of the top-level parent compartment and, on the compartment details page, scroll to the Child Compartments box. If necessary, click on the name of another compartment to view those child compartments.

  3. Click the name of the compartment to which you want to add a tag default.

  4. In the Resources section on the compartment details page, click Tag Defaults.

    Ensure that no more than four tag defaults already exist in this compartment.

  5. Click the Create Tag Default button.

  6. In the Tag Default dialog, select the Tag Namespace and the Tag Key.

  7. For Required Tag Value Options, choose one of the following value types:

    • Default Value: Enter the value for this tag default. If the selected tag key has a defined list of values, then this Default Value must be a member of that list.

    • User-Defined Value: Users are required to enter the value when a resource is created. Selecting User-Defined Value is invalid if the selected tag key definition has a predefined list of values.

  8. Click Submit.

    The new tag default is displayed on the compartment details page.

Using the OCI CLI

  1. Get the following information:

    • The OCID of the compartment on which you want to create the tag default.

      $ oci iam compartment list --compartment-id-in-subtree true
    • The OCID of the tag key definition.

      $ oci iam tag list --tag-namespace-id tag_namespace_OCID
  2. Ensure that no more than four tag defaults already exist in this compartment.

    oci iam tag-default list --compartment-id compartment_OCID
  3. Run the tag default create command.

    Syntax:

    oci iam tag-default create --compartment-id compartment_OCID \
    --tag-definition-id tag_definition_OCID --value text

    Example:

    $ oci iam tag-default create --compartment-id ocid1.compartment.unique_ID \
    --tag-definition-id ocid1.tag.unique_ID --value 789

    Depending on your shell, you might need to escape the dollar symbol to specify a variable value:

    $ oci iam tag-default create --compartment-id ocid1.compartment.unique_ID \
    --tag-definition-id ocid1.tag.unique_ID --value "Assigned by: \${iam.principal.name}"

    This command returns the same output as the tag-default get command.

Updating the Value of a Tag Default

Using the Compute Web UI

  1. In the navigation menu, click Identity, and then click Compartments.

  2. If the compartment where you want to update a tag default is not listed, navigate to the correct compartment.

    Click the name of the top-level parent compartment and, on the compartment details page, scroll to the Child Compartments box. If necessary, click on the name of another compartment to view those child compartments.

  3. Click the name of the compartment that has the tag default whose value you want to change.

  4. In the Resources section of the compartment details page, click Tag Defaults.

  5. For the tag default that you want to change, click the Actions menu, and click the Edit option.

  6. In the Tag Defaults dialog, specify the type of value you want the tag default to have:

    • Default Value: Enter the value for this tag default. If the selected tag key has a defined list of values, then this Default Value must be a member of that list.

    • User-Defined Value: Users are required to enter the value when a resource is created. Selecting User-Defined Value is invalid if the selected tag key definition has a predefined list of values.

  7. Click Submit.

    The updated tag default is displayed on the compartment's details page.

Using the OCI CLI

  1. Get the OCID of the tag default that you want to modify.

    $ oci iam tag-default list --compartment-id compartment_OCID
  2. Run the tag default update command.

    Syntax:

    oci iam tag-default update --tag-default-id tag_default_OCID --value text

    This command returns the same output as the tag-default get command.

Deleting a Tag Default

When you delete a tag default from a compartment, existing occurrences of the tag are not removed from resources.

Using the Compute Web UI

  1. In the navigation menu, click Identity, and then click Compartments.

  2. If the compartment where you want to delete a tag default is not listed, navigate to the correct compartment.

    Click the name of the top-level parent compartment and, on the compartment details page, scroll to the Child Compartments box. If necessary, click on the name of another compartment to view those child compartments.

  3. Click the name of the compartment that has the tag default that you want to delete.

  4. In the Resources section of the compartment details page, click Tag Defaults.

  5. For the tag default that you want to delete, click the Actions menu, and click the Delete option.

  6. At the Delete Default Tag confirmation prompt, click Confirm.

    On the compartment details page, the state of the tag default is Deleting.

Using the OCI CLI

  1. Get the OCID of the tag default that you want to delete.

    $ oci iam tag-default list --compartment-id compartment_OCID
  2. Run the tag default delete command.

    Syntax:

    oci iam tag-default delete --tag-default-id tag_default_OCID

    Example:

    $ oci iam tag-default delete --tag-default-id ocid1.tag-default.unique_ID
    Are you sure you want to delete this resource? [y/N]: y

    To delete a tag default without confirmation, use the --force option.