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

build(deps): bump github.com/hashicorp/terraform-plugin-framework from 1.7.0 to 1.8.0 in the terraform-devex group #36992

Merged
merged 9 commits into from
Apr 25, 2024
Merged
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ require (
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/hcl/v2 v2.20.0
github.com/hashicorp/terraform-plugin-framework v1.7.0
github.com/hashicorp/terraform-plugin-framework v1.8.0
github.com/hashicorp/terraform-plugin-framework-jsontypes v0.1.0
github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1
github.com/hashicorp/terraform-plugin-framework-timetypes v0.3.0
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
github.com/hashicorp/terraform-plugin-go v0.22.1
github.com/hashicorp/terraform-plugin-go v0.22.2
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-mux v0.15.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0
Expand Down Expand Up @@ -242,7 +242,7 @@ require (
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-test/deep v1.1.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
Expand Down Expand Up @@ -280,8 +280,8 @@ require (
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,8 @@ github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4er
github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
Expand Down Expand Up @@ -476,8 +476,8 @@ github.com/hashicorp/terraform-exec v0.20.0 h1:DIZnPsqzPGuUnq6cH8jWcPunBfY+C+M8J
github.com/hashicorp/terraform-exec v0.20.0/go.mod h1:ckKGkJWbsNqFKV1itgMnE0hY9IYf1HoiekpuN0eWoDw=
github.com/hashicorp/terraform-json v0.21.0 h1:9NQxbLNqPbEMze+S6+YluEdXgJmhQykRyRNd+zTI05U=
github.com/hashicorp/terraform-json v0.21.0/go.mod h1:qdeBs11ovMzo5puhrRibdD6d2Dq6TyE/28JiU4tIQxk=
github.com/hashicorp/terraform-plugin-framework v1.7.0 h1:wOULbVmfONnJo9iq7/q+iBOBJul5vRovaYJIu2cY/Pw=
github.com/hashicorp/terraform-plugin-framework v1.7.0/go.mod h1:jY9Id+3KbZ17OMpulgnWLSfwxNVYSoYBQFTgsx044CI=
github.com/hashicorp/terraform-plugin-framework v1.8.0 h1:P07qy8RKLcoBkCrY2RHJer5AEvJnDuXomBgou6fD8kI=
github.com/hashicorp/terraform-plugin-framework v1.8.0/go.mod h1:/CpTukO88PcL/62noU7cuyaSJ4Rsim+A/pa+3rUVufY=
github.com/hashicorp/terraform-plugin-framework-jsontypes v0.1.0 h1:b8vZYB/SkXJT4YPbT3trzE6oJ7dPyMy68+9dEDKsJjE=
github.com/hashicorp/terraform-plugin-framework-jsontypes v0.1.0/go.mod h1:tP9BC3icoXBz72evMS5UTFvi98CiKhPdXF6yLs1wS8A=
github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1 h1:gm5b1kHgFFhaKFhm4h2TgvMUlNzFAtUqlcOWnWPm+9E=
Expand All @@ -486,8 +486,8 @@ github.com/hashicorp/terraform-plugin-framework-timetypes v0.3.0 h1:egR4InfakWkg
github.com/hashicorp/terraform-plugin-framework-timetypes v0.3.0/go.mod h1:9vjvl36aY1p6KltaA5QCvGC5hdE/9t4YuhGftw6WOgE=
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc=
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg=
github.com/hashicorp/terraform-plugin-go v0.22.1 h1:iTS7WHNVrn7uhe3cojtvWWn83cm2Z6ryIUDTRO0EV7w=
github.com/hashicorp/terraform-plugin-go v0.22.1/go.mod h1:qrjnqRghvQ6KnDbB12XeZ4FluclYwptntoWCr9QaXTI=
github.com/hashicorp/terraform-plugin-go v0.22.2 h1:5o8uveu6eZUf5J7xGPV0eY0TPXg3qpmwX9sce03Bxnc=
github.com/hashicorp/terraform-plugin-go v0.22.2/go.mod h1:drq8Snexp9HsbFZddvyLHN6LuWHHndSQg+gV+FPkcIM=
github.com/hashicorp/terraform-plugin-mux v0.15.0 h1:+/+lDx0WUsIOpkAmdwBIoFU8UP9o2eZASoOnLsWbKME=
github.com/hashicorp/terraform-plugin-mux v0.15.0/go.mod h1:9ezplb1Dyq394zQ+ldB0nvy/qbNAz3mMoHHseMTMaKo=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 h1:qHprzXy/As0rxedphECBEQAh3R4yp6pKksKHcqZx5G8=
Expand Down Expand Up @@ -671,10 +671,10 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 h1:AjyfHzEPEFp/NpvfN5g+KDla3EMojjhRVZc1i7cj+oM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s=
google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk=
google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY=
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
Expand Down
4 changes: 2 additions & 2 deletions internal/framework/flex/auto_expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ func TestExpand(t *testing.T) {
},
{
TestName: "single ARN Source and single string Target",
Source: &TestFlexTF17{Field1: fwtypes.ARNValueMust(testARN)},
Source: &TestFlexTF17{Field1: fwtypes.ARNValue(testARN)},
Target: &TestFlexAWS01{},
WantTarget: &TestFlexAWS01{Field1: testARN},
},
{
TestName: "single ARN Source and single *string Target",
Source: &TestFlexTF17{Field1: fwtypes.ARNValueMust(testARN)},
Source: &TestFlexTF17{Field1: fwtypes.ARNValue(testARN)},
Target: &TestFlexAWS02{},
WantTarget: &TestFlexAWS02{Field1: aws.String(testARN)},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/framework/flex/auto_flatten_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,13 @@ func TestFlatten(t *testing.T) {
TestName: "single string Source and single ARN Target",
Source: &TestFlexAWS01{Field1: testARN},
Target: &TestFlexTF17{},
WantTarget: &TestFlexTF17{Field1: fwtypes.ARNValueMust(testARN)},
WantTarget: &TestFlexTF17{Field1: fwtypes.ARNValue(testARN)},
},
{
TestName: "single *string Source and single ARN Target",
Source: &TestFlexAWS02{Field1: aws.String(testARN)},
Target: &TestFlexTF17{},
WantTarget: &TestFlexTF17{Field1: fwtypes.ARNValueMust(testARN)},
WantTarget: &TestFlexTF17{Field1: fwtypes.ARNValue(testARN)},
},
{
TestName: "single nil *string Source and single ARN Target",
Expand Down
4 changes: 2 additions & 2 deletions internal/framework/flex/string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestARNStringFromFramework(t *testing.T) {
}
tests := map[string]testCase{
"valid ARN": {
input: fwtypes.ARNValueMust("arn:aws:iam::123456789012:user/David"),
input: fwtypes.ARNValue("arn:aws:iam::123456789012:user/David"),
expected: aws.String("arn:aws:iam::123456789012:user/David"),
},
"null ARN": {
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestStringToFrameworkARN(t *testing.T) {
tests := map[string]testCase{
"valid ARN": {
input: aws.String("arn:aws:iam::123456789012:user/David"),
expected: fwtypes.ARNValueMust("arn:aws:iam::123456789012:user/David"),
expected: fwtypes.ARNValue("arn:aws:iam::123456789012:user/David"),
},
"null ARN": {
input: nil,
Expand Down
84 changes: 35 additions & 49 deletions internal/framework/types/arn.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@ import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/attr/xattr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hashicorp/terraform-plugin-go/tftypes"
"github.com/hashicorp/terraform-provider-aws/internal/errs/fwdiag"
)

var (
_ xattr.TypeWithValidate = (*arnType)(nil)
_ basetypes.StringTypable = (*arnType)(nil)
_ basetypes.StringValuable = (*ARN)(nil)
_ basetypes.StringTypable = (*arnType)(nil)
)

type arnType struct {
Expand Down Expand Up @@ -61,7 +57,7 @@ func (t arnType) ValueFromString(_ context.Context, in types.String) (basetypes.
return ARNUnknown(), diags // Must not return validation errors.
}

return ARNValueMust(valueString), diags
return ARNValue(valueString), diags
}

func (t arnType) ValueFromTerraform(ctx context.Context, in tftypes.Value) (attr.Value, error) {
Expand Down Expand Up @@ -90,35 +86,10 @@ func (arnType) ValueType(context.Context) attr.Value {
return ARN{}
}

func (t arnType) Validate(ctx context.Context, in tftypes.Value, path path.Path) diag.Diagnostics {
var diags diag.Diagnostics

if !in.IsKnown() || in.IsNull() {
return diags
}

var value string
err := in.As(&value)
if err != nil {
diags.AddAttributeError(
path,
"ARN Type Validation Error",
ProviderErrorDetailPrefix+fmt.Sprintf("Cannot convert value to string: %s", err),
)
return diags
}

if !arn.IsARN(value) {
diags.AddAttributeError(
path,
"ARN Type Validation Error",
fmt.Sprintf("Value %q cannot be parsed as an ARN.", value),
)
return diags
}

return diags
}
var (
_ basetypes.StringValuable = (*ARN)(nil)
_ xattr.ValidateableAttribute = (*ARN)(nil)
)

func ARNNull() ARN {
return ARN{StringValue: basetypes.NewStringNull()}
Expand All @@ -128,23 +99,22 @@ func ARNUnknown() ARN {
return ARN{StringValue: basetypes.NewStringUnknown()}
}

func ARNValue(value string) (ARN, diag.Diagnostics) {
var diags diag.Diagnostics

v, err := arn.Parse(value)
if err != nil {
diags.Append(diag.NewErrorDiagnostic("Invalid ARN", err.Error()))
return ARNUnknown(), diags
}
// ARNValue initializes a new ARN type with the provided value
//
// This function does not return diagnostics, and therefore invalid ARN values
// are not handled during construction. Invalid values will be detected by the
// ValidateAttribute method, called by the ValidateResourceConfig RPC during
// operations like `terraform validate`, `plan`, or `apply`.
func ARNValue(value string) ARN {
// swallow any ARN parsing errors here and just pass along the
// zero value arn.ARN. Invalid values will be handled downstream
// by the ValidateAttribute method.
v, _ := arn.Parse(value)

return ARN{
StringValue: basetypes.NewStringValue(value),
value: v,
}, diags
}

func ARNValueMust(value string) ARN {
return fwdiag.Must(ARNValue(value))
Comment on lines -146 to -147
Copy link
Member

@jar-b jar-b Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that validation is done on the value (during validate, plan, or apply), I opted to remove the Must variant of any constructors which had one.

There were only a few instances where the ARNValue constructor was being used at runtime with handling for the returned diagnostics. I replaced those with direct calls to arn.Parse to guarantee the validity of the ARN value prior to initializing the value. Everywhere ARNValueMust was used has been replaced with the updated ARNValue signature that does not return diagnostics.

}
}

type ARN struct {
Expand All @@ -166,7 +136,23 @@ func (ARN) Type(context.Context) attr.Type {
return ARNType
}

// ValueARN returns the known arn.ARN value. If ARN is null or unknown, returns {}.
// ValueARN returns the known arn.ARN value. If ARN is null, unknown, or invalid returns ARN{}.
func (v ARN) ValueARN() arn.ARN {
return v.value
}

func (v ARN) ValidateAttribute(ctx context.Context, req xattr.ValidateAttributeRequest, resp *xattr.ValidateAttributeResponse) {
if v.IsNull() || v.IsUnknown() {
return
}

if !arn.IsARN(v.ValueString()) {
resp.Diagnostics.AddAttributeError(
req.Path,
"Invalid ARN Value",
"The provided value cannot be parsed as an ARN.\n\n"+
"Path: "+req.Path.String()+"\n"+
"Value: "+v.ValueString(),
)
}
}
40 changes: 17 additions & 23 deletions internal/framework/types/arn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/attr/xattr"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tftypes"
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
Expand All @@ -32,7 +32,7 @@ func TestARNTypeValueFromTerraform(t *testing.T) {
},
"valid ARN": {
val: tftypes.NewValue(tftypes.String, "arn:aws:rds:us-east-1:123456789012:db:test"), // lintignore:AWSAT003,AWSAT005
expected: fwtypes.ARNValueMust("arn:aws:rds:us-east-1:123456789012:db:test"), // lintignore:AWSAT003,AWSAT005
expected: fwtypes.ARNValue("arn:aws:rds:us-east-1:123456789012:db:test"), // lintignore:AWSAT003,AWSAT005
},
"invalid ARN": {
val: tftypes.NewValue(tftypes.String, "not ok"),
Expand All @@ -59,29 +59,25 @@ func TestARNTypeValueFromTerraform(t *testing.T) {
}
}

func TestARNTypeValidate(t *testing.T) {
func TestARNValidateAttribute(t *testing.T) {
t.Parallel()

type testCase struct {
val tftypes.Value
val fwtypes.ARN
expectError bool
}
tests := map[string]testCase{
"not a string": {
val: tftypes.NewValue(tftypes.Bool, true),
expectError: true,
},
"unknown string": {
val: tftypes.NewValue(tftypes.String, tftypes.UnknownValue),
"null value": {
val: fwtypes.ARNNull(),
},
"null string": {
val: tftypes.NewValue(tftypes.String, nil),
"unknown value": {
val: fwtypes.ARNUnknown(),
},
"valid string": {
val: tftypes.NewValue(tftypes.String, "arn:aws:rds:us-east-1:123456789012:db:test"), // lintignore:AWSAT003,AWSAT005
"valid arn": {
val: fwtypes.ARNValue("arn:aws:rds:us-east-1:123456789012:db:test"), // lintignore:AWSAT003,AWSAT005
},
"invalid string": {
val: tftypes.NewValue(tftypes.String, "not ok"),
"invalid arn": {
val: fwtypes.ARNValue("not ok"), // lintignore:AWSAT003,AWSAT005
expectError: true,
},
}
Expand All @@ -93,14 +89,12 @@ func TestARNTypeValidate(t *testing.T) {

ctx := context.Background()

diags := fwtypes.ARNType.Validate(ctx, test.val, path.Root("test"))

if !diags.HasError() && test.expectError {
t.Fatal("expected error, got no error")
}
req := xattr.ValidateAttributeRequest{}
resp := xattr.ValidateAttributeResponse{}

if diags.HasError() && !test.expectError {
t.Fatalf("got unexpected error: %#v", diags)
test.val.ValidateAttribute(ctx, req, &resp)
if resp.Diagnostics.HasError() != test.expectError {
t.Errorf("resp.Diagnostics.HasError() = %t, want = %t", resp.Diagnostics.HasError(), test.expectError)
}
})
}
Expand Down
Loading
Loading