hashicorp / hashicorp/terraform-plugin-codegen-framework
Consider handling of associated_external_type for all types
- Dominant language
- Go
- Stars
- 57
- Forks
- 29
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 1
Description
Within a specification defined by the [schema](https://github.com/hashicorp/terraform-plugin-codegen-spec/blob/main/spec/v1.0/schema.json) within the [terraform-plugin-codegen-spec](https://github.com/hashicorp/terraform-plugin-codegen-spec/) repo, `associated_external_type` is property that can be optionally defined for
- `nested_object` within `list_nested`, `map_nested`, and `set_nested` attributes
- `single_nested` attributes
- `nested_object` within `list_nested`, and `set_nested` blocks
- `single_nested` blocks
The `associated_external_type` field is used during code generation to signal that methods which transform to and from Terraform Plugin Framework types to API SDK types for use with API calls be autogenerated.
For example, usage of `associated_external_type` in the following specification results in the generation of the `To<...>()/From<...>()` methods.
```json
{
"datasources": [
{
"name": "example",
"schema": {
"attributes": [
{
"name": "list_nested_attribute",
"list_nested": {
"nested_object": {
"associated_external_type": {
"import": {
"path": "example.com/apisdk"
},
"type": "*apisdk.Type"
},
"attributes": [
{
"name": "int64_attribute",
"int64": {
"computed_optional_required": "optional"
}
}
]
},
"computed_optional_required": "optional"
}
}
]
}
}
],
"provider": {
"name": "example"
}
}
```
```go
func (v ListNestedAttributeValue) ToApisdkType(ctx context.Context) (*apisdk.Type, diag.Diagnostics) {
var diags diag.Diagnostics
if v.IsNull() {
return nil, diags
}
if v.IsUnknown() {
diags.Append(diag.NewErrorDiagnostic(
"ListNestedAttributeValue Value Is Unknown",
`"ListNestedAttributeValue" is unknown.`,
))
return nil, diags
}
return &apisdk.Type{
Int64Attribute: v.Int64Attribute.ValueInt64Pointer(),
}, diags
}
func (v ListNestedAttributeValue) FromApisdkType(ctx context.Context, apiObject *apisdk.Type) (ListNestedAttributeValue, diag.Diagnostics) {
var diags diag.Diagnostics
if apiObject == nil {
return NewListNestedAttributeValueNull(), diags
}
return ListNestedAttributeValue{
Int64Attribute: types.Int64PointerValue(apiObject.Int64Attribute),
state: attr.ValueStateKnown,
}, diags
}
```
### Proposal
Extension of the handling of `associated_external_type` for other types (e.g., bool attributes, list attributes) should be considered.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.