Skip to content

Commit

Permalink
Merge pull request #28119 from hashicorp/td-framework-0.17
Browse files Browse the repository at this point in the history
deps: terraform-plugin-framework `v0.17.0` upgrade
  • Loading branch information
jar-b committed Dec 5, 2022
2 parents bc4dde9 + 4e8075d commit be9fb0a
Show file tree
Hide file tree
Showing 30 changed files with 420 additions and 848 deletions.
10 changes: 5 additions & 5 deletions go.mod
Expand Up @@ -41,9 +41,9 @@ require (
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/hcl/v2 v2.15.0
github.com/hashicorp/terraform-plugin-framework v0.16.0
github.com/hashicorp/terraform-plugin-framework-validators v0.6.0
github.com/hashicorp/terraform-plugin-go v0.14.1
github.com/hashicorp/terraform-plugin-framework v0.17.0
github.com/hashicorp/terraform-plugin-framework-validators v0.7.0
github.com/hashicorp/terraform-plugin-go v0.14.2
github.com/hashicorp/terraform-plugin-log v0.7.0
github.com/hashicorp/terraform-plugin-mux v0.7.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
Expand Down Expand Up @@ -94,7 +94,7 @@ require (
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/terraform-exec v0.17.3 // indirect
github.com/hashicorp/terraform-json v0.14.0 // indirect
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c // indirect
github.com/hashicorp/terraform-registry-address v0.1.0 // indirect
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
github.com/huandu/xstrings v1.3.2 // indirect
Expand All @@ -121,6 +121,6 @@ require (
golang.org/x/text v0.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20200711021454-869866162049 // indirect
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
)
21 changes: 10 additions & 11 deletions go.sum
Expand Up @@ -206,20 +206,20 @@ github.com/hashicorp/terraform-exec v0.17.3 h1:MX14Kvnka/oWGmIkyuyvL6POx25ZmKrjl
github.com/hashicorp/terraform-exec v0.17.3/go.mod h1:+NELG0EqQekJzhvikkeQsOAZpsw0cv/03rbeQJqscAI=
github.com/hashicorp/terraform-json v0.14.0 h1:sh9iZ1Y8IFJLx+xQiKHGud6/TSUCM0N8e17dKDpqV7s=
github.com/hashicorp/terraform-json v0.14.0/go.mod h1:5A9HIWPkk4e5aeeXIBbkcOvaZbIYnAIkEyqP2pNSckM=
github.com/hashicorp/terraform-plugin-framework v0.16.0 h1:kEHh0d6dp5Ig/ey6PYXkWDZPMLIW8Me41T/Oa7bpO4s=
github.com/hashicorp/terraform-plugin-framework v0.16.0/go.mod h1:Vk5MuIJoE1qksHZawAZr6psx6YXsQBFIKDrWbROrwus=
github.com/hashicorp/terraform-plugin-framework-validators v0.6.0 h1:j8GlgzuTjbbkMnsbiOXerwJTW8Us4saQwo4FfJKd2I0=
github.com/hashicorp/terraform-plugin-framework-validators v0.6.0/go.mod h1:iOYhZQinlZ0R/M3Q3nCXS4dikZ7P41d5b7ezpe9uoIw=
github.com/hashicorp/terraform-plugin-go v0.14.1 h1:cwZzPYla82XwAqpLhSzdVsOMU+6H29tczAwrB0z9Zek=
github.com/hashicorp/terraform-plugin-go v0.14.1/go.mod h1:Bc/K6K26BQ2FHqIELPbpKtt2CzzbQou+0UQF3/0NsCQ=
github.com/hashicorp/terraform-plugin-framework v0.17.0 h1:0KUOY/oe1GPLFqaXnKDnd1rhCrnUtt8pV9wGEwNUFlU=
github.com/hashicorp/terraform-plugin-framework v0.17.0/go.mod h1:FV97t2BZOARkL7NNlsc/N25c84MyeSSz72uPp7Vq1lg=
github.com/hashicorp/terraform-plugin-framework-validators v0.7.0 h1:tIYOMNmEMQIc6mwun8nX3e5U3TkgZg1TpXRlBEBQHwY=
github.com/hashicorp/terraform-plugin-framework-validators v0.7.0/go.mod h1:e1RKREyEVdd3FK8Jfgz8L/ThQgcJKLb4ZJxNzsuIH0A=
github.com/hashicorp/terraform-plugin-go v0.14.2 h1:rhsVEOGCnY04msNymSvbUsXfRLKh9znXZmHlf5e8mhE=
github.com/hashicorp/terraform-plugin-go v0.14.2/go.mod h1:Q12UjumPNGiFsZffxOsA40Tlz1WVXt2Evh865Zj0+UA=
github.com/hashicorp/terraform-plugin-log v0.7.0 h1:SDxJUyT8TwN4l5b5/VkiTIaQgY6R+Y2BQ0sRZftGKQs=
github.com/hashicorp/terraform-plugin-log v0.7.0/go.mod h1:p4R1jWBXRTvL4odmEkFfDdhUjHf9zcs/BCoNHAc7IK4=
github.com/hashicorp/terraform-plugin-mux v0.7.0 h1:wRbSYzg+v2sn5Mdee0UKm4YTt4wJG0LfSwtgNuBkglY=
github.com/hashicorp/terraform-plugin-mux v0.7.0/go.mod h1:Ae30Mc5lz4d1awtiCbHP0YyvgBeiQ00Q1nAq0U3lb+I=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1 h1:zHcMbxY0+rFO9gY99elV/XC/UnQVg7FhRCbj1i5b7vM=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1/go.mod h1:+tNlb0wkfdsDJ7JEiERLz4HzM19HyiuIoGzTsM7rPpw=
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c h1:D8aRO6+mTqHfLsK/BC3j5OAoogv1WLRWzY1AaTo3rBg=
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c/go.mod h1:Wn3Na71knbXc1G8Lh+yu/dQWWJeFQEpDeJMtWMtlmNI=
github.com/hashicorp/terraform-registry-address v0.1.0 h1:W6JkV9wbum+m516rCl5/NjKxCyTVaaUBbzYcMzBDO3U=
github.com/hashicorp/terraform-registry-address v0.1.0/go.mod h1:EnyO2jYO6j29DTHbJcm00E5nQTFeTtyZH3H5ycydQ5A=
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
Expand Down Expand Up @@ -279,7 +279,6 @@ github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k+Mg7cowZ8yv4Trqw9UsJby758=
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -431,8 +430,8 @@ google.golang.org/genproto v0.0.0-20200711021454-869866162049/go.mod h1:FWY/as6D
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.50.1 h1:DS/BukOZWp8s6p4Dt/tOaJaTQyPyOoCcrjroHuCeLzY=
google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
google.golang.org/grpc v1.51.0 h1:E1eGv1FTqoLIdnBCZufiSHgKjlqG6fKFf6pPWtMTh8U=
google.golang.org/grpc v1.51.0/go.mod h1:wgNDFcnuBGmxLKI/qn4T+m5BtEBYXJPvibbUPsAIPww=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
17 changes: 11 additions & 6 deletions internal/acctest/framework.go
Expand Up @@ -2,6 +2,7 @@ package acctest

import (
"context"
"errors"
"fmt"
"log"
"strings"
Expand Down Expand Up @@ -29,16 +30,20 @@ func DeleteFrameworkResource(factory func(context.Context) (fwresource.ResourceW

resource.Configure(ctx, fwresource.ConfigureRequest{ProviderData: meta}, &fwresource.ConfigureResponse{})

schema, diags := resource.GetSchema(ctx)

if diags.HasError() {
return fwdiag.DiagnosticsError(diags)
schemaResp := fwresource.SchemaResponse{}
if v, ok := resource.(fwresource.ResourceWithSchema); ok {
v.Schema(ctx, fwresource.SchemaRequest{}, &schemaResp)
if schemaResp.Diagnostics.HasError() {
return fwdiag.DiagnosticsError(schemaResp.Diagnostics)
}
} else {
return errors.New("resource does not implement Schema method")
}

// Construct a simple Framework State that contains just top-level attributes.
state := tfsdk.State{
Raw: tftypes.NewValue(schema.Type().TerraformType(ctx), nil),
Schema: schema,
Raw: tftypes.NewValue(schemaResp.Schema.Type().TerraformType(ctx), nil),
Schema: schemaResp.Schema,
}

for name, v := range is.Attributes {
Expand Down
4 changes: 2 additions & 2 deletions internal/enum/validate.go
Expand Up @@ -2,7 +2,7 @@ package enum

import (
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
Expand All @@ -11,6 +11,6 @@ func Validate[T valueser[T]]() schema.SchemaValidateDiagFunc {
return validation.ToDiagFunc(validation.StringInSlice(Values[T](), false))
}

func FrameworkValidate[T valueser[T]]() tfsdk.AttributeValidator {
func FrameworkValidate[T valueser[T]]() validator.String {
return stringvalidator.OneOf(Values[T]()...)
}
15 changes: 7 additions & 8 deletions internal/framework/id_attribute.go
@@ -1,17 +1,16 @@
package framework

import (
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
)

func IDAttribute() tfsdk.Attribute {
return tfsdk.Attribute{
Type: types.StringType,
func IDAttribute() schema.StringAttribute {
return schema.StringAttribute{
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
resource.UseStateForUnknown(),
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
}
}
26 changes: 26 additions & 0 deletions internal/framework/types/arn.go
Expand Up @@ -9,6 +9,7 @@ import (
"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-go/tftypes"
)

Expand Down Expand Up @@ -118,6 +119,27 @@ func (t arnType) Description() string {
return `An Amazon Resource Name.`
}

func (t arnType) ValueFromString(ctx context.Context, st types.String) (types.StringValuable, diag.Diagnostics) {
if st.IsNull() {
return ARNNull(), nil
}
if st.IsUnknown() {
return ARNUnknown(), nil
}

var diags diag.Diagnostics
v, err := arn.Parse(st.String())
if err != nil {
diags.AddError(
"ARN ValueFromString Error",
fmt.Sprintf("String %s cannot be parsed as an ARN.", st),
)
return nil, diags
}

return ARNValue(v), diags
}

func ARNNull() ARN {
return ARN{
state: attr.ValueStateNull,
Expand Down Expand Up @@ -150,6 +172,10 @@ func (a ARN) Type(_ context.Context) attr.Type {
return ARNType
}

func (a ARN) ToStringValue(ctx context.Context) (types.String, diag.Diagnostics) {
return types.StringValue(a.value.String()), nil
}

func (a ARN) ToTerraformValue(ctx context.Context) (tftypes.Value, error) {
t := ARNType.TerraformType(ctx)

Expand Down
31 changes: 13 additions & 18 deletions internal/framework/validators/cidr.go
Expand Up @@ -4,7 +4,7 @@ import (
"context"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)

Expand All @@ -22,31 +22,28 @@ func (validator ipv4CIDRNetworkAddressValidator) MarkdownDescription(ctx context
}

// Validate performs the validation.
func (validator ipv4CIDRNetworkAddressValidator) Validate(ctx context.Context, request tfsdk.ValidateAttributeRequest, response *tfsdk.ValidateAttributeResponse) {
s, ok := validateString(ctx, request, response)

if !ok {
func (validator ipv4CIDRNetworkAddressValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) {
if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() {
return
}

if err := verify.ValidateIPv4CIDRBlock(s); err != nil {
if err := verify.ValidateIPv4CIDRBlock(request.ConfigValue.ValueString()); err != nil {
response.Diagnostics.Append(diag.NewAttributeErrorDiagnostic(
request.AttributePath,
request.Path,
validator.Description(ctx),
err.Error(),
))

return
}
}

// IPv4CIDRNetworkAddress returns an AttributeValidator which ensures that any configured
// IPv4CIDRNetworkAddress returns a string validator which ensures that any configured
// attribute value:
//
// - Is a string, which represents a valid IPv4 CIDR network address.
//
// Null (unconfigured) and unknown (known after apply) values are skipped.
func IPv4CIDRNetworkAddress() tfsdk.AttributeValidator {
func IPv4CIDRNetworkAddress() validator.String {
return ipv4CIDRNetworkAddressValidator{}
}

Expand All @@ -64,16 +61,14 @@ func (validator ipv6CIDRNetworkAddressValidator) MarkdownDescription(ctx context
}

// Validate performs the validation.
func (validator ipv6CIDRNetworkAddressValidator) Validate(ctx context.Context, request tfsdk.ValidateAttributeRequest, response *tfsdk.ValidateAttributeResponse) {
s, ok := validateString(ctx, request, response)

if !ok {
func (validator ipv6CIDRNetworkAddressValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) {
if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() {
return
}

if err := verify.ValidateIPv6CIDRBlock(s); err != nil {
if err := verify.ValidateIPv6CIDRBlock(request.ConfigValue.ValueString()); err != nil {
response.Diagnostics.Append(diag.NewAttributeErrorDiagnostic(
request.AttributePath,
request.Path,
validator.Description(ctx),
err.Error(),
))
Expand All @@ -82,12 +77,12 @@ func (validator ipv6CIDRNetworkAddressValidator) Validate(ctx context.Context, r
}
}

// IPv6CIDRNetworkAddress returns an AttributeValidator which ensures that any configured
// IPv6CIDRNetworkAddress returns a string validator which ensures that any configured
// attribute value:
//
// - Is a string, which represents a valid IPv6 CIDR network address.
//
// Null (unconfigured) and unknown (known after apply) values are skipped.
func IPv6CIDRNetworkAddress() tfsdk.AttributeValidator {
func IPv6CIDRNetworkAddress() validator.String {
return ipv6CIDRNetworkAddressValidator{}
}
39 changes: 15 additions & 24 deletions internal/framework/validators/cidr_test.go
Expand Up @@ -4,9 +4,8 @@ import (
"context"
"testing"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
fwvalidators "github.com/hashicorp/terraform-provider-aws/internal/framework/validators"
)
Expand All @@ -15,14 +14,10 @@ func TestIPv4CIDRNetworkAddressValidator(t *testing.T) {
t.Parallel()

type testCase struct {
val attr.Value
val types.String
expectError bool
}
tests := map[string]testCase{
"not a String": {
val: types.BoolValue(true),
expectError: true,
},
"unknown String": {
val: types.StringUnknown(),
},
Expand All @@ -49,13 +44,13 @@ func TestIPv4CIDRNetworkAddressValidator(t *testing.T) {
for name, test := range tests {
name, test := name, test
t.Run(name, func(t *testing.T) {
request := tfsdk.ValidateAttributeRequest{
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
AttributeConfig: test.val,
request := validator.StringRequest{
Path: path.Root("test"),
PathExpression: path.MatchRoot("test"),
ConfigValue: test.val,
}
response := tfsdk.ValidateAttributeResponse{}
fwvalidators.IPv4CIDRNetworkAddress().Validate(context.Background(), request, &response)
response := validator.StringResponse{}
fwvalidators.IPv4CIDRNetworkAddress().ValidateString(context.Background(), request, &response)

if !response.Diagnostics.HasError() && test.expectError {
t.Fatal("expected error, got no error")
Expand All @@ -72,14 +67,10 @@ func TestIPv6CIDRNetworkAddressValidator(t *testing.T) {
t.Parallel()

type testCase struct {
val attr.Value
val types.String
expectError bool
}
tests := map[string]testCase{
"not a String": {
val: types.BoolValue(true),
expectError: true,
},
"unknown String": {
val: types.StringUnknown(),
},
Expand All @@ -106,13 +97,13 @@ func TestIPv6CIDRNetworkAddressValidator(t *testing.T) {
for name, test := range tests {
name, test := name, test
t.Run(name, func(t *testing.T) {
request := tfsdk.ValidateAttributeRequest{
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
AttributeConfig: test.val,
request := validator.StringRequest{
Path: path.Root("test"),
PathExpression: path.MatchRoot("test"),
ConfigValue: test.val,
}
response := tfsdk.ValidateAttributeResponse{}
fwvalidators.IPv6CIDRNetworkAddress().Validate(context.Background(), request, &response)
response := validator.StringResponse{}
fwvalidators.IPv6CIDRNetworkAddress().ValidateString(context.Background(), request, &response)

if !response.Diagnostics.HasError() && test.expectError {
t.Fatal("expected error, got no error")
Expand Down

0 comments on commit be9fb0a

Please sign in to comment.