Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resources - Change body, delete_body, output from string tpye to dynamic type #87

Merged
merged 25 commits into from
May 22, 2024

Conversation

magodo
Copy link
Owner

@magodo magodo commented Apr 16, 2024

This PR makes the following changes:

  • restful_resource - Change the type of body, output from string to dynamic
  • restful_resource - Read invoked from Create/Update now won't update the body (but still update the output). This makes those round trip inconsistent APIs won't cause error during the terraform apply, which makes the resource as tainted. Instead it will show the diff in the next terraform plan, which brings a chance for users to add the write_only_attrs/ignore_changes
  • restful_operation - Change the type of body, delete_body, output from string to dynamic
  • restful_resource data source - Change the type of output from string to dynamic

Fix #83
Fix #91

This commit changes the type of `body` from string to dynamic type.
Accordingly, it removes the `write_only_attrs` as it now can be replaced by the `lifecycle.ignore_changes`.

Whilst some of the attributes are still required:

- `force_new_attrs`: This can't be replaced by `lifecycle.replace_triggered_by`, as the latter can't be applied to the resource itself as the point at which terraform must decide to replace a resource is before the provider has planned the change. See [this](hashicorp/terraform#31702 (comment)) for details.
- `output`: This *can* be changed from string to dynamic (as for `body`) for most cases. Whilst it might cause fatal error when the API returns different model given different input (e.g. an update of the API model introduces a new attribute in the read afterwards). The reason can be found at [here](https://developer.hashicorp.com/terraform/plugin/framework/handling-data/dynamic-data#understanding-type-consistency).
- `output_attrs`: As the `output` is stil a string, this attribute is still needed.

There are also some remaining things to do:

- The import spec now breaks as the `body` needs encode type. There needs a grammer for the `body` to define its fw type.
- The test needs to update
- The data source and operationr esource needs to update

There are also inconvinience than the previous way of using string, e.g. `[1,2,3]` is by default of type tuple, which will cause inconsistency error when the tuple's length changed.
@magodo magodo changed the title Change body from string tpye to dynamic type resources - Change body, delete_body, output from string tpye to dynamic type Apr 16, 2024
@magodo magodo added enhancement New feature or request breaking-change labels Apr 16, 2024
@magodo magodo merged commit 773524f into main May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change enhancement New feature or request
Projects
None yet
1 participant