Hello, just a quick question. :slightly_smiling_fa...
# help
r
Hello, just a quick question. 🙂 Is there any way how to write comments to
infracost-usage.yml
without them being erased with the next
--sync-usage-file
? My intention is to write helpful comments for the rest of team why some usage param was chosen how it was chosen. E.g.
Copy code
azurerm_monitor_action_group.default:
    monthly_notifications: 90 # 1 notification per every day per every environment
Now it seems that some comments get persisted (when there was a generic comment on the line generated before), but others get erased. Is there some special comment syntax to instruct the sync functionality to ignore that particular comments and leave them in the file? Or some other way how to achieve what I'm trying to achieve? 🙂
b
Hello! I've just tested this on our [example](https://github.com/infracost/infracost/blob/master/examples/terraform/infracost-usage.yml#L8-L9), it kept the comments (although adding a bunch of commented out stuff too). Could you please show what was before the sync and after so I can try to reproduce it?
For reference, I had
Copy code
version: 0.1
resource_usage:
  aws_lambda_function.hello_world:
    monthly_requests: 100000000 # Foobar
    request_duration_ms: 250  # Bar foo
    foobar: 111 # test
and I got
Copy code
resource_usage:
  aws_lambda_function.hello_world:
    monthly_requests: 0 # Foobar
    request_duration_ms: 0 # Bar foo
    foobar: 111 # test
Can it be that your TF code doesn't have
azurerm_monitor_action_group.default
resource? If a resource from the usage file is not found, it is deleted. If you want to specify a "default" usage for all resources of the same type, you can use a separate block:
Copy code
resource_type_default_usage:
  azurerm_monitor_action_group:
    monthly_notifications: 90 # 1 notification per every day per every environment
r
Thank you for your response @busy-agent-35515! Sorry, I wasn't clear enough. In some cases it keeps the comment (my example is the case of it working OK). Cases that don't work:
Copy code
version: 0.1
resource_type_default_usage:
  # We set storage account usage globally as it's really cheap and we don't mind slight differences
  azurerm_storage_account:
    ...
☝️ comment gets deleted
Copy code
version: 0.1
resource_type_default_usage:
  azurerm_storage_account: # We set storage account usage globally as it's really cheap and we don't mind slight differences
    ...
☝️ comment gets deleted
Copy code
version: 0.1
resource_type_default_usage:
  azurerm_storage_account:
    data_at_rest_storage_gb: 0.0
☝️ here I deleted the comment as it seems unnecessary to me but it gets re-added (frankly, most of the comments for Azure seem obvious to me as they just copy the name of the property so I'd be nice for me to have the ability of removing all of the comments and only keeping my comments so they "stand out" 🙂)
b
Ah, I see what you mean, thank you for the examples! Indeed, the sync flag overrides the content of the file disregarding any additional comments/attributes. I must say this flag is still experimental, so it surely can be improved. Unfortunately, there is no a workaround just now apart from not using the
--sync-usage-file
flag 😕 One of the possible solutions might be adding an additional flag like
--keep-comments
or something to adjust the generator behavior, but we'd need to implement it. May I ask you to create a new issue here so other community members can see it and upvote it and you can follow the status? If there is interest to this problem we may prioritize it, or maybe somebody can contribute too. https://github.com/infracost/infracost/issues
r
Will do, thank you! ❤️