- Vantage Terraform Integrations module for AWS: The Vantage Terraform Integrations module is available for registered users, across all Vantage tiers, to create the primitives needed to broker a connection with AWS. With the module, you can create a Cross-Account IAM Role as well as a Cost and Usage Report (CUR).
- Vantage Terraform provider: The Terraform provider comprises several Vantage resources you can create, such as Cost Reports, dashboards, etc. Use the provider to automate and manage Vantage from within your existing Terraform codebase. Organizations with IaC practices can set up, create, and sync their cost reporting structure with Vantage.
Vantage Terraform Integrations Module for AWS
Use the Vantage Integrations module to link your AWS and Vantage accounts. Organizations can use the module to integrate thousands of AWS accounts with Vantage. You can view the source of the module on the module’s GitHub repository:- Module file:
main.tf
- Variables for module:
variables.tf
For root AWS accounts, you need to provision a bucket for the Cost and Usage Report (CUR) using the
cur_bucket_name
variable. For sub-accounts, you need to link access, but you don’t need to configure a CUR bucket.cur_bucket_name
variable is not included within the module configuration. As a result, an IAM Role is created, which Vantage can assume to ingest the cost and resource metadata that are displayed within the Vantage console. See the Terraform documentation for more details.
Vantage Resources and Data Sources
Using the Terraform provider, you can automate Vantage resources, such as Cost Reports, via the Vantage Write API—or the backbone of the provider. With the Terraform provider, you can create many resources, like Cost Reports, report notifications, folders, dashboards, etc. The provider also includes many data sources you can use to pull data from the Vantage console. See the documentation for details. By using these Terraform resources, engineering teams automate cost reporting in Vantage. Below are some example use cases.- Build Cost Reports for hundreds of teams stored in another source of truth (e.g., database or GitHub)
- Update filters as resource names or tags change
- Add new reports to team dashboards when new services are deployed
- Create teams and access grants based on teams within an identity provider (IdP)
The ability to create, edit, and destroy resources is keyed to the permissions of the user associated with the API token. For Enterprise customers, role-based access controls also affect these actions. Review the documentation on RBAC for further information.
Terraform Import
terraform import
is a command used in Terraform that allows you to bring existing infrastructure resources into Terraform management. This command helps integrate resources that were created outside of Terraform—such as those provisioned directly in the Vantage console or API—into Terraform’s state file. For example, if you initially set up your cost reporting resources through the Vantage console, you can use this command to import these resources into your Terraform state, which allows you to maintain a single source of truth for your infrastructure.
To use terraform import
, run the following command:
vantage_cost_report.demo_report
: The type of infrastructure component managed by Terraform (e.g.,vantage_cost_report
); followed by a user-defined identifier assigned to a resource in your Terraform configuration.rprt_1abc23456c7c8a90
: Example of a Cost Reporttoken
. This can be found in the URL for a report within the console or via the API.
Terraform Examples
Before you begin, ensure you have a valid Write API token.Create a Cost Report
The following example describes how to create a Cost Report for AWS using Terraform.1
First, declare the Vantage provider.
You can optionally save your API token as an environment variable and remove the
provider "vantage"{...}
block. Export your token with: export VANTAGE_API_TOKEN=<YOUR_API_TOKEN>
.2
Create the
vantage_folder
resource, with “AWS Costs” as the title.3
Create the
vantage_cost_report
resource using the token output from the vantage_folder
resource. The Cost Report will be stored in the newly created AWS folder. The Cost Report’s title is “AWS Costs.” In addition, the vantage_saved_filter
resource includes a filter
parameter that uses Vantage Query Language (VQL), a SQL-like language for querying cloud cost and usage data. Here, the filter is set to show only AWS costs. Set the groupings
parameter to have the report grouped by region and service.Valid groupings include:
account_id
, billing_account_id
, charge_type
, cost_category
, cost_subcategory
, provider
, region
, resource_id
, service
, tag:<tag_value>
. Enter multiple groupings as comma-separated values: groupings=provider,service,region
.Using Multiple Vantage Terraform Resources
In the following example, we will create a filter, report, and folder to track database costs. This example assumes you’ve already declared the appropriate providers.1
First, create an RDS instance using the
aws_db_instance
resource from the AWS provider. Then, create a saved filter using the output of the arn
from the RDS instance as part of the filter criteria.2
Then, create a folder to keep your RDS Cost Reports organized.
3
Finally, use the tokens that are output from the saved filter and folder as input to create a new Cost Report.
terraform-provider-vantage
GitHub repository.
Use terraform import
to Manage External Resources
In the following example, you created a Cost Report in the Vantage console. You want to update the filter on this Cost Report to pull data for different RDS instances, and you want to do this automatically using Terraform. To update data on a resource made outside Terraform, you need to use the terraform import
command.
1
First, obtain the
token
for this Cost Report. You can access this token
using one of the following methods:- If you are viewing the report in the Vantage console, copy the report’s
token
from the end of the URL (e.g., inhttps://console.vantage.sh/reports/rprt_123a47b5ba1234e1
, copyrprt_123a47b5ba1234e1
). - You can access a list of your reports from the
/cost_reports
Vantage API endpoint. Thetoken
is one of the values returned in the response. - Use the
vantage_cost_reports
Terraform data source. You can call the data source and create an output value to access a list of Cost Reports.
2
Ensure the
vantage_cost_report
Terraform resource that you want to update is defined in the configuration. Below it is defined with the current parameters.3
At this point, Terraform is aware of the resource, but it doesn’t manage it yet because the Cost Report was created outside of Terraform, in the Vantage console. To bring the external resource under Terraform’s control, you need to import it using the For example, if your Cost Report token is
terraform import
command. Replace the placeholder <token>
with the token
you just obtained for the Cost Report.rprt_123a47b5ba1234e1
, run the following command:4
After importing the resource, you can modify its attributes in your Terraform configuration. In this example, you can adjust the ARNs in the
filter
parameter to reflect two different RDS instances.5
Finally, apply the changes to your configuration:Terraform will detect the new filter and update the external resource accordingly. You can see this reflected in the Vantage console.