terraform-provider-rancher2
terraform-provider-rancher2 copied to clipboard
[RFE] Setup auto generation for utility code
Is your feature request related to a problem? Please describe.
~~1. Terraform needs to be upgraded to use SDK v2 which will enable better debugging and diagnostics support, specifically the ability to run the TF binary with an IDE debugger (which we could not do before and is a pain point for dev. We've had to guess on multiple past fixes because we have no way to step through the code. Examples are the plan bug and kubeconfig token generation).~~ Covered by existing https://github.com/rancher/terraform-provider-rancher2/issues/1080.
- There's also a lot of patterned code in the TFP provider and it'd save a lot of time to find a way to auto generate all the schemas, expanders, and flatteners.
We just did this for the TF rke provider https://github.com/rancher/terraform-provider-rancher2/issues/1134 and now it needs to be implemented for rancher2.
@a-blender Before working on this we probably should consider checking the new terraform plugin framework.
Different of the upgrade from the SDKv1 -> SDKv2 the upgrade from SDKv2 -> Plugin-framework can be done in parts.
IMO if we do a code generator we probably should do it on the latest versions. For what I read on the framework now will be possible to "unmarshal" the tf config into a struct, which would make this task much easier.
This is not the right place to this, but I was doing some research on the Framework. I'll keep some notes here for tracking before we have a talk and decide things about doing (or not) this migration.
Notes from Migrating SDK-v2 to the new Framework.
Advantage:
- New "SDK", the one reciving new features.
- Cleaner Code and declaration of ressources
- Values can be treated as zero value , null or unkown. Previous null / unknown would return the zero value (Resolve false problem like the one on RKE docker_cri)
- We can now create a struct with tag tfsdk and bind the values instead of doing Flatterns / Expanders.
- Allow for partial change from SDK-V2 to Plugin, (Muxing)
- Automated Doc generation. https://developer.hashicorp.com/terraform/plugin/framework/migrating
Disadvantage:
- HUGEEEE change, All schemas, ressources, .Get/.Set must be modified, it require almost a full refactor. (RKE would have a significant change in 70+ Files and probably 400+ on the rancher2)
- Change all the ressource create to Add the ID value and the the response must be manualy set
Concerns:
- Huge changes than can easily cause regressions.
- Gota fix eventual data consistency errors before doing so, is kinda hard to get them with our setup as described: https://developer.hashicorp.com/terraform/plugin/sdkv2/resources/data-consistency-errors.
Blocked until work for migration to SDK v2 https://github.com/rancher/terraform-provider-rancher2/issues/1080 is merged.