From 3ee720e0e7124d92514ebceea6b6a405562429b2 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Wed, 30 Nov 2022 20:46:38 -0500 Subject: [PATCH 1/5] deps: bump terraform-plugin-framework to 0.17.0 --- go.mod | 8 ++++---- go.sum | 17 ++++++++--------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index a287ec93f5dc..df219cd1e055 100644 --- a/go.mod +++ b/go.mod @@ -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 v0.17.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-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 @@ -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 @@ -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 ) diff --git a/go.sum b/go.sum index 759254a2490d..d76c908ddd80 100644 --- a/go.sum +++ b/go.sum @@ -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 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.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-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= @@ -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= @@ -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= From 03d73b035715fce0ec49e3743d57deec1dae01b5 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Fri, 2 Dec 2022 16:29:56 -0500 Subject: [PATCH 2/5] deps: bump terraform-plugin-framework-validators to 0.7.0 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index df219cd1e055..78ea57a6013e 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,7 @@ require ( github.com/hashicorp/go-version v1.6.0 github.com/hashicorp/hcl/v2 v2.15.0 github.com/hashicorp/terraform-plugin-framework v0.17.0 - github.com/hashicorp/terraform-plugin-framework-validators v0.6.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 diff --git a/go.sum b/go.sum index d76c908ddd80..b07ccbf3adf5 100644 --- a/go.sum +++ b/go.sum @@ -208,8 +208,8 @@ github.com/hashicorp/terraform-json v0.14.0 h1:sh9iZ1Y8IFJLx+xQiKHGud6/TSUCM0N8e github.com/hashicorp/terraform-json v0.14.0/go.mod h1:5A9HIWPkk4e5aeeXIBbkcOvaZbIYnAIkEyqP2pNSckM= 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.6.0 h1:j8GlgzuTjbbkMnsbiOXerwJTW8Us4saQwo4FfJKd2I0= -github.com/hashicorp/terraform-plugin-framework-validators v0.6.0/go.mod h1:iOYhZQinlZ0R/M3Q3nCXS4dikZ7P41d5b7ezpe9uoIw= +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= From 1e9e45fe9544cf4c00991efb0a72e052467279ad Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 1 Dec 2022 13:54:26 -0500 Subject: [PATCH 3/5] fix(fw): assert WithGetSchema interface extension --- internal/acctest/framework.go | 14 +++++++++++--- internal/provider/fwprovider/provider.go | 22 ++++++++++++++++++++-- internal/sweep/framework.go | 14 +++++++++++--- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/internal/acctest/framework.go b/internal/acctest/framework.go index 80c82f35d061..f79f55549c3b 100644 --- a/internal/acctest/framework.go +++ b/internal/acctest/framework.go @@ -2,10 +2,12 @@ package acctest import ( "context" + "errors" "fmt" "log" "strings" + "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" fwresource "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" @@ -29,10 +31,16 @@ func DeleteFrameworkResource(factory func(context.Context) (fwresource.ResourceW resource.Configure(ctx, fwresource.ConfigureRequest{ProviderData: meta}, &fwresource.ConfigureResponse{}) - schema, diags := resource.GetSchema(ctx) + var schema tfsdk.Schema + var diags diag.Diagnostics + if v, ok := resource.(fwresource.ResourceWithGetSchema); ok { + schema, diags = v.GetSchema(ctx) - if diags.HasError() { - return fwdiag.DiagnosticsError(diags) + if diags.HasError() { + return fwdiag.DiagnosticsError(diags) + } + } else { + return errors.New("resource does not implement GetSchema method") } // Construct a simple Framework State that contains just top-level attributes. diff --git a/internal/provider/fwprovider/provider.go b/internal/provider/fwprovider/provider.go index 329abd15c65b..33c39fc160aa 100644 --- a/internal/provider/fwprovider/provider.go +++ b/internal/provider/fwprovider/provider.go @@ -404,7 +404,16 @@ func (w *wrappedDataSource) Metadata(ctx context.Context, request datasource.Met } func (w *wrappedDataSource) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { - return w.inner.GetSchema(ctx) + if v, ok := w.inner.(datasource.DataSourceWithGetSchema); ok { + return v.GetSchema(ctx) + } + + var diags diag.Diagnostics + diags.AddError( + "DataSource GetSchema Not Implemented", + "This data source does not support get schema. Please contact the provider developer for additional information.", + ) + return tfsdk.Schema{}, diags } func (w *wrappedDataSource) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) { @@ -434,7 +443,16 @@ func (w *wrappedResource) Metadata(ctx context.Context, request resource.Metadat } func (w *wrappedResource) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { - return w.inner.GetSchema(ctx) + if v, ok := w.inner.(resource.ResourceWithGetSchema); ok { + return v.GetSchema(ctx) + } + + var diags diag.Diagnostics + diags.AddError( + "Resource GetSchema Not Implemented", + "This resource does not support get schema. Please contact the provider developer for additional information.", + ) + return tfsdk.Schema{}, diags } func (w *wrappedResource) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { diff --git a/internal/sweep/framework.go b/internal/sweep/framework.go index bdc5e3c37a26..d6d4761b21de 100644 --- a/internal/sweep/framework.go +++ b/internal/sweep/framework.go @@ -5,10 +5,12 @@ package sweep import ( "context" + "errors" "log" "strings" "time" + "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" fwresource "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" @@ -68,10 +70,16 @@ func DeleteFrameworkResource(factory func(context.Context) (fwresource.ResourceW resource.Configure(ctx, fwresource.ConfigureRequest{ProviderData: meta}, &fwresource.ConfigureResponse{}) - schema, diags := resource.GetSchema(ctx) + var schema tfsdk.Schema + var diags diag.Diagnostics + if v, ok := resource.(fwresource.ResourceWithGetSchema); ok { + schema, diags = v.GetSchema(ctx) - if diags.HasError() { - return fwdiag.DiagnosticsError(diags) + if diags.HasError() { + return fwdiag.DiagnosticsError(diags) + } + } else { + return errors.New("resource does not implement GetSchema method") } // Simple Terraform State that contains just the resource ID. From 07e733a8156e28f907a0aef42c905913465bfdc0 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Thu, 1 Dec 2022 16:49:46 -0500 Subject: [PATCH 4/5] refactor(fw): GetSchema -> Schema fix: update custom arn attribute type fix(tfsdk2fw): update Schema return fix: update IDAttribute to resource schema fix: update NormalizeIPProtocol plan modifier fix(fw): update ip cidr validators fix(enum): update to string validator interface fix(fw): update int64 between validator fix(fw): migrate blocks to updated schema --- internal/acctest/framework.go | 19 +- internal/enum/validate.go | 4 +- internal/framework/id_attribute.go | 15 +- internal/framework/types/arn.go | 26 +++ internal/framework/validators/cidr.go | 31 ++- internal/framework/validators/cidr_test.go | 39 ++-- internal/framework/validators/int64string.go | 63 ------ .../framework/validators/int64string_test.go | 93 -------- .../framework/validators/type_validation.go | 53 ----- .../validators/type_validation_test.go | 150 ------------- internal/provider/fwprovider/provider.go | 28 +-- .../ec2/vpc_security_group_ingress_rule.go | 116 ++++------ .../vpc_security_group_ingress_rule_test.go | 25 +-- .../accelerator_data_source.go | 51 ++--- .../service/medialive/multiplex_program.go | 211 +++++++++--------- internal/service/meta/arn_data_source.go | 37 ++- .../billing_service_account_data_source.go | 19 +- .../service/meta/default_tags_data_source.go | 16 +- .../service/meta/ip_ranges_data_source.go | 49 ++-- .../service/meta/partition_data_source.go | 25 +-- internal/service/meta/region_data_source.go | 25 +-- internal/service/meta/regions_data_source.go | 27 +-- internal/service/meta/service_data_source.go | 37 ++- internal/service/simpledb/domain.go | 22 +- .../sts/caller_identity_data_source.go | 25 +-- internal/sweep/framework.go | 19 +- tools/tfsdk2fw/datasource.tmpl | 8 +- tools/tfsdk2fw/resource.tmpl | 8 +- 28 files changed, 389 insertions(+), 852 deletions(-) delete mode 100644 internal/framework/validators/int64string.go delete mode 100644 internal/framework/validators/int64string_test.go delete mode 100644 internal/framework/validators/type_validation.go delete mode 100644 internal/framework/validators/type_validation_test.go diff --git a/internal/acctest/framework.go b/internal/acctest/framework.go index f79f55549c3b..d7e2ebf9e8ec 100644 --- a/internal/acctest/framework.go +++ b/internal/acctest/framework.go @@ -7,7 +7,6 @@ import ( "log" "strings" - "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" fwresource "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" @@ -31,22 +30,20 @@ func DeleteFrameworkResource(factory func(context.Context) (fwresource.ResourceW resource.Configure(ctx, fwresource.ConfigureRequest{ProviderData: meta}, &fwresource.ConfigureResponse{}) - var schema tfsdk.Schema - var diags diag.Diagnostics - if v, ok := resource.(fwresource.ResourceWithGetSchema); ok { - schema, diags = v.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 GetSchema method") + 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 { diff --git a/internal/enum/validate.go b/internal/enum/validate.go index 180609681a4f..4becca3521e4 100644 --- a/internal/enum/validate.go +++ b/internal/enum/validate.go @@ -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" ) @@ -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]()...) } diff --git a/internal/framework/id_attribute.go b/internal/framework/id_attribute.go index 2ed666fb4ae0..b2ca9be81f74 100644 --- a/internal/framework/id_attribute.go +++ b/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(), }, } } diff --git a/internal/framework/types/arn.go b/internal/framework/types/arn.go index fef235a7df3c..a5eefe0f3baf 100644 --- a/internal/framework/types/arn.go +++ b/internal/framework/types/arn.go @@ -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" ) @@ -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, @@ -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) diff --git a/internal/framework/validators/cidr.go b/internal/framework/validators/cidr.go index b60aa6fb40b3..c72ec8b95fed 100644 --- a/internal/framework/validators/cidr.go +++ b/internal/framework/validators/cidr.go @@ -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" ) @@ -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{} } @@ -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(), )) @@ -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{} } diff --git a/internal/framework/validators/cidr_test.go b/internal/framework/validators/cidr_test.go index 7b568d1f371a..faf768be5d3e 100644 --- a/internal/framework/validators/cidr_test.go +++ b/internal/framework/validators/cidr_test.go @@ -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" ) @@ -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(), }, @@ -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") @@ -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(), }, @@ -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") diff --git a/internal/framework/validators/int64string.go b/internal/framework/validators/int64string.go deleted file mode 100644 index bad5adfd2875..000000000000 --- a/internal/framework/validators/int64string.go +++ /dev/null @@ -1,63 +0,0 @@ -package validators - -import ( - "context" - "fmt" - - "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" -) - -var _ tfsdk.AttributeValidator = int64StringBetweenValidator{} - -// int64StringBetweenValidator validates that a string Attribute's value is an integer in a range. -type int64StringBetweenValidator struct { - min, max int64 -} - -// Description describes the validation in plain text formatting. -func (validator int64StringBetweenValidator) Description(_ context.Context) string { - return fmt.Sprintf("integer value must be between %d and %d", validator.min, validator.max) -} - -// MarkdownDescription describes the validation in Markdown formatting. -func (validator int64StringBetweenValidator) MarkdownDescription(ctx context.Context) string { - return validator.Description(ctx) -} - -// Validate performs the validation. -func (validator int64StringBetweenValidator) Validate(ctx context.Context, request tfsdk.ValidateAttributeRequest, response *tfsdk.ValidateAttributeResponse) { - i, ok := validateInt64String(ctx, request, response) - - if !ok { - return - } - - if i < validator.min || i > validator.max { - response.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic( - request.AttributePath, - validator.Description(ctx), - fmt.Sprintf("%d", i), - )) - - return - } -} - -// Int64StringBetween returns an AttributeValidator which ensures that any configured -// attribute value: -// -// - Is a string, which represents a 64-bit integer. -// - Integer value is greater than or equal to the given minimum and less than or equal to the given maximum. -// -// Null (unconfigured) and unknown (known after apply) values are skipped. -func Int64StringBetween(min, max int64) tfsdk.AttributeValidator { - if min > max { - return nil - } - - return int64StringBetweenValidator{ - min: min, - max: max, - } -} diff --git a/internal/framework/validators/int64string_test.go b/internal/framework/validators/int64string_test.go deleted file mode 100644 index 1e1a59121651..000000000000 --- a/internal/framework/validators/int64string_test.go +++ /dev/null @@ -1,93 +0,0 @@ -package validators_test - -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/types" - fwvalidators "github.com/hashicorp/terraform-provider-aws/internal/framework/validators" -) - -func TestBetweenValidator(t *testing.T) { - t.Parallel() - - type testCase struct { - val attr.Value - min int64 - max int64 - expectError bool - } - tests := map[string]testCase{ - "not a String": { - val: types.BoolValue(true), - expectError: true, - }, - "unknown String": { - val: types.StringUnknown(), - min: 1, - max: 3, - }, - "null String": { - val: types.StringNull(), - min: 1, - max: 3, - }, - "invalid String": { - val: types.StringValue("test-value"), - min: 1, - max: 3, - expectError: true, - }, - "valid string": { - val: types.StringValue("2"), - min: 1, - max: 3, - }, - "valid string min": { - val: types.StringValue("1"), - min: 1, - max: 3, - }, - "valid string max": { - val: types.StringValue("3"), - min: 1, - max: 3, - }, - "too small string": { - val: types.StringValue("-1"), - min: 1, - max: 3, - expectError: true, - }, - "too large string": { - val: types.StringValue("42"), - min: 1, - max: 3, - expectError: true, - }, - } - - 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, - } - response := tfsdk.ValidateAttributeResponse{} - fwvalidators.Int64StringBetween(test.min, test.max).Validate(context.Background(), request, &response) - - if !response.Diagnostics.HasError() && test.expectError { - t.Fatal("expected error, got no error") - } - - if response.Diagnostics.HasError() && !test.expectError { - t.Fatalf("got unexpected error: %s", response.Diagnostics) - } - }) - } -} diff --git a/internal/framework/validators/type_validation.go b/internal/framework/validators/type_validation.go deleted file mode 100644 index 89e61f2c1808..000000000000 --- a/internal/framework/validators/type_validation.go +++ /dev/null @@ -1,53 +0,0 @@ -package validators - -import ( - "context" - "strconv" - - "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" - "github.com/hashicorp/terraform-plugin-framework/types" -) - -// validateInt64String ensures that the request contains a String value which represents a 64-bit integer. -func validateInt64String(ctx context.Context, request tfsdk.ValidateAttributeRequest, response *tfsdk.ValidateAttributeResponse) (int64, bool) { - s, ok := validateString(ctx, request, response) - - if !ok { - return 0, false - } - - i, err := strconv.ParseInt(s, 10, 64) - - if err != nil { - response.Diagnostics.Append(diag.NewAttributeErrorDiagnostic( - request.AttributePath, - "Invalid Attribute Value Format", - err.Error())) - return 0, false - } - - return i, true -} - -// validateString ensures that the request contains a String value. -func validateString(ctx context.Context, request tfsdk.ValidateAttributeRequest, response *tfsdk.ValidateAttributeResponse) (string, bool) { - t := request.AttributeConfig.Type(ctx) - if t != types.StringType { - response.Diagnostics.Append(validatordiag.InvalidAttributeTypeDiagnostic( - request.AttributePath, - "expected value of type string", - t.String(), - )) - return "", false - } - - s := request.AttributeConfig.(types.String) - - if s.IsUnknown() || s.IsNull() { - return "", false - } - - return s.ValueString(), true -} diff --git a/internal/framework/validators/type_validation_test.go b/internal/framework/validators/type_validation_test.go deleted file mode 100644 index c23dda069683..000000000000 --- a/internal/framework/validators/type_validation_test.go +++ /dev/null @@ -1,150 +0,0 @@ -package validators - -import ( - "context" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform-plugin-framework/path" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" - "github.com/hashicorp/terraform-plugin-framework/types" -) - -func TestValidateInt64String(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - request tfsdk.ValidateAttributeRequest - expectedInt64 int64 - expectedOk bool - }{ - "invalid-type": { - request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.BoolValue(true), - AttributePath: path.Root("test"), - AttributePathExpression: path.MatchRoot("test"), - }, - expectedInt64: 0, - expectedOk: false, - }, - "string-null": { - request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Int64Null(), - AttributePath: path.Root("test"), - AttributePathExpression: path.MatchRoot("test"), - }, - expectedInt64: 0, - expectedOk: false, - }, - "string-valid-value": { - request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.StringValue("43"), - AttributePath: path.Root("test"), - AttributePathExpression: path.MatchRoot("test"), - }, - expectedInt64: 43, - expectedOk: true, - }, - "string-invalid-value": { - request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.StringValue("test-value"), - AttributePath: path.Root("test"), - AttributePathExpression: path.MatchRoot("test"), - }, - expectedInt64: 0, - expectedOk: false, - }, - "string-unknown": { - request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Int64Unknown(), - AttributePath: path.Root("test"), - AttributePathExpression: path.MatchRoot("test"), - }, - expectedInt64: 0, - expectedOk: false, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - gotInt64, gotOk := validateInt64String(context.Background(), testCase.request, &tfsdk.ValidateAttributeResponse{}) - - if diff := cmp.Diff(gotInt64, testCase.expectedInt64); diff != "" { - t.Errorf("unexpected int64-string difference: %s", diff) - } - - if diff := cmp.Diff(gotOk, testCase.expectedOk); diff != "" { - t.Errorf("unexpected ok difference: %s", diff) - } - }) - } -} - -func TestValidateString(t *testing.T) { - t.Parallel() - - testCases := map[string]struct { - request tfsdk.ValidateAttributeRequest - expectedString string - expectedOk bool - }{ - "invalid-type": { - request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.BoolValue(true), - AttributePath: path.Root("test"), - AttributePathExpression: path.MatchRoot("test"), - }, - expectedString: "", - expectedOk: false, - }, - "string-null": { - request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Int64Null(), - AttributePath: path.Root("test"), - AttributePathExpression: path.MatchRoot("test"), - }, - expectedString: "", - expectedOk: false, - }, - "string-value": { - request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.StringValue("test-value"), - AttributePath: path.Root("test"), - AttributePathExpression: path.MatchRoot("test"), - }, - expectedString: "test-value", - expectedOk: true, - }, - "string-unknown": { - request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Int64Unknown(), - AttributePath: path.Root("test"), - AttributePathExpression: path.MatchRoot("test"), - }, - expectedString: "", - expectedOk: false, - }, - } - - for name, testCase := range testCases { - name, testCase := name, testCase - - t.Run(name, func(t *testing.T) { - t.Parallel() - - gotString, gotOk := validateString(context.Background(), testCase.request, &tfsdk.ValidateAttributeResponse{}) - - if diff := cmp.Diff(gotString, testCase.expectedString); diff != "" { - t.Errorf("unexpected string difference: %s", diff) - } - - if diff := cmp.Diff(gotOk, testCase.expectedOk); diff != "" { - t.Errorf("unexpected ok difference: %s", diff) - } - }) - } -} diff --git a/internal/provider/fwprovider/provider.go b/internal/provider/fwprovider/provider.go index 33c39fc160aa..c7f43a36c340 100644 --- a/internal/provider/fwprovider/provider.go +++ b/internal/provider/fwprovider/provider.go @@ -403,17 +403,15 @@ func (w *wrappedDataSource) Metadata(ctx context.Context, request datasource.Met w.inner.Metadata(ctx, request, response) } -func (w *wrappedDataSource) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { - if v, ok := w.inner.(datasource.DataSourceWithGetSchema); ok { - return v.GetSchema(ctx) +func (w *wrappedDataSource) Schema(ctx context.Context, request datasource.SchemaRequest, response *datasource.SchemaResponse) { + if v, ok := w.inner.(datasource.DataSourceWithSchema); ok { + v.Schema(ctx, request, response) + return } - - var diags diag.Diagnostics - diags.AddError( - "DataSource GetSchema Not Implemented", + response.Diagnostics.AddError( + "DataSource Schema Not Implemented", "This data source does not support get schema. Please contact the provider developer for additional information.", ) - return tfsdk.Schema{}, diags } func (w *wrappedDataSource) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) { @@ -442,17 +440,15 @@ func (w *wrappedResource) Metadata(ctx context.Context, request resource.Metadat w.inner.Metadata(ctx, request, response) } -func (w *wrappedResource) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) { - if v, ok := w.inner.(resource.ResourceWithGetSchema); ok { - return v.GetSchema(ctx) +func (w *wrappedResource) Schema(ctx context.Context, request resource.SchemaRequest, response *resource.SchemaResponse) { + if v, ok := w.inner.(resource.ResourceWithSchema); ok { + v.Schema(ctx, request, response) + return } - - var diags diag.Diagnostics - diags.AddError( - "Resource GetSchema Not Implemented", + response.Diagnostics.AddError( + "Resource Schema Not Implemented", "This resource does not support get schema. Please contact the provider developer for additional information.", ) - return tfsdk.Schema{}, diags } func (w *wrappedResource) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { diff --git a/internal/service/ec2/vpc_security_group_ingress_rule.go b/internal/service/ec2/vpc_security_group_ingress_rule.go index d380af55a421..3f562d7d55ff 100644 --- a/internal/service/ec2/vpc_security_group_ingress_rule.go +++ b/internal/service/ec2/vpc_security_group_ingress_rule.go @@ -11,10 +11,12 @@ import ( "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework-validators/resourcevalidator" - "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "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" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/flex" @@ -104,91 +106,77 @@ type resourceSecurityGroupRule struct { framework.ResourceWithConfigure } -// GetSchema returns the schema for this resource. -func (r *resourceSecurityGroupRule) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) { - schema := tfsdk.Schema{ - Attributes: map[string]tfsdk.Attribute{ - "arn": { - Type: types.StringType, +// Schema returns the schema for this resource. +func (r *resourceSecurityGroupRule) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "arn": schema.StringAttribute{ Computed: true, - PlanModifiers: []tfsdk.AttributePlanModifier{ - resource.UseStateForUnknown(), + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), }, }, - "cidr_ipv4": { - Type: types.StringType, + "cidr_ipv4": schema.StringAttribute{ Optional: true, - Validators: []tfsdk.AttributeValidator{ + Validators: []validator.String{ fwvalidators.IPv4CIDRNetworkAddress(), }, }, - "cidr_ipv6": { - Type: types.StringType, + "cidr_ipv6": schema.StringAttribute{ Optional: true, - Validators: []tfsdk.AttributeValidator{ + Validators: []validator.String{ fwvalidators.IPv6CIDRNetworkAddress(), }, }, - "description": { - Type: types.StringType, + "description": schema.StringAttribute{ Optional: true, }, - "from_port": { - Type: types.Int64Type, + "from_port": schema.Int64Attribute{ Optional: true, - Validators: []tfsdk.AttributeValidator{ + Validators: []validator.Int64{ int64validator.Between(-1, 65535), }, }, - "id": { - Type: types.StringType, + "id": schema.StringAttribute{ Computed: true, - PlanModifiers: []tfsdk.AttributePlanModifier{ - resource.UseStateForUnknown(), + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), }, }, - "ip_protocol": { - Type: types.StringType, + "ip_protocol": schema.StringAttribute{ Required: true, - PlanModifiers: []tfsdk.AttributePlanModifier{ + PlanModifiers: []planmodifier.String{ NormalizeIPProtocol(), }, }, - "prefix_list_id": { - Type: types.StringType, + "prefix_list_id": schema.StringAttribute{ Optional: true, }, - "referenced_security_group_id": { - Type: types.StringType, + "referenced_security_group_id": schema.StringAttribute{ Optional: true, }, - "security_group_id": { - Type: types.StringType, + "security_group_id": schema.StringAttribute{ Optional: true, - PlanModifiers: []tfsdk.AttributePlanModifier{ - resource.RequiresReplace(), + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), }, }, - "security_group_rule_id": { - Type: types.StringType, + "security_group_rule_id": schema.StringAttribute{ Computed: true, - PlanModifiers: []tfsdk.AttributePlanModifier{ - resource.UseStateForUnknown(), + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), }, }, "tags": tftags.TagsAttribute(), "tags_all": tftags.TagsAttributeComputedOnly(), - "to_port": { - Type: types.Int64Type, + "to_port": schema.Int64Attribute{ Optional: true, - Validators: []tfsdk.AttributeValidator{ + Validators: []validator.Int64{ int64validator.Between(-1, 65535), }, }, }, } - - return schema, nil } // Update is called to update the state of the resource. @@ -555,7 +543,7 @@ func (d *resourceSecurityGroupRuleData) sourceAttributeName() string { type normalizeIPProtocol struct{} -func NormalizeIPProtocol() tfsdk.AttributePlanModifier { +func NormalizeIPProtocol() planmodifier.String { return normalizeIPProtocol{} } @@ -567,37 +555,17 @@ func (m normalizeIPProtocol) MarkdownDescription(ctx context.Context) string { return m.Description(ctx) } -func (m normalizeIPProtocol) Modify(ctx context.Context, request tfsdk.ModifyAttributePlanRequest, response *tfsdk.ModifyAttributePlanResponse) { - if request.AttributeState == nil { - response.AttributePlan = request.AttributePlan - +func (m normalizeIPProtocol) PlanModifyString(ctx context.Context, request planmodifier.StringRequest, response *planmodifier.StringResponse) { + if request.StateValue.IsNull() { + response.PlanValue = request.PlanValue return } - // If the current value is semantically equivalent to the planned value - // then return the current value, else return the planned value. - - var planned types.String - - response.Diagnostics = append(response.Diagnostics, tfsdk.ValueAs(ctx, request.AttributePlan, &planned)...) - - if response.Diagnostics.HasError() { + // If the state value is semantically equivalent to the planned value + // then return the state value, else return the planned value. + if ProtocolForValue(request.StateValue.ValueString()) == ProtocolForValue(request.PlanValue.ValueString()) { + response.PlanValue = request.StateValue return } - - var current types.String - - response.Diagnostics = append(response.Diagnostics, tfsdk.ValueAs(ctx, request.AttributeState, ¤t)...) - - if response.Diagnostics.HasError() { - return - } - - if ProtocolForValue(current.ValueString()) == ProtocolForValue(planned.ValueString()) { - response.AttributePlan = request.AttributeState - - return - } - - response.AttributePlan = request.AttributePlan + response.PlanValue = request.PlanValue } diff --git a/internal/service/ec2/vpc_security_group_ingress_rule_test.go b/internal/service/ec2/vpc_security_group_ingress_rule_test.go index 6cf41e53b266..a7145c43de20 100644 --- a/internal/service/ec2/vpc_security_group_ingress_rule_test.go +++ b/internal/service/ec2/vpc_security_group_ingress_rule_test.go @@ -10,9 +10,8 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "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/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/types" sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -27,9 +26,9 @@ func TestNormalizeIPProtocol(t *testing.T) { t.Parallel() type testCase struct { - plannedValue attr.Value - currentValue attr.Value - expectedValue attr.Value + plannedValue types.String + currentValue types.String + expectedValue types.String expectError bool } tests := map[string]testCase{ @@ -54,15 +53,15 @@ func TestNormalizeIPProtocol(t *testing.T) { name, test := name, test t.Run(name, func(t *testing.T) { ctx := context.Background() - request := tfsdk.ModifyAttributePlanRequest{ - AttributePath: path.Root("test"), - AttributePlan: test.plannedValue, - AttributeState: test.currentValue, + request := planmodifier.StringRequest{ + Path: path.Root("test"), + PlanValue: test.plannedValue, + StateValue: test.currentValue, } - response := tfsdk.ModifyAttributePlanResponse{ - AttributePlan: request.AttributePlan, + response := planmodifier.StringResponse{ + PlanValue: request.PlanValue, } - tfec2.NormalizeIPProtocol().Modify(ctx, request, &response) + tfec2.NormalizeIPProtocol().PlanModifyString(ctx, request, &response) if !response.Diagnostics.HasError() && test.expectError { t.Fatal("expected error, got no error") @@ -72,7 +71,7 @@ func TestNormalizeIPProtocol(t *testing.T) { t.Fatalf("got unexpected error: %s", response.Diagnostics) } - if diff := cmp.Diff(response.AttributePlan, test.expectedValue); diff != "" { + if diff := cmp.Diff(response.PlanValue, test.expectedValue); diff != "" { t.Errorf("unexpected diff (+wanted, -got): %s", diff) } }) diff --git a/internal/service/globalaccelerator/accelerator_data_source.go b/internal/service/globalaccelerator/accelerator_data_source.go index 802f1dbe9119..b4e8f7233610 100644 --- a/internal/service/globalaccelerator/accelerator_data_source.go +++ b/internal/service/globalaccelerator/accelerator_data_source.go @@ -8,8 +8,7 @@ import ( "github.com/aws/aws-sdk-go/service/globalaccelerator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/framework" @@ -36,65 +35,57 @@ func (d *dataSourceAccelerator) Metadata(_ context.Context, request datasource.M response.TypeName = "aws_globalaccelerator_accelerator" } -// GetSchema returns the schema for this data source. -func (d *dataSourceAccelerator) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) { - schema := tfsdk.Schema{ - Attributes: map[string]tfsdk.Attribute{ - "arn": { - Type: fwtypes.ARNType, - Optional: true, - Computed: true, +// Schema returns the schema for this data source. +func (d *dataSourceAccelerator) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "arn": schema.StringAttribute{ + CustomType: fwtypes.ARNType, + Optional: true, + Computed: true, }, - "attributes": { - Type: types.ListType{ElemType: types.ObjectType{ + "attributes": schema.ListAttribute{ + ElementType: types.ObjectType{ AttrTypes: map[string]attr.Type{ "flow_logs_enabled": types.BoolType, "flow_logs_s3_bucket": types.StringType, "flow_logs_s3_prefix": types.StringType, }, - }}, + }, Computed: true, }, - "dns_name": { - Type: types.StringType, + "dns_name": schema.StringAttribute{ Computed: true, }, - "enabled": { - Type: types.BoolType, + "enabled": schema.BoolAttribute{ Computed: true, }, - "hosted_zone_id": { - Type: types.StringType, + "hosted_zone_id": schema.StringAttribute{ Computed: true, }, - "id": { - Type: types.StringType, + "id": schema.StringAttribute{ Optional: true, Computed: true, }, - "ip_address_type": { - Type: types.StringType, + "ip_address_type": schema.StringAttribute{ Computed: true, }, - "ip_sets": { - Type: types.ListType{ElemType: types.ObjectType{ + "ip_sets": schema.ListAttribute{ + ElementType: types.ObjectType{ AttrTypes: map[string]attr.Type{ "ip_addresses": types.ListType{ElemType: types.StringType}, "ip_family": types.StringType, }, - }}, + }, Computed: true, }, - "name": { - Type: types.StringType, + "name": schema.StringAttribute{ Optional: true, Computed: true, }, "tags": tftags.TagsAttributeComputedOnly(), }, } - - return schema, nil } // Read is called when the provider must read data source values in order to update state. diff --git a/internal/service/medialive/multiplex_program.go b/internal/service/medialive/multiplex_program.go index cbe58de0f65c..75ebfca40834 100644 --- a/internal/service/medialive/multiplex_program.go +++ b/internal/service/medialive/multiplex_program.go @@ -9,11 +9,16 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/medialive" mltypes "github.com/aws/aws-sdk-go-v2/service/medialive/types" + "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" resourceHelper "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/create" @@ -43,129 +48,131 @@ func (m *multiplexProgram) Metadata(_ context.Context, request resource.Metadata response.TypeName = "aws_medialive_multiplex_program" } -func (m *multiplexProgram) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) { - schema := tfsdk.Schema{ - Attributes: map[string]tfsdk.Attribute{ +func (m *multiplexProgram) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ "id": framework.IDAttribute(), - "multiplex_id": { - Type: types.StringType, + "multiplex_id": schema.StringAttribute{ Required: true, - PlanModifiers: tfsdk.AttributePlanModifiers{ - resource.RequiresReplace(), + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), }, }, - "program_name": { - Type: types.StringType, + "program_name": schema.StringAttribute{ Required: true, - PlanModifiers: tfsdk.AttributePlanModifiers{ - resource.RequiresReplace(), + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), }, }, }, - Blocks: map[string]tfsdk.Block{ - "multiplex_program_settings": { - NestingMode: tfsdk.BlockNestingModeList, - MinItems: 1, - MaxItems: 1, - Attributes: map[string]tfsdk.Attribute{ - "program_number": { - Type: types.Int64Type, - Required: true, - }, - "preferred_channel_pipeline": { - Type: types.StringType, - Required: true, - Validators: []tfsdk.AttributeValidator{ - enum.FrameworkValidate[mltypes.PreferredChannelPipeline](), - }, - }, + Blocks: map[string]schema.Block{ + "multiplex_program_settings": schema.ListNestedBlock{ + Validators: []validator.List{ + listvalidator.SizeAtLeast(1), + listvalidator.SizeAtMost(1), }, - Blocks: map[string]tfsdk.Block{ - "service_descriptor": { - NestingMode: tfsdk.BlockNestingModeList, - MaxItems: 1, - Attributes: map[string]tfsdk.Attribute{ - "provider_name": { - Type: types.StringType, - Required: true, - }, - "service_name": { - Type: types.StringType, - Required: true, + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "program_number": schema.Int64Attribute{ + Required: true, + }, + "preferred_channel_pipeline": schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + enum.FrameworkValidate[mltypes.PreferredChannelPipeline](), }, }, }, - "video_settings": { - NestingMode: tfsdk.BlockNestingModeList, - MaxItems: 1, - Attributes: map[string]tfsdk.Attribute{ - "constant_bitrate": { - Type: types.Int64Type, - Optional: true, - Computed: true, - PlanModifiers: []tfsdk.AttributePlanModifier{ - resource.UseStateForUnknown(), - }, + Blocks: map[string]schema.Block{ + "service_descriptor": schema.ListNestedBlock{ + Validators: []validator.List{ + listvalidator.SizeAtMost(1), }, - }, - Blocks: map[string]tfsdk.Block{ - "statemux_settings": { - DeprecationMessage: "Configure statmux_settings instead of statemux_settings. This block will be removed in the next major version of the provider.", - NestingMode: tfsdk.BlockNestingModeList, - MaxItems: 1, - Attributes: map[string]tfsdk.Attribute{ - "minimum_bitrate": { - Type: types.Int64Type, - Optional: true, - Computed: true, - PlanModifiers: []tfsdk.AttributePlanModifier{ - resource.UseStateForUnknown(), - }, + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "provider_name": schema.StringAttribute{ + Required: true, }, - "maximum_bitrate": { - Type: types.Int64Type, - Optional: true, - Computed: true, - PlanModifiers: []tfsdk.AttributePlanModifier{ - resource.UseStateForUnknown(), - }, - }, - "priority": { - Type: types.Int64Type, - Optional: true, - Computed: true, - PlanModifiers: []tfsdk.AttributePlanModifier{ - resource.UseStateForUnknown(), - }, + "service_name": schema.StringAttribute{ + Required: true, }, }, }, - "statmux_settings": { - NestingMode: tfsdk.BlockNestingModeList, - MaxItems: 1, - Attributes: map[string]tfsdk.Attribute{ - "minimum_bitrate": { - Type: types.Int64Type, + }, + "video_settings": schema.ListNestedBlock{ + Validators: []validator.List{ + listvalidator.SizeAtMost(1), + }, + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "constant_bitrate": schema.Int64Attribute{ Optional: true, Computed: true, - PlanModifiers: []tfsdk.AttributePlanModifier{ - resource.UseStateForUnknown(), + PlanModifiers: []planmodifier.Int64{ + int64planmodifier.UseStateForUnknown(), }, }, - "maximum_bitrate": { - Type: types.Int64Type, - Optional: true, - Computed: true, - PlanModifiers: []tfsdk.AttributePlanModifier{ - resource.UseStateForUnknown(), + }, + Blocks: map[string]schema.Block{ + "statemux_settings": schema.ListNestedBlock{ + DeprecationMessage: "Configure statmux_settings instead of statemux_settings. This block will be removed in the next major version of the provider.", + Validators: []validator.List{ + listvalidator.SizeAtMost(1), + }, + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "minimum_bitrate": schema.Int64Attribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Int64{ + int64planmodifier.UseStateForUnknown(), + }, + }, + "maximum_bitrate": schema.Int64Attribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Int64{ + int64planmodifier.UseStateForUnknown(), + }, + }, + "priority": schema.Int64Attribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Int64{ + int64planmodifier.UseStateForUnknown(), + }, + }, + }, }, }, - "priority": { - Type: types.Int64Type, - Optional: true, - Computed: true, - PlanModifiers: []tfsdk.AttributePlanModifier{ - resource.UseStateForUnknown(), + "statmux_settings": schema.ListNestedBlock{ + Validators: []validator.List{ + listvalidator.SizeAtMost(1), + }, + NestedObject: schema.NestedBlockObject{ + Attributes: map[string]schema.Attribute{ + "minimum_bitrate": schema.Int64Attribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Int64{ + int64planmodifier.UseStateForUnknown(), + }, + }, + "maximum_bitrate": schema.Int64Attribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Int64{ + int64planmodifier.UseStateForUnknown(), + }, + }, + "priority": schema.Int64Attribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Int64{ + int64planmodifier.UseStateForUnknown(), + }, + }, + }, }, }, }, @@ -176,8 +183,6 @@ func (m *multiplexProgram) GetSchema(context.Context) (tfsdk.Schema, diag.Diagno }, }, } - - return schema, nil } func (m *multiplexProgram) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { diff --git a/internal/service/meta/arn_data_source.go b/internal/service/meta/arn_data_source.go index 33be54d66b70..488135aa0ed7 100644 --- a/internal/service/meta/arn_data_source.go +++ b/internal/service/meta/arn_data_source.go @@ -6,8 +6,7 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-provider-aws/internal/framework" fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" @@ -32,43 +31,35 @@ func (d *dataSourceARN) Metadata(_ context.Context, request datasource.MetadataR response.TypeName = "aws_arn" } -// GetSchema returns the schema for this data source. -func (d *dataSourceARN) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) { - schema := tfsdk.Schema{ - Attributes: map[string]tfsdk.Attribute{ - "account": { - Type: types.StringType, +// Schema returns the schema for this data source. +func (d *dataSourceARN) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "account": schema.StringAttribute{ Computed: true, }, - "arn": { - Type: fwtypes.ARNType, - Required: true, + "arn": schema.StringAttribute{ + CustomType: fwtypes.ARNType, + Required: true, }, - "id": { - Type: types.StringType, + "id": schema.StringAttribute{ Optional: true, Computed: true, }, - "partition": { - Type: types.StringType, + "partition": schema.StringAttribute{ Computed: true, }, - "region": { - Type: types.StringType, + "region": schema.StringAttribute{ Computed: true, }, - "resource": { - Type: types.StringType, + "resource": schema.StringAttribute{ Computed: true, }, - "service": { - Type: types.StringType, + "service": schema.StringAttribute{ Computed: true, }, }, } - - return schema, nil } // Read is called when the provider must read data source values in order to update state. diff --git a/internal/service/meta/billing_service_account_data_source.go b/internal/service/meta/billing_service_account_data_source.go index 8be692f62cbb..f5e589a20c08 100644 --- a/internal/service/meta/billing_service_account_data_source.go +++ b/internal/service/meta/billing_service_account_data_source.go @@ -5,8 +5,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-provider-aws/internal/framework" ) @@ -30,23 +29,19 @@ func (d *dataSourceBillingServiceAccount) Metadata(_ context.Context, request da response.TypeName = "aws_billing_service_account" } -// GetSchema returns the schema for this data source. -func (d *dataSourceBillingServiceAccount) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) { - schema := tfsdk.Schema{ - Attributes: map[string]tfsdk.Attribute{ - "arn": { - Type: types.StringType, +// Schema returns the schema for this data source. +func (d *dataSourceBillingServiceAccount) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "arn": schema.StringAttribute{ Computed: true, }, - "id": { - Type: types.StringType, + "id": schema.StringAttribute{ Optional: true, Computed: true, }, }, } - - return schema, nil } // Read is called when the provider must read data source values in order to update state. diff --git a/internal/service/meta/default_tags_data_source.go b/internal/service/meta/default_tags_data_source.go index 014fa45cd705..cb2f29d38760 100644 --- a/internal/service/meta/default_tags_data_source.go +++ b/internal/service/meta/default_tags_data_source.go @@ -6,8 +6,7 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/framework" @@ -33,20 +32,17 @@ func (d *dataSourceDefaultTags) Metadata(_ context.Context, request datasource.M response.TypeName = "aws_default_tags" } -// GetSchema returns the schema for this data source. -func (d *dataSourceDefaultTags) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) { - schema := tfsdk.Schema{ - Attributes: map[string]tfsdk.Attribute{ - "id": { - Type: types.StringType, +// Schema returns the schema for this data source. +func (d *dataSourceDefaultTags) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ Optional: true, Computed: true, }, "tags": tftags.TagsAttributeComputedOnly(), }, } - - return schema, nil } // Read is called when the provider must read data source values in order to update state. diff --git a/internal/service/meta/ip_ranges_data_source.go b/internal/service/meta/ip_ranges_data_source.go index 284774479c65..86cfe5b5292d 100644 --- a/internal/service/meta/ip_ranges_data_source.go +++ b/internal/service/meta/ip_ranges_data_source.go @@ -12,8 +12,7 @@ import ( cleanhttp "github.com/hashicorp/go-cleanhttp" "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/framework" @@ -40,47 +39,41 @@ func (d *dataSourceIPRanges) Metadata(_ context.Context, request datasource.Meta response.TypeName = "aws_ip_ranges" } -// GetSchema returns the schema for this data source. -func (d *dataSourceIPRanges) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) { - schema := tfsdk.Schema{ - Attributes: map[string]tfsdk.Attribute{ - "cidr_blocks": { - Type: types.ListType{ElemType: types.StringType}, - Computed: true, +// Schema returns the schema for this data source. +func (d *dataSourceIPRanges) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "cidr_blocks": schema.ListAttribute{ + ElementType: types.StringType, + Computed: true, }, - "create_date": { - Type: types.StringType, + "create_date": schema.StringAttribute{ Computed: true, }, - "id": { - Type: types.StringType, + "id": schema.StringAttribute{ Optional: true, Computed: true, }, - "ipv6_cidr_blocks": { - Type: types.ListType{ElemType: types.StringType}, - Computed: true, + "ipv6_cidr_blocks": schema.ListAttribute{ + ElementType: types.StringType, + Computed: true, }, - "regions": { - Type: types.SetType{ElemType: types.StringType}, - Optional: true, + "regions": schema.SetAttribute{ + ElementType: types.StringType, + Optional: true, }, - "services": { - Type: types.SetType{ElemType: types.StringType}, - Required: true, + "services": schema.SetAttribute{ + ElementType: types.StringType, + Required: true, }, - "sync_token": { - Type: types.Int64Type, + "sync_token": schema.Int64Attribute{ Computed: true, }, - "url": { - Type: types.StringType, + "url": schema.StringAttribute{ Optional: true, }, }, } - - return schema, nil } // Read is called when the provider must read data source values in order to update state. diff --git a/internal/service/meta/partition_data_source.go b/internal/service/meta/partition_data_source.go index 3d486adbf90c..004da956142c 100644 --- a/internal/service/meta/partition_data_source.go +++ b/internal/service/meta/partition_data_source.go @@ -4,8 +4,7 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-provider-aws/internal/framework" ) @@ -29,31 +28,25 @@ func (d *dataSourcePartition) Metadata(_ context.Context, request datasource.Met response.TypeName = "aws_partition" } -// GetSchema returns the schema for this data source. -func (d *dataSourcePartition) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) { - schema := tfsdk.Schema{ - Attributes: map[string]tfsdk.Attribute{ - "dns_suffix": { - Type: types.StringType, +// Schema returns the schema for this data source. +func (d *dataSourcePartition) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "dns_suffix": schema.StringAttribute{ Computed: true, }, - "id": { - Type: types.StringType, + "id": schema.StringAttribute{ Optional: true, Computed: true, }, - "partition": { - Type: types.StringType, + "partition": schema.StringAttribute{ Computed: true, }, - "reverse_dns_prefix": { - Type: types.StringType, + "reverse_dns_prefix": schema.StringAttribute{ Computed: true, }, }, } - - return schema, nil } // Read is called when the provider must read data source values in order to update state. diff --git a/internal/service/meta/region_data_source.go b/internal/service/meta/region_data_source.go index d492d92c9b6b..b74d6c051659 100644 --- a/internal/service/meta/region_data_source.go +++ b/internal/service/meta/region_data_source.go @@ -7,8 +7,7 @@ import ( "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-provider-aws/internal/framework" ) @@ -32,33 +31,27 @@ func (d *dataSourceRegion) Metadata(_ context.Context, request datasource.Metada response.TypeName = "aws_region" } -// GetSchema returns the schema for this data source. -func (d *dataSourceRegion) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) { - schema := tfsdk.Schema{ - Attributes: map[string]tfsdk.Attribute{ - "description": { - Type: types.StringType, +// Schema returns the schema for this data source. +func (d *dataSourceRegion) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "description": schema.StringAttribute{ Computed: true, }, - "endpoint": { - Type: types.StringType, + "endpoint": schema.StringAttribute{ Optional: true, Computed: true, }, - "id": { - Type: types.StringType, + "id": schema.StringAttribute{ Optional: true, Computed: true, }, - "name": { - Type: types.StringType, + "name": schema.StringAttribute{ Optional: true, Computed: true, }, }, } - - return schema, nil } // Read is called when the provider must read data source values in order to update state. diff --git a/internal/service/meta/regions_data_source.go b/internal/service/meta/regions_data_source.go index a5b5599b1003..65ed838fb15b 100644 --- a/internal/service/meta/regions_data_source.go +++ b/internal/service/meta/regions_data_source.go @@ -6,8 +6,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/framework" @@ -33,30 +32,26 @@ func (d *dataSourceRegions) Metadata(_ context.Context, request datasource.Metad response.TypeName = "aws_regions" } -// GetSchema returns the schema for this data source. -func (d *dataSourceRegions) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) { - schema := tfsdk.Schema{ - Attributes: map[string]tfsdk.Attribute{ - "all_regions": { - Type: types.BoolType, +// Schema returns the schema for this data source. +func (d *dataSourceRegions) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "all_regions": schema.BoolAttribute{ Optional: true, }, - "id": { - Type: types.StringType, + "id": schema.StringAttribute{ Optional: true, Computed: true, }, - "names": { - Type: types.SetType{ElemType: types.StringType}, - Computed: true, + "names": schema.SetAttribute{ + ElementType: types.StringType, + Computed: true, }, }, - Blocks: map[string]tfsdk.Block{ + Blocks: map[string]schema.Block{ "filter": tfec2.CustomFiltersBlock(), }, } - - return schema, nil } // Read is called when the provider must read data source values in order to update state. diff --git a/internal/service/meta/service_data_source.go b/internal/service/meta/service_data_source.go index 090f6a698db8..1057a6011f87 100644 --- a/internal/service/meta/service_data_source.go +++ b/internal/service/meta/service_data_source.go @@ -7,8 +7,7 @@ import ( "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-provider-aws/internal/framework" "github.com/hashicorp/terraform-provider-aws/internal/slices" @@ -33,52 +32,42 @@ func (d *dataSourceService) Metadata(_ context.Context, request datasource.Metad response.TypeName = "aws_service" } -// GetSchema returns the schema for this data source. -func (d *dataSourceService) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) { - schema := tfsdk.Schema{ - Attributes: map[string]tfsdk.Attribute{ - "dns_name": { - Type: types.StringType, +// Schema returns the schema for this data source. +func (d *dataSourceService) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "dns_name": schema.StringAttribute{ Optional: true, Computed: true, }, - "id": { - Type: types.StringType, + "id": schema.StringAttribute{ Optional: true, Computed: true, }, - "partition": { - Type: types.StringType, + "partition": schema.StringAttribute{ Computed: true, }, - "region": { - Type: types.StringType, + "region": schema.StringAttribute{ Optional: true, Computed: true, }, - "reverse_dns_name": { - Type: types.StringType, + "reverse_dns_name": schema.StringAttribute{ Optional: true, Computed: true, }, - "reverse_dns_prefix": { - Type: types.StringType, + "reverse_dns_prefix": schema.StringAttribute{ Optional: true, Computed: true, }, - "service_id": { - Type: types.StringType, + "service_id": schema.StringAttribute{ Optional: true, Computed: true, }, - "supported": { - Type: types.BoolType, + "supported": schema.BoolAttribute{ Computed: true, }, }, } - - return schema, nil } // Read is called when the provider must read data source values in order to update state. diff --git a/internal/service/simpledb/domain.go b/internal/service/simpledb/domain.go index dbbab53904f4..c8ba6d7a969c 100644 --- a/internal/service/simpledb/domain.go +++ b/internal/service/simpledb/domain.go @@ -7,10 +7,11 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/simpledb" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" - "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "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" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" sdkresource "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -39,22 +40,19 @@ func (r *resourceDomain) Metadata(_ context.Context, request resource.MetadataRe response.TypeName = "aws_simpledb_domain" } -// GetSchema returns the schema for this resource. -func (r *resourceDomain) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) { - schema := tfsdk.Schema{ - Attributes: map[string]tfsdk.Attribute{ +// Schema returns the schema for this resource. +func (r *resourceDomain) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ "id": framework.IDAttribute(), - "name": { - Type: types.StringType, + "name": schema.StringAttribute{ Required: true, - PlanModifiers: tfsdk.AttributePlanModifiers{ - resource.RequiresReplace(), + PlanModifiers: []planmodifier.String{ + stringplanmodifier.RequiresReplace(), }, }, }, } - - return schema, nil } // Create is called when the provider must create a new resource. diff --git a/internal/service/sts/caller_identity_data_source.go b/internal/service/sts/caller_identity_data_source.go index fdaaf78c9b84..dd96b8b37ba9 100644 --- a/internal/service/sts/caller_identity_data_source.go +++ b/internal/service/sts/caller_identity_data_source.go @@ -5,8 +5,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/diag" - "github.com/hashicorp/terraform-plugin-framework/tfsdk" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/framework" @@ -31,31 +30,25 @@ func (d *dataSourceCallerIdentity) Metadata(_ context.Context, request datasourc response.TypeName = "aws_caller_identity" } -// GetSchema returns the schema for this data source. -func (d *dataSourceCallerIdentity) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) { - schema := tfsdk.Schema{ - Attributes: map[string]tfsdk.Attribute{ - "account_id": { - Type: types.StringType, +// Schema returns the schema for this data source. +func (d *dataSourceCallerIdentity) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "account_id": schema.StringAttribute{ Computed: true, }, - "arn": { - Type: types.StringType, + "arn": schema.StringAttribute{ Computed: true, }, - "id": { - Type: types.StringType, + "id": schema.StringAttribute{ Optional: true, Computed: true, }, - "user_id": { - Type: types.StringType, + "user_id": schema.StringAttribute{ Computed: true, }, }, } - - return schema, nil } // Read is called when the provider must read data source values in order to update state. diff --git a/internal/sweep/framework.go b/internal/sweep/framework.go index d6d4761b21de..5a12dbacc26b 100644 --- a/internal/sweep/framework.go +++ b/internal/sweep/framework.go @@ -10,7 +10,6 @@ import ( "strings" "time" - "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/path" fwresource "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" @@ -70,22 +69,20 @@ func DeleteFrameworkResource(factory func(context.Context) (fwresource.ResourceW resource.Configure(ctx, fwresource.ConfigureRequest{ProviderData: meta}, &fwresource.ConfigureResponse{}) - var schema tfsdk.Schema - var diags diag.Diagnostics - if v, ok := resource.(fwresource.ResourceWithGetSchema); ok { - schema, diags = v.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 GetSchema method") + return errors.New("resource does not implement Schema method") } // Simple Terraform State that contains just the resource ID. 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, } state.SetAttribute(ctx, path.Root("id"), id) response := fwresource.DeleteResponse{} diff --git a/tools/tfsdk2fw/datasource.tmpl b/tools/tfsdk2fw/datasource.tmpl index ef265cf43fb0..35f25ca15cc7 100644 --- a/tools/tfsdk2fw/datasource.tmpl +++ b/tools/tfsdk2fw/datasource.tmpl @@ -33,11 +33,9 @@ func (d *dataSource{{ .Name }}) Metadata(_ context.Context, request datasource.M response.TypeName = "{{ .TFTypeName }}" } -// GetSchema returns the schema for this data source. -func (d *dataSource{{ .Name }}) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) { - schema := {{ .Schema }} - - return schema, nil +// Schema returns the schema for this data source. +func (d *dataSource{{ .Name }}) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = {{ .Schema }} } // Read is called when the provider must read data source values in order to update state. diff --git a/tools/tfsdk2fw/resource.tmpl b/tools/tfsdk2fw/resource.tmpl index 7bd775ab4b6f..793770d8f034 100644 --- a/tools/tfsdk2fw/resource.tmpl +++ b/tools/tfsdk2fw/resource.tmpl @@ -35,11 +35,9 @@ func (r *resource{{ .Name }}) Metadata(_ context.Context, request resource.Metad response.TypeName = "{{ .TFTypeName }}" } -// GetSchema returns the schema for this resource. -func (r *resource{{ .Name }}) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) { - schema := {{ .Schema }} - - return schema, nil +// Schema returns the schema for this resource. +func (r *resource{{ .Name }}) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = {{ .Schema }} } // Create is called when the provider must create a new resource. From 4e8075db401cfe053920e21e773881e8e04e7010 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 5 Dec 2022 10:51:36 -0500 Subject: [PATCH 5/5] r/aws_medialive_multiplex_program: handle not found exception on delete --- internal/service/medialive/multiplex_program.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/service/medialive/multiplex_program.go b/internal/service/medialive/multiplex_program.go index 75ebfca40834..3b6bca2edf79 100644 --- a/internal/service/medialive/multiplex_program.go +++ b/internal/service/medialive/multiplex_program.go @@ -399,14 +399,16 @@ func (m *multiplexProgram) Delete(ctx context.Context, req resource.DeleteReques }) if err != nil { + var nfe *mltypes.NotFoundException + if errors.As(err, &nfe) { + return + } resp.Diagnostics.AddError( create.ProblemStandardMessage(names.MediaLive, create.ErrActionDeleting, ResNameMultiplexProgram, state.ProgramName.String(), nil), err.Error(), ) return } - - resp.State.RemoveResource(ctx) } func (m *multiplexProgram) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {