skyscrapr / terraform-provider-cloudability

Cloudability provider for Hashicorp Terraform
MIT License
8 stars 6 forks source link

New Business metric cannot be created through terraform #36

Closed prabha11-sys closed 1 year ago

prabha11-sys commented 1 year ago

Hello @skyscrapr, Receive the below error while trying to create a new business metric. Even though terraform throws the error, the business metric was actually created in Cloudability.

Below is the resource in terraform config,

resource "cloudability_business_metric" "RI_Waste" { name = "RI Waste" number_format = "currency" default_value_expression = "0" statement { match_expression = "DIMENSION['lease_type'] == 'Reserved' && DIMENSION['transaction_type'] == 'Recurring Charge''" value_expression = "METRIC['total_amortized_cost']" } lifecycle { ignore_changes = [ default_value_expression, default_value ] } }

Error from terraform apply:

cloudability_business_metric.RI_Waste: Creating...

╷ │ Error: {"error":{"status":400,"code":"bad_request","messages":["error in statement #1, matchExpression: syntax error at column 94"],"uniqueid":"89f9b614-3281-11ee-bb72-5200f8ca778a","typeid":"97b7c4f9c7bd727965fa3d331860ca66","traceid":"89f46dc6-3281-11ee-bb72-5200f8ca778a","service":"Collections"}} │ │ │ with cloudability_business_metric.RI_Waste, │ on business_metric.tf line 43, in resource "cloudability_business_metric" "RI_Waste": │ 43: resource "cloudability_business_metric" "RI_Waste" {

skyscrapr commented 1 year ago

I'll try to take a deeper look at business metrics later this weekend.

It would be great if you can open a ticket with cloudability as the behaviour used in the APi is not ideal.

skyscrapr commented 1 year ago

Hi @prabha11-sys

it looks like this is simply due to a typo. The error is accurate. character 94 in the match_expression is a duplicate '. If i remove that extra "'", i can successfully create the business metric.

skyscrapr commented 1 year ago

Actually before I close the issue, can you confirm that this works for you? I don't think the metric should be created if the error is displayed. Let me know and I'll close the issue.

skyscrapr commented 1 year ago

Hi @prabha11-sys

I looks like Cloudability has modified the behaviour of the API to fix some of the quirks with setting default value on business metrics. Or possibly they have tidied up the documentation to remove ambiguity.

It looks like they have moved to using default_value_expression on the business metrics and no longer also using default_value. This simplifies things and I'll make this change. However this might break your existing configs. I think it' best to make this change though. So hopefully not too painful.

I'll update and close the issues with business metrics once released. This will also prvent the need to use lifecycle blocks to ignore changes.

skyscrapr commented 1 year ago

Fixed in v0.0.34

skyscrapr commented 1 year ago

@prabha11-sys Please test and let me know if this new version is working for you. I think Cloudability has changed the behaviour for the better.

You will no longer need the lifecycle block in your configuration. You will just use default_value_expression and not default_value.

This feature is still in preview so I expect things might change in the next few releases.