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

Consider Adding tfprotov5/tfprotov6 Schema* Methods for tftypes.Type Conversion #157

Closed
bflad opened this issue Feb 16, 2022 · 1 comment · Fixed by #158
Closed

Consider Adding tfprotov5/tfprotov6 Schema* Methods for tftypes.Type Conversion #157

bflad opened this issue Feb 16, 2022 · 1 comment · Fixed by #158
Labels
enhancement New feature or request

Comments

@bflad
Copy link
Contributor

bflad commented Feb 16, 2022

terraform-plugin-go version

v0.7.1

Use cases

Downstream implementations, whether SDKs or providers, may need to retrieve the tftypes.Type equivalent of tfprotov5/tfprotov6 schema types such as:

  • Schema
  • SchemaAttribute
  • SchemaBlock
  • SchemaNestedBlock
  • SchemaObject

For example, this is necessary for calling (DynamicValue).Unmarshal(), which is necessary for data handling of ApplyResourceChange and other RPCs.

Attempted solutions

Manually (re-)implementing this logic downstream.

Proposal

Implement methods such as the following:

// package tfprotov5
func (s *Schema) Type() tftypes.Type { /* ... */ }
func (s *SchemaAttribute) Type() tftypes.Type { /* ... */ }
func (s *SchemaBlock) Type() tftypes.Type { /* ... */ }
func (s *SchemaNestedBlock) Type() tftypes.Type { /* ... */ }

// package tfprotov6
func (s *Schema) Type() tftypes.Type { /* ... */ }
func (s *SchemaAttribute) Type() tftypes.Type { /* ... */ }
func (s *SchemaBlock) Type() tftypes.Type { /* ... */ }
func (s *SchemaNestedBlock) Type() tftypes.Type { /* ... */ }
func (s *SchemaObject) Type() tftypes.Type { /* ... */ }

With associated unit testing.

References

@bflad bflad added the enhancement New feature or request label Feb 16, 2022
bflad added a commit that referenced this issue Feb 16, 2022
Reference: #128
Reference: #157

This methods implement standard conversion logic from `Schema*` types into their associated `tftypes.Type` equivalent. For example, these can be used to prepare calls to the `(DynamicValue).Unmarshal()` method, which is necessary in many RPCs.

Preferably, these methods would have been named `Type()`, however the `SchemaAttribute` type implements a `Type` field and Go does not permit overlapping field and method names. Instead, the name `ValueType()` was chosen as an alternate designation as the `tftypes.Type` really represents a data value type, instead of a type constraint (sometimes also referred to as a schema type).
bflad added a commit that referenced this issue Feb 17, 2022
…158)

Reference: #128
Reference: #157

This methods implement standard conversion logic from `Schema*` types into their associated `tftypes.Type` equivalent. For example, these can be used to prepare calls to the `(DynamicValue).Unmarshal()` method, which is necessary in many RPCs.

Preferably, these methods would have been named `Type()`, however the `SchemaAttribute` type implements a `Type` field and Go does not permit overlapping field and method names. Instead, the name `ValueType()` was chosen as an alternate designation as the `tftypes.Type` really represents a data value type, instead of a type constraint (sometimes also referred to as a schema type).
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant