minamijoyo / tfschema

A schema inspector for Terraform / OpenTofu providers
MIT License
295 stars 15 forks source link

Show if arguments require a new resource i.e. `ForceNew: true` #34

Open nitrocode opened 3 years ago

nitrocode commented 3 years ago

Hi @minamijoyo.

Is it possible to grab the ForceNew arguments for resources and build a new column to show which resource arguments cause a recreation ?

For example: https://github.com/hashicorp/terraform-provider-aws/blob/main/aws/resource_aws_ecs_service.go

✗ tfschema resource show aws_ecs_service
+------------------------------------+-------------+----------+----------+----------+-----------+-----------+
| ATTRIBUTE                          | TYPE        | REQUIRED | OPTIONAL | COMPUTED | SENSITIVE | FORCENEW  |
+------------------------------------+-------------+----------+----------+----------+-----------+-----------+
| cluster                            | string      | false    | true     | true     | false     | true      |
minamijoyo commented 3 years ago

Hi, @nitrocode Thank you for your proposal.

Unfortunately it's technically impossible for now because the ForceNew attribute you linked is just an attribute for terraform-plugin-sdk and is not a part of terraform plugin protocol. We cannot inspect it outside of plugin.

https://github.com/hashicorp/terraform-plugin-sdk/blob/5f0e47111e779cb308990590c18d0ed547f0dd37/helper/schema/schema.go#L140

https://github.com/hashicorp/terraform/blob/5b07bb70401093a9ddbb3f2ebc3e2598ec9642d7/docs/plugin-protocol/tfplugin5.2.proto#L90-L100

I agree that it would be useful if it were exposed to users via the plugin protocol so that other tools such as not only tfschema but also terraform-ls (the official LSP server) can use it. I suggest you to open a new issue to the upstream hashicorp/terraform repo.

Thanks!