Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit e7415b7
Author: Benjamin Bennett <[email protected]>
Date:   Fri Mar 1 16:16:39 2024 +0000

    Reinstate go toolchain and add changelog for Go version bump to 1.21 (#937)

    * Reinstate go toolchain and add changelog for Go version bump to 1.21

    * Adding changelog

    * Updating changelog

commit 1597a95
Author: Sarah French <[email protected]>
Date:   Fri Mar 1 16:12:22 2024 +0000

    Update provider functions testing docs to help users avoid nil pointer error (#940)

    * Fix capitalisation

    * Update example test to mitigate nil pointer error

    See #928

    * Update website/docs/plugin/framework/functions/testing.mdx

    Co-authored-by: Austin Valle <[email protected]>

    * Update website/docs/plugin/framework/functions/testing.mdx

    Co-authored-by: Austin Valle <[email protected]>

    * Update website/docs/plugin/framework/functions/testing.mdx

    Co-authored-by: Austin Valle <[email protected]>

    * Update website/docs/plugin/framework/functions/testing.mdx

    Co-authored-by: Austin Valle <[email protected]>

    * Update website/docs/plugin/framework/functions/testing.mdx

    Co-authored-by: Austin Valle <[email protected]>

    ---------

    Co-authored-by: Austin Valle <[email protected]>
    Co-authored-by: Brian Flad <[email protected]>

commit bd22b58
Author: Brian Flad <[email protected]>
Date:   Fri Mar 1 07:20:55 2024 -0500

    resource/schema: Ensure invalid attribute default value errors are raised (#933)

    Reference: #590
    Reference: #930

    Previously the logic handling attribute `Default` values would silently ignore any type errors, which would lead to confusing planning data behaviors. This updates the logic to raise those error properly and adds covering unit testing.

    These error messages are using the underlying `tftypes` type system errors which is currently a pragmatic compromise throughout various parts of the framework logic that bridges between both type systems to save additional type assertion logic and potential bugs relating to those conversions. In the future if the internal `tftypes` handling and exported fields are replaced with the framework type system types, this logic would instead return error messaging based on the framework type system errors.

    This also will enhance the schema validation logic to check any `Default` response value and compare its type to the schema, which will raise framework type system errors during the `GetProviderSchema` RPC, or during schema unit testing if provider developers have implemented that additional testing.

commit f03ca33
Author: Austin Valle <[email protected]>
Date:   Thu Feb 29 14:23:29 2024 -0500

    function: Add validation for parameter name conflicts and update defaulting logic (#936)

    * add validation and refactor defaulting logic

    * add changelogs

    * test fix

    * Update website/docs/plugin/framework/functions/documentation.mdx

    Co-authored-by: Brian Flad <[email protected]>

    * refactor the logic, tests and docs for defaulting

    * Update website/docs/plugin/framework/functions/documentation.mdx

    Co-authored-by: Benjamin Bennett <[email protected]>

    ---------

    Co-authored-by: Brian Flad <[email protected]>
    Co-authored-by: Benjamin Bennett <[email protected]>
  • Loading branch information
austinvalle committed Mar 1, 2024
1 parent f1c8a97 commit 22b4218
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
6 changes: 4 additions & 2 deletions internal/toproto5/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,11 @@ func TestFunctionParameter(t *testing.T) {
},
},
"type-dynamic": {
fw: function.DynamicParameter{},
fw: function.DynamicParameter{
Name: "dynamic",
},
expected: &tfprotov5.FunctionParameter{
Name: function.DefaultParameterName,
Name: "dynamic",
Type: tftypes.DynamicPseudoType,
},
},
Expand Down
6 changes: 4 additions & 2 deletions internal/toproto6/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,11 @@ func TestFunctionParameter(t *testing.T) {
},
},
"type-dynamic": {
fw: function.DynamicParameter{},
fw: function.DynamicParameter{
Name: "dynamic",
},
expected: &tfprotov6.FunctionParameter{
Name: function.DefaultParameterName,
Name: "dynamic",
Type: tftypes.DynamicPseudoType,
},
},
Expand Down
8 changes: 4 additions & 4 deletions resource/schema/list_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ func (a ListAttribute) ValidateImplementation(ctx context.Context, req fwschema.
resp.Diagnostics.Append(fwschema.AttributeMissingElementTypeDiag(req.Path))
}

if a.ElementType != nil {
resp.Diagnostics.Append(checkAttrTypeForDynamics(req.Path, a.ElementType))
}

if a.ListDefaultValue() != nil {
if !a.IsComputed() {
resp.Diagnostics.Append(nonComputedAttributeWithDefaultDiag(req.Path))
Expand All @@ -279,10 +283,6 @@ func (a ListAttribute) ValidateImplementation(ctx context.Context, req fwschema.
resp.Diagnostics.Append(fwschema.AttributeDefaultElementTypeMismatchDiag(req.Path, a.ElementType, defaultResp.PlanValue.ElementType(ctx)))
}
}

if a.ElementType != nil {
resp.Diagnostics.Append(checkAttrTypeForDynamics(req.Path, a.ElementType))
}
}

// TODO: Not sure if there is a better package for this function, but it definitely needs to go somewhere else. `attr` package?
Expand Down
10 changes: 5 additions & 5 deletions resource/schema/list_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ func (a ListNestedAttribute) ValidateImplementation(ctx context.Context, req fws
resp.Diagnostics.Append(nonComputedAttributeWithDefaultDiag(req.Path))
}

// Only want to check the type for dynamics if no custom type is being used
if a.CustomType == nil {
resp.Diagnostics.Append(checkAttrTypeForDynamics(req.Path, a.GetType()))
}

// Validate Default implementation. This is safe unless the framework
// ever allows more dynamic Default implementations at which the
// implementation would be required to be validated at runtime.
Expand All @@ -301,9 +306,4 @@ func (a ListNestedAttribute) ValidateImplementation(ctx context.Context, req fws
resp.Diagnostics.Append(fwschema.AttributeDefaultElementTypeMismatchDiag(req.Path, a.NestedObject.Type(), defaultResp.PlanValue.ElementType(ctx)))
}
}

// Only want to check the type for dynamics if no custom type is being used
if a.CustomType == nil {
resp.Diagnostics.Append(checkAttrTypeForDynamics(req.Path, a.GetType()))
}
}

0 comments on commit 22b4218

Please sign in to comment.