crossplane / terrajet

Generate Crossplane Providers from any Terraform Provider
https://crossplane.io
Apache License 2.0
289 stars 38 forks source link

Generate Required Fields with Pointer Types #88

Closed ulucinar closed 2 years ago

ulucinar commented 2 years ago

What happened?

Currently in Terrajet, we generate fields that correspond to Terraform attributes with a required schema such as this one with non-pointer types. When we late initialize an instance of the enclosing type (network_profile in this example) with an optional schema, we only late-initialize the optional, hence pointer-typed fields) but not the fields that are marked as required. This is because the late-initialization library only initializes nil-pointers because zero-values of non-pointer types (e.g., an empty string) could be a valid value for that attribute, which should not be late-initialized.

How can we reproduce it?

When trying #77 with provider-tf-azure on a v1alpha1.KubernetesCluster resource, first the Kubernetes cluster is provisioned successfully but after the first observation causes a NetworkPlugin to be late-initialized without the NetworkPlugin field (a required field) being late-initialized to one of the allowed values (kubenet or azure) although the Terraform state has it properly set to kubenet.

ulucinar commented 2 years ago

After discussing this issue with @muvaf, we have decided to generate required fields with pointer types also. This will have a bigger impact when compared to handling the situation per-case via Terraformed resource configurations but we do not expect any new issues when we switch from non-pointer to pointer types for required fields and if we succeed, it will provide a better development experience without the need for custom configurations. Also we cannot detect such issues at build time and if we don't attempt to address by non-pointer types, we will be hunting for these issues at runtime.