idea: add support for warnings
We have began using terraform checks to create warnings in our plan which would become failures in an apply. This allows the plan to finish entirely and not fail on the first error.
These warnings show up at the bottom of the plan file. Below is an example of the human readable output when these warning are present.
The enhancement idea is adding a feature that clearly indicates the presence of warnings within the plan comment and potentially retrieving the warnings into their own dedicated section for easier identification.
Plan: 2 to add, 0 to change, 0 to destroy.
╷
│ Warning: cannot read schema: cannot read data schema: Schema 'dev_default.test_bad' does not exist.
│
│ with module.analytics_structured_external_location["app"].data.databricks_schema.this,
│ on ../../../../modules/databricks/external_location/main.tf line 95, in check "volume_schema":
│ 95: data "databricks_schema" "this" {
│
╵
╷
│ Warning: cannot read schema: cannot read data schema: Schema 'dev_default.test_bad' does not exist.
│
│ with module.analytics_structured_external_location["dms"].data.databricks_schema.this,
│ on ../../../../modules/databricks/external_location/main.tf line 95, in check "volume_schema":
│ 95: data "databricks_schema" "this" {
│
╵
─────────────────────────────────────────────────────────────────────────────
Saved the plan to: plan.tfplan
To perform exactly these actions, run the following command to apply:
terraform apply "plan.tfplan"
I would be interested in contributing to this feature. However, I am not proficient in TypeScript. I looked through the codebase and am not sure where to start. As a DE, I have a decent grasp of Python, so I'm not starting from scratch. If others would find this idea helpful and might be able to make a quick enhancement, or point me in the right direction, I would truly appreciate it.
I think this would be a great addition! I personally haven't worked with TF checks yet but this seems very much in scope of this action :)
I would be interested in contributing to this feature.
That sounds great! ;) I wouldn't worry about TypeScript so much, you'll get the hang of it when knowing where to look and trying to solve a particular issue :smile:
Some pointers:
- Here we define the schema of the
planfile.jsonor, rather, the "sub-schema" that we're interested in. Likely, you'll have to extend this such that we can parse warnings from the JSON file https://github.com/borchero/terraform-plan-comment/blob/3399d8dbae8b05185e815e02361ede2949cd99c4/src/planfile.ts#L4 - Here we have the structure which stores the data about the sections of the final comment. I guess you'd need to add a new section for the warnings here https://github.com/borchero/terraform-plan-comment/blob/3399d8dbae8b05185e815e02361ede2949cd99c4/src/render.ts#L5
- Now comes the more interesting part. Here, we parse the contents of the "stdout plan" (i.e. not the JSON plan) for a particular resource. You'd probably need to add another dedicated function that parses warnings (conceptually similar to this one) https://github.com/borchero/terraform-plan-comment/blob/3399d8dbae8b05185e815e02361ede2949cd99c4/src/render.ts#L26
- Here you plug everything together: the structured info extracted from the JSON plan and the stdout plan https://github.com/borchero/terraform-plan-comment/blob/3399d8dbae8b05185e815e02361ede2949cd99c4/src/render.ts#L103
- Eventually, this part is responsible for turning the structured data from step 2 into the contents of the comment https://github.com/borchero/terraform-plan-comment/blob/3399d8dbae8b05185e815e02361ede2949cd99c4/src/comment.ts#L15
Let me know if you have more specific questions!
🤖 Stalebot
This issue hasn't seen updates in the last 60 days.
If it has been resolved or is not relevant anymore, please consider closing the issue. Otherwise, it will be closed automatically in 30 days.
🤖 Stalebot
This issue hasn't seen updates in the last 60 days.
If it has been resolved or is not relevant anymore, please consider closing the issue. Otherwise, it will be closed automatically in 30 days.