When to Use FinOps as Code
The console and code are complements, not competitors. The console is built for exploration and answering questions quickly. Code is built for configuration that has to stay correct over time. Most organizations build something in the console first, then promote it to code once it becomes part of a regular process. (This particular pattern is shown in Use Case 5.) Use code when a configuration is:- Shared: Cost Reports, Folders, and Dashboards that multiple teams rely on for recurring reviews.
- Durable: Anything that should persist beyond the person who created it and remain intact through team changes.
- Sensitive: Allocation logic like Virtual Tags and Billing Rules that reclassifies historical cost and feeds chargeback. These changes deserve a reviewed diff.
- Repeated: Work you do the same way every time, like onboarding a new team. Doing it once by hand is fine, but doing it for the fifteenth team is not.
- Subject to review or audit: When you need a record of who changed what, when, and why.
- Created at scale: Hundreds of teams, accounts, or tag values that are tedious and error-prone to click through.
- Exploratory: Ad-hoc cost questions, one-off investigations, and “what is driving this?” analysis.
- A one-off: A report you need once and will not maintain.
- A learning exercise: Trying a feature to understand how it behaves before committing to a pattern.
Prerequisites
- A Vantage account with at least one connected provider.
- The Vantage Terraform provider configured with a Read/Write API token. If you do not use Terraform, you can manage the same resources through the corresponding Vantage API endpoints.
- A Git repo with a Terraform workflow your team already uses for plan and apply.
Use Cases
Each use case below follows the same shape: a source of truth your organization already maintains, such as a CSV of teams, a YAML org chart, or an export from your identity provider that drives the Vantage configuration. AI drafts the change, you review the plan, and code applies it. This keeps the business logic in one place and scales from five teams to five hundred without changing the workflow.Onboard a New Team
Generate Virtual Tags
Layered Allocation
Durable Reports
Import from Console
Version and Roll Back
Use Case 1: Onboard a New Team
Every time a new team starts up, you need the same handful of Vantage resources: a folder to organize their reports, a Cost Report filtered to their accounts, a team with an access grant so they can see their data, and a budget to track spend. Keep the team definitions in one file, and let Terraform create every resource from it.Using our existing Vantage Terraform patterns, generate only the HCL to onboard the teams in teams.yaml. For each team, create a folder, a Cost Report filtered to its AWS accounts, a team, an access grant to its folder, and a monthly budget. Iterate over the file with for_each. Do not create new modules or change existing resources. Return only the diff and your assumptions.
for_each:
teams.yaml and re-run terraform plan. Because every resource is keyed by team name with for_each, Terraform creates only the new team’s resources and leaves the existing teams untouched. The plan shows additions, not a rebuild.
vantage_budget periods take a start_at and amount; end_at is optional. Add one period per month, or generate periods, to cover the full budget window. Validate generated code against the provider docs before applying.Use Case 2: Generate Virtual Tags from a Source-of-Truth File
Allocation is where code review matters most. A Virtual Tag change can reclassify months of historical cost across every report that groups by that tag. The most maintainable pattern is to keep the mapping that defines the tag, such as teams, accounts, or namespaces, in a file your organization already owns, and generate the tag values from it. The file is the system of record.terraform plan recomputes the tag whenever it changes. Start with the list of teams your organization already maintains:
team Virtual Tag that normalizes the AWS team tag and the Kubernetes organization/team label into a single dimension. Terraform reads the CSV and produces one value per team.
Using the Vantage Terraform provider, write a vantage_virtual_tag_config that reads teams.csv (one team per row) and creates a cross-provider "team" Virtual Tag. For each team, generate a value whose VQL matches the AWS tag "team" and the Kubernetes label "organization/team" with that team's name. Return only the HCL.
backfill_until date, verify the tag keys match what your providers actually emit, and keep allocation changes in their own PR. Do not bury them alongside unrelated report updates. Because each value adds processing work, review the Scaling Virtual Tags guide before generating tags with hundreds of values, and see tagging examples for more filter patterns.
Use Case 3: Layered Allocation for Chargeback
Large organizations rarely get a clean allocation dimension from a single source. A team or product name might come from a manually maintained override, a Kubernetes namespace, a provider tag, or a Business Metric, and you need one canonical value with a clear order of precedence. You can build this entirely from Virtual Tags: define a few narrow source tags, then merge them into one standardized key using tag key collapsing, where the first source in the list that has a value wins. First, define the source tags. Each one captures a single way ateam value can be derived. Keep them narrow and independent.
{ key = "team" } entry is the native provider tag key, not another vantage_virtual_tag_config resource.
team dimension you can group and filter by across providers, with deterministic precedence.
Use Case 4: Turn an Investigation into a Durable Report
Someone from finance asks why data transfer costs jumped last month. You dig into it with the FinOps Agent or a Vantage MCP client and find the answer. Then the thread disappears into chat history and the same question comes back next month. If a question is going to recur, turn the answer into a Terraform-managed Cost Report.Investigate
Draft the report definition
Based on this cost investigation, write a Vantage VQL filter and suggested groupings for a Cost Report that tracks these costs going forward. Explain your assumptions and return only the filter and groupings; do not create the report.
Commit the report
Wire it into a review cadence
Use Case 5: Import Console Resources into Terraform
You do not need to start from scratch. Many teams build their initial reporting structure in the console and only move to Terraform once a resource becomes part of a standing process. Examples include a chargeback report that runs monthly, a Virtual Tag that feeds executive Dashboards, or a team structure that needs to stay in sync with your identity provider.Get the resource token
rprt_1abc23456c7c8a90) or query the API or a Terraform data source.Define the resource in Terraform
Import
Reconcile the plan
terraform plan. The first plan will likely show differences between your HCL and the live resource. Update the configuration until the plan is clean. If the diff is confusing, paste it into your AI assistant:Here is the terraform plan output for a Vantage resource I just imported. Explain which fields are computed defaults I can ignore and which are real differences I need to set in my configuration to make the plan clean.
Use Case 6: Version and Roll Back Allocation Config
Your allocation logic—the Virtual Tags that drive showback and chargeback—is some of the most valuable configuration in Vantage, and the most tedious to reconstruct by hand if a change does not work out. When it lives in code and Git, every version is saved automatically: you can see exactly what changed between any two points in time and return to a known-good version without rebuilding it from memory. This is the payoff of importing your resources. Once a Virtual Tag is defined in code, Git becomes its version history. You do not have to hand-write the starting configuration. List your Virtual Tag tokens (from the console URL or thevantage_virtual_tag_configs data source), write a Terraform import block for each one, and let Terraform generate the HCL for you.
import blocks and terraform plan -generate-config-out require Terraform 1.5 or later.virtual_tags.tf. Reconcile the generated configuration until the plan is clean, then run terraform apply to complete the import into state. Commit virtual_tags.tf after the import is complete. It is now your baseline version, and the manual work of capturing the existing setup is done once and never again.
From here, every change to allocation goes through a pull request, so Git records what changed, when, and why.
Change in a branch
terraform plan in the PR shows the exact before and after of the allocation change.Tag a release (optional)
vtags-2026-06-01) so you have named versions to return to.Roll back when needed
Using AI Effectively
AI is what makes FinOps as Code fast: it reads your source files, drafts the HCL, and explains its reasoning so that you spend your time reviewing a diff instead of writing boilerplate. To get accurate output:- Give it the source of truth and the patterns: Point the assistant at your CSV/YAML file and an existing resource in your repo so generated code matches your conventions.
- Ask for a diff and assumptions, not actions: Have AI return only the HCL changes and the assumptions it made. Keep it from creating or modifying resources directly.
- Make it validate against the provider docs: Ask the assistant to check generated code against the Vantage provider docs on the Terraform Registry. Schemas change (e.g.,
vantage_budgetusesperiods,vantage_dashboarduseswidgets) and a stale example will not apply cleanly. - Let the plan be the proof: A clean
terraform planis the real test. If the plan is noisy or fails, feed it back to the assistant and ask it to reconcile.
Guardrails
These are worth writing into your team’s operating agreement, not just this guide:- AI never runs
terraform apply. A human reviews the plan and merges the PR. - Every PR that touches Vantage resources includes a
terraform planoutput. - Allocation changes (Virtual Tags, Billing Rules) go in their own PRs, separate from reporting or access changes. These affect historical cost data and should be reviewed with that in mind.
- VQL filters get a dedicated review check. A wrong
costs.account_idor missingtags.valueis the most common source of bad reports.
Frequently Asked Questions
Can I use the console and code at the same time?
Can I use the console and code at the same time?
What happens if someone edits a code-managed resource in the console?
What happens if someone edits a code-managed resource in the console?
terraform plan will show a diff between your HCL and the live resource, and terraform apply will revert the console change to match the code. Treat the plan as a drift detector: if you see unexpected changes, someone edited the resource outside of code. For resources you want to manage in code, make code the only place they are changed.How should I handle API tokens and Terraform state?
How should I handle API tokens and Terraform state?
.terraform/ and local state files out of version control.Do allocation changes reprocess historical cost data?
Do allocation changes reprocess historical cost data?
Which resources can I manage as code?
Which resources can I manage as code?
References
- Product Documentation
- Tutorials and Examples