# Tag Mapping Rules

Usage in the Cloud has both a fundamental bug and a fundamental feature, in that tags are historical in nature. If I tag a VM today with Environment:Production, the usage for that VM will only be tagged today onwards that way. This is a feature as I might want to say today the VM belongs to CostCentre:Accounting, and tomorrow it might be CostCentre:Development (e.g.) - but it's also a bug as my historical spend will be untagged if I only just started tagging.

Most organizations don't get their tags right the first time, that's really difficult to do and expecting that doesn't reflect the changing nature of businesses costs. Tag Mapping fixes this.

# What Tag Mappings Do

  • Transform incoming usage records before they land in the tenant.
  • Rules run top-to-bottom, one record at a time; later rules can be skipped if a rule sets "stop processing".
  • Changes apply on the next scheduled import or re-ingest.

# Common Use Cases

  1. Normalize environment keys and values

    • Match Tag Key/Value where env is Prd, Production, or Prod.
    • Add Tag Environment=Production to standardize both key and value.
  2. Derive environment from resource naming

    • If Service Name starts with prd- (prd-%%), treat it as production.
    • Add Tag Environment=Production so naming conventions become tags.
  3. Backfill empty cost centers

    • If Tag Key Value CostCentre is (Blanks), treat it as unassigned.
    • Add Tag CostCentre=IT as a prompt to fix ownership.

# Where to Configure

  • Navigate to SettingsTag Mappings.
  • Each rule is shown as an expansion card with its name, active toggle, move up/down controls, and delete.

# Rule Anatomy

  • Name & Description: shown on the card header; rename inline.
  • Active toggle: enables/disables the rule without deleting it.
  • Order: move up/down to control evaluation sequence.
  • Stop processing: option inside the form to halt further rules when this one matches.
  • Conditions (IF / AND): all must be true for the rule to run.
  • Actions (THEN / AND): executed in the displayed order when conditions pass.

# Supported Conditions

  • Source Row Field (case-insensitive or sensitive): match a raw usage field (e.g., ResourceName, Meter, Service) against one or more values.
  • Tag Key Value (case-insensitive or sensitive): match an existing tag key/value.
  • Subscription Name (case-insensitive or sensitive): match the subscription on the row.
  • Cloud Account Name (case-insensitive or sensitive): match the cloud account on the row.
  • Markers supported in value lists:
    • * matches anything.
    • (Blanks) matches empty/missing values.
    • %%text%% contains, text%% starts with, %%text ends with.

# Supported Actions

  • Add Tag: write or overwrite a tag key with a value.
  • Copy Value: copy an existing tag's value into another tag key.
  • Remove Tag: delete a tag key if present.
  • Markup Cost: apply a numeric markup to cost on matching rows.

Actions execute in the order shown; use the arrow controls to reorder.

# Creating a New Rule

  1. Click Add new mapping here at the bottom of the list.
  2. Give the rule a name.
  3. Add one or more conditions (IF/AND).
  4. Add one or more actions (THEN/AND) and order them.
  5. (Optional) Enable Stop applying other mapping rules if conditions met to short-circuit.
  6. Submit to save.

# Editing an Existing Rule

  • Expand the rule card, update conditions/actions, reorder as needed, and submit.
  • Toggle Active to disable without deleting.
  • Use move up/down to change precedence; reorder is saved immediately.

# Execution Notes

  • All conditions are ANDed.
  • If "stop processing" is checked, later rules are skipped for that row.
  • Changes are applied on next ingestion; existing historical data is unchanged unless reprocessed.

# Tips & Patterns

  • Use (Blanks) to branch when data or tags are missing.
  • Use * with other specific conditions to create guarded defaults.
  • Copy + Add: copy a tag to a standard key, then overwrite with Add Tag if you need a fallback value.
  • Keep run order unique/intentional for deterministic results.

# Troubleshooting

  • Rule not firing: confirm it is active, ordered before conflicting rules, and that conditions use the correct field/tag names and markers.
  • No changes visible: ensure an import has run after edits.
  • Validation: inputs must have at least one condition and one action; required fields must be filled.