Thursday, May 7, 2020

Adding Tag Defaults to OCI Resources.

6:36 AM Posted by Dilli Raj Maharjan 2 comments

Tag defaults let us specify tags to be applied automatically to all resources at the time of creation in a specific compartment. This feature allows us to ensure that appropriate tags are applied at resource creation without requiring the user who is creating the resource to have access to the tag namespaces. 
Following is an example where I have created Tag Namespace Resources with Tag Key Defination Owner. I have created Tag Default with default value ${iam.principal.name} at ${oci.datetime} which is IAM user who created the resource and date time. The final output of default tag in resource looks something like 99593080-lab.user01 at 2020-05-03T10:10:37.244Z, OCI IAM username and timestamp respectively.

Default tag comprise of 2 steps: Creating Namespace tags and assigning Default tags.

Following are the steps to create tag namespace.


Click on Navigation menu aka buger menu and click on Governance and Tag Namespace.




Click on Create Namespace Definition to create Namespace defination.


Choose the compartment, type Namespace Definition Name and its Description. In my case I have used Resources are the Namespace definition name and Namespace for OCI resources as the description. Click on Create Namespace Definition to continue.



Once Namespace Definition is created it looks something like below. Click on Namespace Definition to create Tag Key Definition.


Click on Create Tag Key Definition to add Tag Key Definition.

Provide Tag Key value and its description. In my case Owner is tag key and Owner of namespace is description I have used for tag key. I have left default value of STATIC VALUE for Tag Value type. If I have selected A LIST OF VALUES option I can provide a list of fixed value that will be displayed as drop down list values. Click on Create Tag Key Definition.



Once Tag namespace and tag key definition are created next step is to select the compartment and add Default tag.


Click on Navigation menu aka hamberger menu. Click on Identity and compartments.



Select approprite compartment and click on compartment name to add Default tags.



Under Resources section at left hand size click on Tag Defaults.


Click on Create Tag Default.


Provide Tag Namespace, Tag key and Default value. We can use static user-applied value instead of tag variable values. Click on Create to create Default tag.



Once Tag Defaults is created it looks something like below.


After creating Tag Defaults now we can create instance on the compartment for test. Once Instance is fully provisioned we can see the tag value assigned automatically.


Create Instance in the compartment where we have added Default Tags.



Provisioning in progress... Click on Tags tab to view tag details.



Once we click on Tags now we can see tag Resources.Owner has value as 99593080-lab.user01 at 2020-05-03T10:10:37.244Z



Following are the tag variables we can use with tag defaults.
${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. 

2 comments: