Hi everyone. Is there a way to peek at the GraphQL...
# help
a
Hi everyone. Is there a way to peek at the GraphQL query generated by
infracost
? Our team doesn't use Terraform, but I'm interested in the
Cloud Pricing API
server. I'm looking to dynamically construct a GraphQL query to submit to a self-hosted
Cloud Pricing
server, and I'm looking to see how
infracost breakdown
works. Taking this Terraform example:
Copy code
$ cat <http://ec2_simple.tf|ec2_simple.tf>
resources "aws_instance" "my-web-service" {
  instance_type = "t2.micro"
}
Running
infracost breakdown -p .
gives us:
OVERALL TOTAL $9.27
. I'm looking to see what the GraphQL query looks like in this simple example, then to construct larger Terraform files to see how the query changes.
l
@able-pencil-95187 there’s not an easy way yet to go from the Infracost CLI to the raw pricing API calls. At the moment, you really have to look through the code for each resource and look at the values we pass. Here’s an example of the EC2 compute values in the code which would map to the a GraphQL query like the following:
Copy code
query {
  compute: products(filter: {
    vendorName: "aws",
    service: "AmazonEC2"
    region: "us-east-1"
    productFamily: "Compute Instance"
    attributeFilters: [
      {key: "instanceType", value: "t2.micro"}
      {key: "tenancy", value: "Shared"}
      {key: "operatingSystem", value: "Linux"}
      {key: "preInstalledSw", value: "NA"}
      {key: "licenseModel", value: "No License required"}
      {key: "capacitystatus", value: "Used"}
    ]
  }) {
    attributes {
      key, value
    }
    prices(filter: {
      purchaseOption: "on_demand"
    }) {
      USD
    }
  }
}
There’s also some docs here with an example request.
a
look through the code for each resource and look at the values we pass
@little-author-61621 can you link the directory for the resources? I might be able to extrapolate a lot
so the simple EC2 example I pasted will become constructed into the above gql query?
l
https://github.com/infracost/infracost/tree/master/internal/resources That example I pasted is just the EC2 compute cost, but depending on what you need, you might also need other costs (root volume storage/IOPS, compute credits, EBS optimized costs). These are also in that same resource file.