Hello all! Is there a way to get cost for Persiste...
# help
q
Hello all! Is there a way to get cost for Persistent Disk in GCP, with Cloud Pricing API? Thanks
s
Hi Stefano, I'm afraid not easily, you’d have to replicate the logic in the infracost CLI to lookup the prices and then do the cost calculations based on the size of the disk etc. You can follow the code thread from https://github.com/infracost/infracost/tree/master/internal/resources > google > resources > compute_disk.go and keep following the computeDiskCostComponent function to see how that’s calculating the cost using the pricing API filters
q
Hi Drew, thank you for the tip. I built a query that gives me almost all the information I need:
Copy code
query {
  products(
    filter: {
      vendorName: "gcp"
      service: "Compute Engine"
      productFamily:"Storage"
      region: "us-east1"
      attributeFilters:[{
        key:"description"
        value_regex: "/d*/g"
      }]
    }
  )
  { 
    productFamily
    vendorName
    prices { EUR } 
    attributes {
      key
      value
    }
  } 
}
s
That's what you filter in the attribute regex. The key values examples are above in the code: https://github.com/infracost/infracost/blob/master/internal/resources/google/compute_cost_component_helpers.go#L324-L336 So for example, if the disk type you're looking for the price on is a balanced PD, you do:
Copy code
query {
  products(
    filter: {
      vendorName: "gcp"
      service: "Compute Engine"
      productFamily:"Storage"
      region: "us-east1"
      attributeFilters:[{
        key:"description"
        value_regex: "/^Balanced PD Capacity/g"
      }]
    }
  )
  { 
    productFamily
    vendorName
    prices { EUR } 
    attributes {
      key
      value
    }
  } 
}
And then get back:
Copy code
{
  "data": {
    "products": [
      {
        "productFamily": "Storage",
        "vendorName": "gcp",
        "prices": [
          {
            "EUR": "0.09595"
          }
        ],
        "attributes": [
          {
            "key": "description",
            "value": "Balanced PD Capacity"
          },
          {
            "key": "resourceGroup",
            "value": "SSD"
          }
        ]
      }
    ]
  }
}