LAB 32 ‐ Tags in OCI - DevWithNehaCloud/Oracle-Cloud-Infrastructure-wiki GitHub Wiki
OCI Tags
In Oracle Cloud Infrastructure (OCI), Tags are labels or metadata that you attach to cloud resources such as:
- Compute Instances
- VCNs
- Block Volumes
- Buckets
- Databases
Tags help organize, track, manage, and automate resources efficiently.
Why Tags are Used in OCI
Tags are mainly used for:
- Resource organization
- Cost tracking
- Automation
- Governance
- Access control
- Searching and filtering resources
Types of Tags in OCI
1. Defined Tags
Defined Tags are:
- Pre-created by administrators
- Organized inside a Tag Namespace
- Standardized and controlled
- Recommended for production environments
Example
Namespace
Operations
Tag Key
Environment
Tag Value
Production
Final Result
Operations.Environment = Production
Features of Defined Tags
- Standardized tagging structure
- Better governance and compliance
- Can enforce rules and policies
- Useful for billing and cost tracking
- Managed centrally by administrators
2. Free-form Tags
Free-form Tags are:
- Simple key-value pairs
- Created directly during resource creation
- Flexible and easy to use
- No namespace required
Example
Owner = Neha
Project = BankingApp
Features of Free-form Tags
- Quick and flexible
- Easy for testing and lab environments
- No administrative setup required
- Less governance and standardization
Difference Between Defined Tags and Free-form Tags
| Feature | Defined Tags | Free-form Tags |
|---|---|---|
| Namespace Required | Yes | No |
| Standardization | High | Low |
| Governance | Strong | Weak |
| Best For | Production Environment | Testing/Lab Environment |
| Admin Control | Yes | No |
| Cost Tracking | Better | Limited |
OCI Tagging Components
1. Tag Namespace
A namespace is a container for defined tags.
Examples
Finance
Operations
Security
2. Tag Key
The name of the tag.
Examples
Environment
CostCenter
Owner
3. Tag Value
The actual assigned value.
Examples
Production
HR
Neha
Common Real-World Use Cases
1. Cost Tracking
Used to track billing by department or project.
Example
Finance.CostCenter = HR
2. Environment Identification
Helps identify resource environments.
Example
Operations.Environment = Dev
Operations.Environment = Test
Operations.Environment = Prod
3. Ownership Tracking
Used to identify the resource owner.
Example
Owner = Neha
4. Automation
Automation scripts can:
- Start or stop instances
- Trigger backups
- Apply security policies
based on tags.
Example: Resource with Tags
Suppose a Compute Instance is created.
Defined Tag
Operations.Environment = Production
Free-form Tag
Owner = Neha
Important Notes
- Tags do NOT affect resource performance.
- Tags can be added during or after resource creation.
- Defined Tags require proper IAM permissions.
- Tags are very important in large organizations for governance and billing.
Advantages of Using Tags
- Better resource management
- Easier billing analysis
- Improved governance
- Easier automation
- Simplified searching and filtering
Short Interview Answer
OCI Tags are metadata labels attached to cloud resources for organization, cost tracking, automation, and governance. OCI provides two types of tags: Defined Tags and Free-form Tags. Defined Tags are namespace-based and standardized, while Free-form Tags are flexible key-value pairs.
Difference Between Tag Namespace and Tags
| Feature | Tag Namespace | Tags |
|---|---|---|
| Purpose | Container for tags | Metadata attached to resources |
| Level | Higher-level grouping | Actual tagging information |
| Contains | Multiple tags | Key-value pair |
| Used For | Organization and governance | Resource tracking and management |
| Example | Finance | Environment = Production |
Example
Tag Namespace
Operations
Tags
Environment = PROD
Owner = Neha
Final Result
Operations.Environment = PROD
Operations.Owner = Neha
Simple Understanding
- Tag Namespace = Folder
- Tags = Labels inside the folder
Short Interview Answer
A Tag Namespace is a container used to organize related tags, while Tags are key-value metadata labels attached to OCI resources for tracking, management, and cost monitoring.
Steps to Create Tag Namespaces
- Click on burger menu navigate to Governance & Administration and select the option Tag Namespaces
- Select the Create Tag Namespace option.
We are creating the tag namespace at the root compartment level because it is the highest level in OCI. From the root level, the tags can be accessed and assigned to resources in all child compartments.
- Fill in the required details and select the Create option.
Details
-
Name:
Enter the name for the Tag Namespace. -
Description:
Provide a meaningful description for the namespace. -
Compartment:
Usually, the Root Compartment (Tenancy) is selected.
Best Practice
It is recommended to create Tag Namespaces at the tenancy/root level so they can be used across all child compartments and resources.
The Tag Namespace name is typically chosen based on the organization, department, or project naming standard.
Steps to Create Tags
- Go inside the Tag namespace information and select the option create Tag Key Definition
- Fill the required details
- Now create one more tag by clicking on create Tag Key Definition
Steps to Attach Tags to OCI Resources
- Navigate to the compute-instances and click on the instance that you created then click on the Tags option then click on Add
- Select the namespace tag key and value which you have created and click on Add tags
Now you can see that this instance has been tagged under the Prod team and with the owner name Neha. In the future, if we need to perform cost tracking or identify services created by owner Neha, we can easily filter and track those resources using tags.
Now let's attach tags to another OCI service called Block Volume.
Now the Block Volume has also been tagged with the application owner details, where the owner name is set to Mallory. Using these tags, we can easily filter and identify resources associated with the owner, perform cost tracking, and manage related services more efficiently.
Difference Between Static Value and List of Values in OCI Tag Value Type
In Oracle Cloud Infrastructure (OCI) Defined Tags, the Tag Value Type determines how values can be assigned to a tag.
OCI provides two options:
- Static Value
- List of Values
1. Static Value
In Static Value, users can manually enter any custom value while assigning the tag.
It provides flexibility because the value is not restricted.
Example
Suppose the tag key is:
Owner
While attaching the tag, users can enter any value such as:
Neha
Rahul
Amit
FinanceTeam
Use Cases of Static Value
Static Value is useful when:
- Values can frequently change
- Custom input is required
- No strict standardization is needed
Examples
- Owner names
- Project names
- Ticket numbers
- Application IDs
Advantages
- Flexible
- Easy to use
- No predefined list required
Disadvantages
- Users may enter inconsistent values
- Difficult to maintain standardization
Example Problem
Prod
production
PROD
All may represent the same thing but are treated differently.
2. List of Values
In List of Values, administrators predefine allowed values, and users can only select from that list.
This helps maintain consistency and governance.
Example
Suppose the tag key is:
Environment
Allowed values are predefined as:
UAT
PROD
DEV
TEST
Now users can only choose one of these values while tagging resources.
Use Cases of List of Values
List of Values is useful when:
- Standardization is important
- Governance is required
- Only approved values should be used
Examples
- Environment names
- Department names
- Cost centers
- Compliance classifications
Advantages
- Better consistency
- Easier filtering and reporting
- Improved governance
- Better cost tracking accuracy
Disadvantages
- Less flexibility
- Admin must update the list when new values are needed
Key Difference Between Static Value and List of Values
| Feature | Static Value | List of Values |
|---|---|---|
| Value Entry | User enters any value | User selects from predefined values |
| Flexibility | High | Limited |
| Standardization | Low | High |
| Governance | Weak | Strong |
| Best For | Dynamic/custom data | Controlled environments |
Your Example
You selected List of Values and added:
UAT
PROD
DEV
TEST
This is the best approach for environment tagging because:
- Everyone uses the same standard values
- No spelling variations occur
- Cost tracking and filtering become easier
- Reporting becomes more accurate
Real-World Example
Suppose your organization has multiple environments:
DEV
TEST
UAT
PROD
If users manually type values using Static Value, they may enter:
prod
PROD
Production
production
This creates inconsistency during:
- Cost tracking
- Reporting
- Filtering
- Automation
Using List of Values avoids this issue because users can only select approved values.
Best Practice
-
Use List of Values for:
- Environment
- Department
- Cost Center
- Compliance Type
-
Use Static Value for:
- Owner Name
- Project ID
- Application Name
- Dynamic custom values
Short Interview Answer
In OCI Tags, Static Value allows users to enter any custom value, while List of Values restricts users to predefined values only. Static Value provides flexibility, whereas List of Values provides better standardization, governance, and consistency.