diff --git a/docs/skaff.md b/docs/skaff.md index 0f6b742e5ed..87939a13e9b 100644 --- a/docs/skaff.md +++ b/docs/skaff.md @@ -106,7 +106,6 @@ Flags: -n, --name string name of the entity -p, --plugin-sdkv2 generate for Terraform Plugin SDK V2 -s, --snakename string if skaff doesn't get it right, explicitly give name in snake case (e.g., db_vpc_instance) - -o, --v1 generate for AWS Go SDK v1 (some existing services) ``` ### Function @@ -154,5 +153,4 @@ Flags: -n, --name string name of the entity -p, --plugin-sdkv2 generate for Terraform Plugin SDK V2 -s, --snakename string if skaff doesn't get it right, explicitly give name in snake case (e.g., db_vpc_instance) - -o, --v1 generate for AWS Go SDK v1 (some existing services) ``` diff --git a/skaff/cmd/datasource.go b/skaff/cmd/datasource.go index 19b03a07fe9..5ba7af8fc9b 100644 --- a/skaff/cmd/datasource.go +++ b/skaff/cmd/datasource.go @@ -12,7 +12,7 @@ var datasourceCmd = &cobra.Command{ Use: "datasource", Short: "Create scaffolding for a data source", RunE: func(cmd *cobra.Command, args []string) error { - return datasource.Create(name, snakeName, !clearComments, force, !v1, !pluginSDKV2, includeTags) + return datasource.Create(name, snakeName, !clearComments, force, !pluginSDKV2, includeTags) }, } @@ -22,7 +22,6 @@ func init() { datasourceCmd.Flags().BoolVarP(&clearComments, "clear-comments", "c", false, "do not include instructional comments in source") datasourceCmd.Flags().StringVarP(&name, "name", "n", "", "name of the entity") datasourceCmd.Flags().BoolVarP(&force, "force", "f", false, "force creation, overwriting existing files") - datasourceCmd.Flags().BoolVarP(&v1, "v1", "o", false, "generate for AWS Go SDK v1 (some existing services)") datasourceCmd.Flags().BoolVarP(&pluginSDKV2, "plugin-sdkv2", "p", false, "generate for Terraform Plugin SDK V2") datasourceCmd.Flags().BoolVarP(&includeTags, "include-tags", "t", false, "Indicate that this resource has tags and the code for tagging should be generated") } diff --git a/skaff/cmd/resource.go b/skaff/cmd/resource.go index 3d07a069267..62f55fae7ed 100644 --- a/skaff/cmd/resource.go +++ b/skaff/cmd/resource.go @@ -13,7 +13,6 @@ var ( clearComments bool name string force bool - v1 bool pluginSDKV2 bool includeTags bool ) @@ -22,7 +21,7 @@ var resourceCmd = &cobra.Command{ Use: "resource", Short: "Create scaffolding for a resource", RunE: func(cmd *cobra.Command, args []string) error { - return resource.Create(name, snakeName, !clearComments, force, !v1, !pluginSDKV2, includeTags) + return resource.Create(name, snakeName, !clearComments, force, !pluginSDKV2, includeTags) }, } @@ -32,7 +31,6 @@ func init() { resourceCmd.Flags().BoolVarP(&clearComments, "clear-comments", "c", false, "do not include instructional comments in source") resourceCmd.Flags().StringVarP(&name, "name", "n", "", "name of the entity") resourceCmd.Flags().BoolVarP(&force, "force", "f", false, "force creation, overwriting existing files") - resourceCmd.Flags().BoolVarP(&v1, "v1", "o", false, "generate for AWS Go SDK v1 (some existing services)") resourceCmd.Flags().BoolVarP(&pluginSDKV2, "plugin-sdkv2", "p", false, "generate for Terraform Plugin SDK V2") resourceCmd.Flags().BoolVarP(&includeTags, "include-tags", "t", false, "Indicate that this resource has tags and the code for tagging should be generated") } diff --git a/skaff/convert/convert.go b/skaff/convert/convert.go index 7847979305d..71d8261dc06 100644 --- a/skaff/convert/convert.go +++ b/skaff/convert/convert.go @@ -11,22 +11,6 @@ import ( "github.com/YakDriver/regexache" ) -// ToSnakeCase converts a camel cased string to snake case -// -// If the override argument is a non-empty string, its value is returned -// unchanged. -func ToSnakeCase(upper string, override string) string { - if override != "" { - return override - } - - re := regexache.MustCompile(`([a-z])([A-Z]{2,})`) - upper = re.ReplaceAllString(upper, `${1}_${2}`) - - re2 := regexache.MustCompile(`([A-Z][a-z])`) - return strings.TrimPrefix(strings.ToLower(re2.ReplaceAllString(upper, `_$1`)), "_") -} - // ToHumanResName converts a camel cased string to a human readable name func ToHumanResName(upper string) string { re := regexache.MustCompile(`([a-z])([A-Z]{2,})`) diff --git a/skaff/convert/convert_test.go b/skaff/convert/convert_test.go index 2e0cfe9d322..c532fc33359 100644 --- a/skaff/convert/convert_test.go +++ b/skaff/convert/convert_test.go @@ -7,55 +7,6 @@ import ( "testing" ) -func TestToSnakeName(t *testing.T) { - testCases := []struct { - TestName string - Input string - Expected string - }{ - { - TestName: "empty", - Input: "", - Expected: "", - }, - { - TestName: "simple", - Input: "Cheese", - Expected: "cheese", - }, - { - TestName: "two word", - Input: "CityLights", - Expected: "city_lights", - }, - { - TestName: "three word", - Input: "OpenEndResource", - Expected: "open_end_resource", - }, - { - TestName: "initialism", - Input: "DBInstance", - Expected: "db_instance", - }, - { - TestName: "initialisms", - Input: "DBInstanceVPCEndpoint", - Expected: "db_instance_vpc_endpoint", - }, - } - - for _, testCase := range testCases { - t.Run(testCase.TestName, func(t *testing.T) { - got := ToSnakeCase(testCase.Input, "") - - if got != testCase.Expected { - t.Errorf("got %s, expected %s", got, testCase.Expected) - } - }) - } -} - func TestToHumanResName(t *testing.T) { testCases := []struct { TestName string diff --git a/skaff/datasource/datasource.go b/skaff/datasource/datasource.go index 58f2bfb535f..988ed0bf6d0 100644 --- a/skaff/datasource/datasource.go +++ b/skaff/datasource/datasource.go @@ -14,6 +14,7 @@ import ( "strings" "text/template" + "github.com/hashicorp/terraform-provider-aws/names" "github.com/hashicorp/terraform-provider-aws/names/data" "github.com/hashicorp/terraform-provider-aws/skaff/convert" ) @@ -42,13 +43,12 @@ type TemplateData struct { Service string ServiceLower string AWSServiceName string - AWSGoSDKV2 bool PluginFramework bool HumanDataSourceName string ProviderResourceName string } -func Create(dsName, snakeName string, comments, force, v2, pluginFramework, tags bool) error { +func Create(dsName, snakeName string, comments, force, pluginFramework, tags bool) error { wd, err := os.Getwd() // os.Getenv("GOPACKAGE") not available since this is not run with go generate if err != nil { return fmt.Errorf("error reading working directory: %s", err) @@ -68,7 +68,9 @@ func Create(dsName, snakeName string, comments, force, v2, pluginFramework, tags return fmt.Errorf("error checking: snake name should be all lower case with underscores, if needed (e.g., db_instance)") } - snakeName = convert.ToSnakeCase(dsName, snakeName) + if snakeName == "" { + snakeName = names.ToSnakeCase(dsName) + } service, err := data.LookupService(servicePackage) if err != nil { @@ -87,7 +89,6 @@ func Create(dsName, snakeName string, comments, force, v2, pluginFramework, tags Service: service.ProviderNameUpper(), ServiceLower: strings.ToLower(service.ProviderNameUpper()), AWSServiceName: service.FullHumanFriendly(), - AWSGoSDKV2: v2, PluginFramework: pluginFramework, HumanDataSourceName: convert.ToHumanResName(dsName), ProviderResourceName: convert.ToProviderResourceName(servicePackage, snakeName), diff --git a/skaff/datasource/datasource.gtpl b/skaff/datasource/datasource.gtpl index 516838179e6..e330f1ddf32 100644 --- a/skaff/datasource/datasource.gtpl +++ b/skaff/datasource/datasource.gtpl @@ -31,8 +31,6 @@ import ( // // The provider linter wants your imports to be in two groups: first, // standard library (i.e., "fmt" or "strings"), second, everything else. -{{- end }} -{{- if and .IncludeComments .AWSGoSDKV2 }} // // Also, AWS Go SDK v2 may handle nested structures differently than v1, // using the services/{{ .SDKPackage }}/types package. If so, you'll @@ -47,14 +45,10 @@ import ( "regexp" "strings" "time" -{{ if .AWSGoSDKV2 }} + "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/{{ .SDKPackage }}" "github.com/aws/aws-sdk-go-v2/service/{{ .SDKPackage }}/types" -{{- else }} - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/{{ .SDKPackage }}" -{{- end }} "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -172,7 +166,7 @@ func dataSource{{ .DataSource }}Read(ctx context.Context, d *schema.ResourceData // TIP: -- 1. Get a client connection to the relevant service {{- end }} - conn := meta.(*conns.AWSClient).{{ .Service }}{{ if .AWSGoSDKV2 }}Client(ctx){{ else }}Conn(ctx){{ end }} + conn := meta.(*conns.AWSClient).{{ .Service }}Client(ctx) {{ if .IncludeComments }} // TIP: -- 2. Get information about a resource from AWS using an API Get, // List, or Describe-type function, or, better yet, using a finder. Data @@ -225,7 +219,7 @@ func dataSource{{ .DataSource }}Read(ctx context.Context, d *schema.ResourceData {{ if .IncludeComments }} // TIP: Setting a JSON string to avoid errorneous diffs. {{- end }} - p, err := verify.SecondJSONUnlessEquivalent(d.Get("policy").(string), {{ if .AWSGoSDKV2 }}aws.ToString{{ else }}aws.StringValue{{ end }}(out.Policy)) + p, err := verify.SecondJSONUnlessEquivalent(d.Get("policy").(string), aws.ToString(out.Policy)) if err != nil { return create.AppendDiagError(diags, names.{{ .Service }}, create.ErrActionSetting, DSName{{ .DataSource }}, d.Id(), err) } diff --git a/skaff/datasource/datasourcefw.gtpl b/skaff/datasource/datasourcefw.gtpl index b33cc56288e..cd00f104b5c 100644 --- a/skaff/datasource/datasourcefw.gtpl +++ b/skaff/datasource/datasourcefw.gtpl @@ -30,8 +30,6 @@ import ( // // The provider linter wants your imports to be in two groups: first, // standard library (i.e., "fmt" or "strings"), second, everything else. -{{- end }} -{{- if and .IncludeComments .AWSGoSDKV2 }} // // Also, AWS Go SDK v2 may handle nested structures differently than v1, // using the services/{{ .SDKPackage }}/types package. If so, you'll @@ -39,14 +37,12 @@ import ( // awstypes.. {{- end }} "context" -{{ if .AWSGoSDKV2 }} + "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/{{ .SDKPackage }}" awstypes "github.com/aws/aws-sdk-go-v2/service/{{ .SDKPackage }}/types" -{{- else }} "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/{{ .SDKPackage }}" -{{- end }} "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/types" @@ -178,7 +174,7 @@ func (d *dataSource{{ .DataSource }}) Read(ctx context.Context, req datasource.R {{- if .IncludeComments }} // TIP: -- 1. Get a client connection to the relevant service {{- end }} - conn := d.Meta().{{ .Service }}{{ if .AWSGoSDKV2 }}Client(ctx){{ else }}Conn(ctx){{ end }} + conn := d.Meta().{{ .Service }}Client(ctx) {{ if .IncludeComments }} // TIP: -- 2. Fetch the config {{- end }} diff --git a/skaff/datasource/datasourcetest.gtpl b/skaff/datasource/datasourcetest.gtpl index cb4372bc95b..7ea6a1c2797 100644 --- a/skaff/datasource/datasourcetest.gtpl +++ b/skaff/datasource/datasourcetest.gtpl @@ -31,8 +31,6 @@ import ( // // The provider linter wants your imports to be in two groups: first, // standard library (i.e., "fmt" or "strings"), second, everything else. -{{- end }} -{{- if and .IncludeComments .AWSGoSDKV2 }} // // Also, AWS Go SDK v2 may handle nested structures differently than v1, // using the services/{{ .SDKPackage }}/types package. If so, you'll @@ -44,14 +42,9 @@ import ( "testing" "github.com/YakDriver/regexache" -{{- if .AWSGoSDKV2 }} "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/{{ .SDKPackage }}" "github.com/aws/aws-sdk-go-v2/service/{{ .SDKPackage }}/types" -{{- else }} - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/{{ .SDKPackage }}" -{{- end }} "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" @@ -67,9 +60,7 @@ import ( // any normal context constants, variables, or functions. {{- end }} tf{{ .ServicePackage }} "github.com/hashicorp/terraform-provider-aws/internal/service/{{ .ServicePackage }}" -{{- if .AWSGoSDKV2 }} "github.com/hashicorp/terraform-provider-aws/names" -{{- end }} ) {{ if .IncludeComments }} // TIP: File Structure. The basic outline for all test files should be as @@ -177,18 +168,10 @@ func TestAcc{{ .Service }}{{ .DataSource }}DataSource_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - {{- if .AWSGoSDKV2 }} acctest.PreCheckPartitionHasService(t, names.{{ .Service }}EndpointID) - {{- else }} - acctest.PreCheckPartitionHasService(t, {{ .ServicePackage }}.EndpointsID) - {{- end }} testAccPreCheck(ctx, t) }, - {{- if .AWSGoSDKV2 }} ErrorCheck: acctest.ErrorCheck(t, names.{{ .Service }}ServiceID), - {{- else }} - ErrorCheck: acctest.ErrorCheck(t, {{ .ServicePackage }}.EndpointsID), - {{- end }} ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheck{{ .DataSource }}Destroy(ctx), Steps: []resource.TestStep{ diff --git a/skaff/function/function.go b/skaff/function/function.go index 7f1fa19b903..16e7c41c8b5 100644 --- a/skaff/function/function.go +++ b/skaff/function/function.go @@ -14,6 +14,7 @@ import ( "strings" "text/template" + "github.com/hashicorp/terraform-provider-aws/names" "github.com/hashicorp/terraform-provider-aws/skaff/convert" ) @@ -43,7 +44,9 @@ func Create(name, snakeName, description string, comments, force bool) error { return fmt.Errorf("snake name should be all lower case with underscores, if needed (e.g., arn_build)") } - snakeName = convert.ToSnakeCase(name, snakeName) + if snakeName == "" { + snakeName = names.ToSnakeCase(name) + } templateData := TemplateData{ Function: name, diff --git a/skaff/go.mod b/skaff/go.mod index d6142e3d781..6995a04c3cd 100644 --- a/skaff/go.mod +++ b/skaff/go.mod @@ -13,6 +13,7 @@ require ( github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/uuid v1.6.0 // indirect + github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.59 // indirect github.com/hashicorp/hcl/v2 v2.22.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect diff --git a/skaff/go.sum b/skaff/go.sum index bfbb6b38abd..74f80d9c447 100644 --- a/skaff/go.sum +++ b/skaff/go.sum @@ -13,6 +13,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.59 h1:j5ZrYJbLfZLJ9X5Bnp43z+ygN7kf6rbLCGIBGCIWWEA= +github.com/hashicorp/aws-sdk-go-base/v2 v2.0.0-beta.59/go.mod h1:jZEzCETkIzEinF749zPXsqpPmsA9P0fbMqRyoBh5UNo= github.com/hashicorp/hcl/v2 v2.22.0 h1:hkZ3nCtqeJsDhPRFz5EA9iwcG1hNWGePOTw6oyul12M= github.com/hashicorp/hcl/v2 v2.22.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= diff --git a/skaff/resource/resource.go b/skaff/resource/resource.go index ffeab94d6ca..3397715b06c 100644 --- a/skaff/resource/resource.go +++ b/skaff/resource/resource.go @@ -14,6 +14,7 @@ import ( "strings" "text/template" + "github.com/hashicorp/terraform-provider-aws/names" "github.com/hashicorp/terraform-provider-aws/names/data" "github.com/hashicorp/terraform-provider-aws/skaff/convert" ) @@ -42,13 +43,12 @@ type TemplateData struct { Service string ServiceLower string AWSServiceName string - AWSGoSDKV2 bool PluginFramework bool HumanResourceName string ProviderResourceName string } -func Create(resName, snakeName string, comments, force, v2, pluginFramework, tags bool) error { +func Create(resName, snakeName string, comments, force, pluginFramework, tags bool) error { wd, err := os.Getwd() // os.Getenv("GOPACKAGE") not available since this is not run with go generate if err != nil { return fmt.Errorf("error reading working directory: %s", err) @@ -68,7 +68,9 @@ func Create(resName, snakeName string, comments, force, v2, pluginFramework, tag return fmt.Errorf("error checking: snake name should be all lower case with underscores, if needed (e.g., db_instance)") } - snakeName = convert.ToSnakeCase(resName, snakeName) + if snakeName == "" { + snakeName = names.ToSnakeCase(resName) + } service, err := data.LookupService(servicePackage) if err != nil { @@ -87,7 +89,6 @@ func Create(resName, snakeName string, comments, force, v2, pluginFramework, tag Service: service.ProviderNameUpper(), ServiceLower: strings.ToLower(service.ProviderNameUpper()), AWSServiceName: service.FullHumanFriendly(), - AWSGoSDKV2: v2, PluginFramework: pluginFramework, HumanResourceName: convert.ToHumanResName(resName), ProviderResourceName: convert.ToProviderResourceName(servicePackage, snakeName), diff --git a/skaff/resource/resource.gtpl b/skaff/resource/resource.gtpl index fdade8cfea0..f410b6e8d6a 100644 --- a/skaff/resource/resource.gtpl +++ b/skaff/resource/resource.gtpl @@ -31,8 +31,6 @@ import ( // // The provider linter wants your imports to be in two groups: first, // standard library (i.e., "fmt" or "strings"), second, everything else. -{{- end }} -{{- if and .IncludeComments .AWSGoSDKV2 }} // // Also, AWS Go SDK v2 may handle nested structures differently than v1, // using the services/{{ .SDKPackage }}/types package. If so, you'll @@ -47,15 +45,10 @@ import ( "regexp" "strings" "time" -{{ if .AWSGoSDKV2 }} + "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/{{ .SDKPackage }}" "github.com/aws/aws-sdk-go-v2/service/{{ .SDKPackage }}/types" -{{- else }} - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/{{ .SDKPackage }}" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" -{{- end }} "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -232,7 +225,7 @@ func resource{{ .Resource }}Create(ctx context.Context, d *schema.ResourceData, // TIP: -- 1. Get a client connection to the relevant service {{- end }} - conn := meta.(*conns.AWSClient).{{ .Service }}{{ if .AWSGoSDKV2 }}Client(ctx){{ else }}Conn(ctx){{ end }} + conn := meta.(*conns.AWSClient).{{ .Service }}Client(ctx) {{ if .IncludeComments }} // TIP: -- 2. Populate a create input structure {{- end }} @@ -272,11 +265,7 @@ func resource{{ .Resource }}Create(ctx context.Context, d *schema.ResourceData, {{ if .IncludeComments }} // TIP: -- 3. Call the AWS create function {{- end }} - {{- if .AWSGoSDKV2 }} out, err := conn.Create{{ .Resource }}(ctx, in) - {{- else }} - out, err := conn.Create{{ .Resource }}WithContext(ctx, in) - {{- end }} if err != nil { {{- if .IncludeComments }} // TIP: Since d.SetId() has not been called yet, you cannot use d.Id() @@ -292,7 +281,7 @@ func resource{{ .Resource }}Create(ctx context.Context, d *schema.ResourceData, // TIP: -- 4. Set the minimum arguments and/or attributes for the Read function to // work. {{- end }} - d.SetId({{ if .AWSGoSDKV2 }}aws.ToString{{ else }}aws.StringValue{{ end }}(out.{{ .Resource }}.{{ .Resource }}ID)) + d.SetId(aws.ToString(out.{{ .Resource }}.{{ .Resource }}ID)) {{ if .IncludeComments }} // TIP: -- 5. Use a waiter to wait for create to complete {{- end }} @@ -323,7 +312,7 @@ func resource{{ .Resource }}Read(ctx context.Context, d *schema.ResourceData, me // TIP: -- 1. Get a client connection to the relevant service {{- end }} - conn := meta.(*conns.AWSClient).{{ .Service }}{{ if .AWSGoSDKV2 }}Client(ctx){{ else }}Conn(ctx){{ end }} + conn := meta.(*conns.AWSClient).{{ .Service }}Client(ctx) {{ if .IncludeComments }} // TIP: -- 2. Get the resource from AWS using an API Get, List, or Describe- // type function, or, better yet, using a finder. @@ -371,7 +360,7 @@ func resource{{ .Resource }}Read(ctx context.Context, d *schema.ResourceData, me {{ if .IncludeComments }} // TIP: Setting a JSON string to avoid errorneous diffs. {{- end }} - p, err := verify.SecondJSONUnlessEquivalent(d.Get("policy").(string), {{ if .AWSGoSDKV2 }}aws.ToString{{ else }}aws.StringValue{{ end }}(out.Policy)) + p, err := verify.SecondJSONUnlessEquivalent(d.Get("policy").(string), aws.ToString(out.Policy)) if err != nil { return create.AppendDiagError(diags, names.{{ .Service }}, create.ErrActionSetting, ResName{{ .Resource }}, d.Id(), err) } @@ -416,7 +405,7 @@ func resource{{ .Resource }}Update(ctx context.Context, d *schema.ResourceData, // TIP: -- 1. Get a client connection to the relevant service {{- end }} - conn := meta.(*conns.AWSClient).{{ .Service }}{{ if .AWSGoSDKV2 }}Client(ctx){{ else }}Conn(ctx){{ end }} + conn := meta.(*conns.AWSClient).{{ .Service }}Client(ctx) {{ if .IncludeComments }} // TIP: -- 2. Populate a modify input structure and check for changes // @@ -447,18 +436,14 @@ func resource{{ .Resource }}Update(ctx context.Context, d *schema.ResourceData, // TIP: -- 3. Call the AWS modify/update function {{- end }} log.Printf("[DEBUG] Updating {{ .Service }} {{ .Resource }} (%s): %#v", d.Id(), in) - {{- if .AWSGoSDKV2 }} out, err := conn.Update{{ .Resource }}(ctx, in) - {{- else }} - out, err := conn.Update{{ .Resource }}WithContext(ctx, in) - {{- end }} if err != nil { return create.AppendDiagError(diags, names.{{ .Service }}, create.ErrActionUpdating, ResName{{ .Resource }}, d.Id(), err) } {{ if .IncludeComments }} // TIP: -- 4. Use a waiter to wait for update to complete {{- end }} - if _, err := wait{{ .Resource }}Updated(ctx, conn, {{ if .AWSGoSDKV2 }}aws.ToString{{ else }}aws.StringValue{{ end }}(out.OperationId), d.Timeout(schema.TimeoutUpdate)); err != nil { + if _, err := wait{{ .Resource }}Updated(ctx, conn, aws.ToString(out.OperationId), d.Timeout(schema.TimeoutUpdate)); err != nil { return create.AppendDiagError(diags, names.{{ .Service }}, create.ErrActionWaitingForUpdate, ResName{{ .Resource }}, d.Id(), err) } {{ if .IncludeComments }} @@ -490,7 +475,7 @@ func resource{{ .Resource }}Delete(ctx context.Context, d *schema.ResourceData, // TIP: -- 1. Get a client connection to the relevant service {{- end }} - conn := meta.(*conns.AWSClient).{{ .Service }}{{ if .AWSGoSDKV2 }}Client(ctx){{ else }}Conn(ctx){{ end }} + conn := meta.(*conns.AWSClient).{{ .Service }}Client(ctx) {{ if .IncludeComments }} // TIP: -- 2. Populate a delete input structure {{- end }} @@ -498,34 +483,19 @@ func resource{{ .Resource }}Delete(ctx context.Context, d *schema.ResourceData, {{ if .IncludeComments }} // TIP: -- 3. Call the AWS delete function {{- end }} - {{- if .AWSGoSDKV2 }} _, err := conn.Delete{{ .Resource }}(ctx, &{{ .ServiceLower }}.Delete{{ .Resource }}Input{ Id: aws.String(d.Id()), }) - {{- else }} - _, err := conn.Delete{{ .Resource }}WithContext(ctx, &{{ .ServiceLower }}.Delete{{ .Resource }}Input{ - Id: aws.String(d.Id()), - }) - {{- end }} {{ if .IncludeComments }} // TIP: On rare occassions, the API returns a not found error after deleting a // resource. If that happens, we don't want it to show up as an error. {{- end }} - {{- if .AWSGoSDKV2 }} if errs.IsA[*types.ResourceNotFoundException](err){ return diags } if err != nil { return create.AppendDiagError(diags, names.{{ .Service }}, create.ErrActionDeleting, ResName{{ .Resource }}, d.Id(), err) } - {{- else }} - if tfawserr.ErrCodeEquals(err, {{ .ServiceLower }}.ErrCodeResourceNotFoundException) { - return diags - } - if err != nil { - return create.AppendDiagError(diags, names.{{ .Service }}, create.ErrActionDeleting, ResName{{ .Resource }}, d.Id(), err) - } - {{- end }} {{ if .IncludeComments }} // TIP: -- 4. Use a waiter to wait for delete to complete {{- end }} @@ -564,11 +534,7 @@ const ( // // You will need to adjust the parameters and names to fit the service. {{- end }} -{{ if .AWSGoSDKV2 }} func wait{{ .Resource }}Created(ctx context.Context, conn *{{ .ServiceLower }}.Client, id string, timeout time.Duration) (*{{ .ServiceLower }}.{{ .Resource }}, error) { -{{- else }} -func wait{{ .Resource }}Created(ctx context.Context, conn *{{ .ServiceLower }}.{{ .Service }}, id string, timeout time.Duration) (*{{ .ServiceLower }}.{{ .Resource }}, error) { -{{- end }} stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{statusNormal}, @@ -591,11 +557,7 @@ func wait{{ .Resource }}Created(ctx context.Context, conn *{{ .ServiceLower }}.{ // the update has been fully realized. Other times, you can check to see if a // key resource argument is updated to a new value or not. {{- end }} -{{ if .AWSGoSDKV2 }} func wait{{ .Resource }}Updated(ctx context.Context, conn *{{ .ServiceLower }}.Client, id string, timeout time.Duration) (*{{ .ServiceLower }}.{{ .Resource }}, error) { -{{- else }} -func wait{{ .Resource }}Updated(ctx context.Context, conn *{{ .ServiceLower }}.{{ .Service }}, id string, timeout time.Duration) (*{{ .ServiceLower }}.{{ .Resource }}, error) { -{{- end }} stateConf := &retry.StateChangeConf{ Pending: []string{statusChangePending}, Target: []string{statusUpdated}, @@ -616,11 +578,7 @@ func wait{{ .Resource }}Updated(ctx context.Context, conn *{{ .ServiceLower }}.{ // TIP: A deleted waiter is almost like a backwards created waiter. There may // be additional pending states, however. {{- end }} -{{ if .AWSGoSDKV2 }} func wait{{ .Resource }}Deleted(ctx context.Context, conn *{{ .ServiceLower }}.Client, id string, timeout time.Duration) (*{{ .ServiceLower }}.{{ .Resource }}, error) { -{{- else }} -func wait{{ .Resource }}Deleted(ctx context.Context, conn *{{ .ServiceLower }}.{{ .Service }}, id string, timeout time.Duration) (*{{ .ServiceLower }}.{{ .Resource }}, error) { -{{- end }} stateConf := &retry.StateChangeConf{ Pending: []string{statusDeleting, statusNormal}, Target: []string{}, @@ -644,11 +602,7 @@ func wait{{ .Resource }}Deleted(ctx context.Context, conn *{{ .ServiceLower }}.{ // Waiters consume the values returned by status functions. Design status so // that it can be reused by a create, update, and delete waiter, if possible. {{- end }} -{{ if .AWSGoSDKV2 }} func status{{ .Resource }}(ctx context.Context, conn *{{ .ServiceLower }}.Client, id string) retry.StateRefreshFunc { -{{- else }} -func status{{ .Resource }}(ctx context.Context, conn *{{ .ServiceLower }}.{{ .Service }}, id string) retry.StateRefreshFunc { -{{- end }} return func() (interface{}, string, error) { out, err := find{{ .Resource }}ByID(ctx, conn, id) if tfresource.NotFound(err) { @@ -659,7 +613,7 @@ func status{{ .Resource }}(ctx context.Context, conn *{{ .ServiceLower }}.{{ .Se return nil, "", err } - return out, {{ if .AWSGoSDKV2 }}aws.ToString{{ else }}aws.StringValue{{ end }}(out.Status), nil + return out, aws.ToString(out.Status), nil } } {{ if .IncludeComments }} @@ -669,16 +623,11 @@ func status{{ .Resource }}(ctx context.Context, conn *{{ .ServiceLower }}.{{ .Se // comes in handy in other places besides the status function. As a result, it // is good practice to define it separately. {{- end }} -{{ if .AWSGoSDKV2 }} func find{{ .Resource }}ByID(ctx context.Context, conn *{{ .ServiceLower }}.Client, id string) (*{{ .ServiceLower }}.{{ .Resource }}, error) { -{{- else }} -func find{{ .Resource }}ByID(ctx context.Context, conn *{{ .ServiceLower }}.{{ .Service }}, id string) (*{{ .ServiceLower }}.{{ .Resource }}, error) { -{{- end }} in := &{{ .ServiceLower }}.Get{{ .Resource }}Input{ Id: aws.String(id), } - {{- if .AWSGoSDKV2 }} out, err := conn.Get{{ .Resource }}(ctx, in) if errs.IsA[*types.ResourceNotFoundException](err){ return nil, &retry.NotFoundError{ @@ -689,18 +638,6 @@ func find{{ .Resource }}ByID(ctx context.Context, conn *{{ .ServiceLower }}.{{ . if err != nil { return nil, err } - {{- else }} - out, err := conn.Get{{ .Resource }}WithContext(ctx, in) - if tfawserr.ErrCodeEquals(err, {{ .ServiceLower }}.ErrCodeResourceNotFoundException) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: in, - } - } - if err != nil { - return nil, err - } - {{- end }} if out == nil || out.{{ .Resource }} == nil { return nil, tfresource.NewEmptyResultError(in) @@ -729,11 +666,11 @@ func flattenComplexArgument(apiObject *{{ .ServiceLower }}.ComplexArgument) map[ m := map[string]interface{}{} if v := apiObject.SubFieldOne; v != nil { - m["sub_field_one"] = {{ if .AWSGoSDKV2 }}aws.ToString{{ else }}aws.StringValue{{ end }}(v) + m["sub_field_one"] = aws.ToString(v) } if v := apiObject.SubFieldTwo; v != nil { - m["sub_field_two"] = {{ if .AWSGoSDKV2 }}aws.ToString{{ else }}aws.StringValue{{ end }}(v) + m["sub_field_two"] = aws.ToString(v) } return m diff --git a/skaff/resource/resourcefw.gtpl b/skaff/resource/resourcefw.gtpl index 282b1aa2c6d..9db993ce15f 100644 --- a/skaff/resource/resourcefw.gtpl +++ b/skaff/resource/resourcefw.gtpl @@ -30,8 +30,6 @@ import ( // // The provider linter wants your imports to be in two groups: first, // standard library (i.e., "fmt" or "strings"), second, everything else. -{{- end }} -{{- if and .IncludeComments .AWSGoSDKV2 }} // // Also, AWS Go SDK v2 may handle nested structures differently than v1, // using the services/{{ .SDKPackage }}/types package. If so, you'll @@ -41,15 +39,10 @@ import ( "context" "errors" "time" -{{ if .AWSGoSDKV2 }} + "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/{{ .SDKPackage }}" awstypes "github.com/aws/aws-sdk-go-v2/service/{{ .SDKPackage }}/types" -{{- else }} - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/{{ .SDKPackage }}" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" -{{- end }} "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" "github.com/hashicorp/terraform-plugin-framework-validators/listvalidator" "github.com/hashicorp/terraform-plugin-framework/path" @@ -61,9 +54,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-provider-aws/internal/create" -{{- if .AWSGoSDKV2 }} "github.com/hashicorp/terraform-provider-aws/internal/errs" -{{- end }} "github.com/hashicorp/terraform-provider-aws/internal/framework" "github.com/hashicorp/terraform-provider-aws/internal/framework/flex" fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types" @@ -258,7 +249,7 @@ func (r *resource{{ .Resource }}) Create(ctx context.Context, req resource.Creat // TIP: -- 1. Get a client connection to the relevant service {{- end }} - conn := r.Meta().{{ .Service }}{{ if .AWSGoSDKV2 }}Client(ctx){{ else }}Conn(ctx){{ end }} + conn := r.Meta().{{ .Service }}Client(ctx) {{ if .IncludeComments }} // TIP: -- 2. Fetch the plan {{- end }} @@ -286,11 +277,7 @@ func (r *resource{{ .Resource }}) Create(ctx context.Context, req resource.Creat {{ if .IncludeComments -}} // TIP: -- 4. Call the AWS Create function {{- end }} - {{- if .AWSGoSDKV2 }} out, err := conn.Create{{ .Resource }}(ctx, &input) - {{- else }} - out, err := conn.Create{{ .Resource }}WithContext(ctx, &input) - {{- end }} if err != nil { {{- if .IncludeComments }} // TIP: Since ID has not been set yet, you cannot use plan.ID.String() @@ -353,7 +340,7 @@ func (r *resource{{ .Resource }}) Read(ctx context.Context, req resource.ReadReq // TIP: -- 1. Get a client connection to the relevant service {{- end }} - conn := r.Meta().{{ .Service }}{{ if .AWSGoSDKV2 }}Client(ctx){{ else }}Conn(ctx){{ end }} + conn := r.Meta().{{ .Service }}Client(ctx) {{ if .IncludeComments }} // TIP: -- 2. Fetch the state {{- end }} @@ -421,7 +408,7 @@ func (r *resource{{ .Resource }}) Update(ctx context.Context, req resource.Updat {{- if .IncludeComments }} // TIP: -- 1. Get a client connection to the relevant service {{- end }} - conn := r.Meta().{{ .Service }}{{ if .AWSGoSDKV2 }}Client(ctx){{ else }}Conn(ctx){{ end }} + conn := r.Meta().{{ .Service }}Client(ctx) {{ if .IncludeComments }} // TIP: -- 2. Fetch the plan {{- end }} @@ -447,11 +434,7 @@ func (r *resource{{ .Resource }}) Update(ctx context.Context, req resource.Updat {{ if .IncludeComments }} // TIP: -- 4. Call the AWS modify/update function {{- end }} - {{- if .AWSGoSDKV2 }} out, err := conn.Update{{ .Resource }}(ctx, &input) - {{- else }} - out, err := conn.Update{{ .Resource }}WithContext(ctx, &input) - {{- end }} if err != nil { resp.Diagnostics.AddError( create.ProblemStandardMessage(names.{{ .Service }}, create.ErrActionUpdating, ResName{{ .Resource }}, plan.ID.String(), err), @@ -516,7 +499,7 @@ func (r *resource{{ .Resource }}) Delete(ctx context.Context, req resource.Delet {{- if .IncludeComments }} // TIP: -- 1. Get a client connection to the relevant service {{- end }} - conn := r.Meta().{{ .Service }}{{ if .AWSGoSDKV2 }}Client(ctx){{ else }}Conn(ctx){{ end }} + conn := r.Meta().{{ .Service }}Client(ctx) {{ if .IncludeComments }} // TIP: -- 2. Fetch the state {{- end }} @@ -534,25 +517,16 @@ func (r *resource{{ .Resource }}) Delete(ctx context.Context, req resource.Delet {{ if .IncludeComments }} // TIP: -- 4. Call the AWS delete function {{- end }} - {{- if .AWSGoSDKV2 }} _, err := conn.Delete{{ .Resource }}(ctx, &input) - {{- else }} - _, err := conn.Delete{{ .Resource }}WithContext(ctx, &input) - {{- end }} {{- if .IncludeComments }} // TIP: On rare occassions, the API returns a not found error after deleting a // resource. If that happens, we don't want it to show up as an error. {{- end }} if err != nil { - {{- if .AWSGoSDKV2 }} if errs.IsA[*awstypes.ResourceNotFoundException](err) { return } - {{- else }} - if tfawserr.ErrCodeEquals(err, {{ .ServiceLower }}.ErrCodeResourceNotFoundException) { - return - } - {{- end }} + resp.Diagnostics.AddError( create.ProblemStandardMessage(names.{{ .Service }}, create.ErrActionDeleting, ResName{{ .Resource }}, state.ID.String(), err), err.Error(), @@ -618,11 +592,7 @@ const ( // // You will need to adjust the parameters and names to fit the service. {{- end }} -{{- if .AWSGoSDKV2 }} func wait{{ .Resource }}Created(ctx context.Context, conn *{{ .ServiceLower }}.Client, id string, timeout time.Duration) (*awstypes.{{ .Resource }}, error) { -{{- else }} -func wait{{ .Resource }}Created(ctx context.Context, conn *{{ .ServiceLower }}.{{ .Service }}, id string, timeout time.Duration) (*{{ .ServiceLower }}.{{ .Resource }}, error) { -{{- end }} stateConf := &retry.StateChangeConf{ Pending: []string{}, Target: []string{statusNormal}, @@ -645,11 +615,7 @@ func wait{{ .Resource }}Created(ctx context.Context, conn *{{ .ServiceLower }}.{ // the update has been fully realized. Other times, you can check to see if a // key resource argument is updated to a new value or not. {{- end }} -{{- if .AWSGoSDKV2 }} func wait{{ .Resource }}Updated(ctx context.Context, conn *{{ .ServiceLower }}.Client, id string, timeout time.Duration) (*awstypes.{{ .Resource }}, error) { -{{- else }} -func wait{{ .Resource }}Updated(ctx context.Context, conn *{{ .ServiceLower }}.{{ .Service }}, id string, timeout time.Duration) (*{{ .ServiceLower }}.{{ .Resource }}, error) { -{{- end }} stateConf := &retry.StateChangeConf{ Pending: []string{statusChangePending}, Target: []string{statusUpdated}, @@ -670,11 +636,7 @@ func wait{{ .Resource }}Updated(ctx context.Context, conn *{{ .ServiceLower }}.{ // TIP: A deleted waiter is almost like a backwards created waiter. There may // be additional pending states, however. {{- end }} -{{- if .AWSGoSDKV2 }} func wait{{ .Resource }}Deleted(ctx context.Context, conn *{{ .ServiceLower }}.Client, id string, timeout time.Duration) (*awstypes.{{ .Resource }}, error) { -{{- else }} -func wait{{ .Resource }}Deleted(ctx context.Context, conn *{{ .ServiceLower }}.{{ .Service }}, id string, timeout time.Duration) (*{{ .ServiceLower }}.{{ .Resource }}, error) { -{{- end }} stateConf := &retry.StateChangeConf{ Pending: []string{statusDeleting, statusNormal}, Target: []string{}, @@ -698,11 +660,7 @@ func wait{{ .Resource }}Deleted(ctx context.Context, conn *{{ .ServiceLower }}.{ // Waiters consume the values returned by status functions. Design status so // that it can be reused by a create, update, and delete waiter, if possible. {{- end }} -{{- if .AWSGoSDKV2 }} func status{{ .Resource }}(ctx context.Context, conn *{{ .ServiceLower }}.Client, id string) retry.StateRefreshFunc { -{{- else }} -func status{{ .Resource }}(ctx context.Context, conn *{{ .ServiceLower }}.{{ .Service }}, id string) retry.StateRefreshFunc { -{{- end }} return func() (interface{}, string, error) { out, err := find{{ .Resource }}ByID(ctx, conn, id) if tfresource.NotFound(err) { @@ -712,11 +670,8 @@ func status{{ .Resource }}(ctx context.Context, conn *{{ .ServiceLower }}.{{ .Se if err != nil { return nil, "", err } -{{ if .AWSGoSDKV2 }} + return out, aws.ToString(out.Status), nil -{{- else }} - return out, aws.StringValue(out.Status), nil -{{- end }} } } {{ if .IncludeComments }} @@ -726,15 +681,11 @@ func status{{ .Resource }}(ctx context.Context, conn *{{ .ServiceLower }}.{{ .Se // comes in handy in other places besides the status function. As a result, it // is good practice to define it separately. {{- end }} -{{- if .AWSGoSDKV2 }} func find{{ .Resource }}ByID(ctx context.Context, conn *{{ .ServiceLower }}.Client, id string) (*awstypes.{{ .Resource }}, error) { -{{- else }} -func find{{ .Resource }}ByID(ctx context.Context, conn *{{ .ServiceLower }}.{{ .Service }}, id string) (*{{ .ServiceLower }}.{{ .Resource }}, error) { -{{- end }} in := &{{ .ServiceLower }}.Get{{ .Resource }}Input{ Id: aws.String(id), } - {{ if .AWSGoSDKV2 }} + out, err := conn.Get{{ .Resource }}(ctx, in) if err != nil { if errs.IsA[*awstypes.ResourceNotFoundException](err) { @@ -746,19 +697,6 @@ func find{{ .Resource }}ByID(ctx context.Context, conn *{{ .ServiceLower }}.{{ . return nil, err } - {{- else }} - out, err := conn.Get{{ .Resource }}WithContext(ctx, in) - if tfawserr.ErrCodeEquals(err, {{ .ServiceLower }}.ErrCodeResourceNotFoundException) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: in, - } - } - - if err != nil { - return nil, err - } - {{- end }} if out == nil || out.{{ .Resource }} == nil { return nil, tfresource.NewEmptyResultError(in) diff --git a/skaff/resource/resourcetest.gtpl b/skaff/resource/resourcetest.gtpl index c95f1e680a2..0bc28db0674 100644 --- a/skaff/resource/resourcetest.gtpl +++ b/skaff/resource/resourcetest.gtpl @@ -31,8 +31,6 @@ import ( // // The provider linter wants your imports to be in two groups: first, // standard library (i.e., "fmt" or "strings"), second, everything else. -{{- end }} -{{- if and .IncludeComments .AWSGoSDKV2 }} // // Also, AWS Go SDK v2 may handle nested structures differently than v1, // using the services/{{ .SDKPackage }}/types package. If so, you'll @@ -45,15 +43,9 @@ import ( "testing" "github.com/YakDriver/regexache" -{{- if .AWSGoSDKV2 }} "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/{{ .SDKPackage }}" "github.com/aws/aws-sdk-go-v2/service/{{ .SDKPackage }}/types" -{{- else }} - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/{{ .SDKPackage }}" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" -{{- end }} sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -175,18 +167,10 @@ func TestAcc{{ .Service }}{{ .Resource }}_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - {{- if .AWSGoSDKV2 }} acctest.PreCheckPartitionHasService(t, names.{{ .Service }}EndpointID) - {{- else }} - acctest.PreCheckPartitionHasService(t, {{ .ServicePackage }}.EndpointsID) - {{- end }} testAccPreCheck(ctx, t) }, - {{- if .AWSGoSDKV2 }} ErrorCheck: acctest.ErrorCheck(t, names.{{ .Service }}ServiceID), - {{- else }} - ErrorCheck: acctest.ErrorCheck(t, {{ .ServicePackage }}.EndpointsID), - {{- end }} ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheck{{ .Resource }}Destroy(ctx), Steps: []resource.TestStep{ @@ -228,18 +212,10 @@ func TestAcc{{ .Service }}{{ .Resource }}_disappears(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - {{- if .AWSGoSDKV2 }} acctest.PreCheckPartitionHasService(t, names.{{ .Service }}EndpointID) - {{- else }} - acctest.PreCheckPartitionHasService(t, {{ .ServicePackage }}.EndpointsID) - {{- end }} testAccPreCheck(t) }, - {{- if .AWSGoSDKV2 }} ErrorCheck: acctest.ErrorCheck(t, names.{{ .Service }}ServiceID), - {{- else }} - ErrorCheck: acctest.ErrorCheck(t, {{ .ServicePackage }}.EndpointsID), - {{- end }} ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheck{{ .Resource }}Destroy(ctx), Steps: []resource.TestStep{ @@ -269,7 +245,7 @@ func TestAcc{{ .Service }}{{ .Resource }}_disappears(t *testing.T) { func testAccCheck{{ .Resource }}Destroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).{{ .Service }}{{ if .AWSGoSDKV2 }}Client(ctx){{ else }}Conn(ctx){{ end }} + conn := acctest.Provider.Meta().(*conns.AWSClient).{{ .Service }}Client(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_{{ .ServicePackage }}_{{ .ResourceSnake }}" { @@ -280,24 +256,14 @@ func testAccCheck{{ .Resource }}Destroy(ctx context.Context) resource.TestCheckF {{ .Resource }}Id: aws.String(rs.Primary.ID), } - {{- if .AWSGoSDKV2 }} _, err := conn.Describe{{ .Resource }}(ctx, &{{ .SDKPackage }}.Describe{{ .Resource }}Input{ {{ .Resource }}Id: aws.String(rs.Primary.ID), }) - {{- else }} - _, err := conn.Describe{{ .Resource }}WithContext(ctx, &{{ .SDKPackage }}.Describe{{ .Resource }}Input{ - {{ .Resource }}Id: aws.String(rs.Primary.ID), - }) - {{- end }} - {{- if .AWSGoSDKV2 }} + if errs.IsA[*types.ResourceNotFoundException](err){ return nil } - {{ else }} - if tfawserr.ErrCodeEquals(err, {{ .SDKPackage }}.ErrCodeNotFoundException) { - return nil - } - {{ end -}} + if err != nil { return create.Error(names.{{ .Service }}, create.ErrActionCheckingDestroyed, tf{{ .ServicePackage }}.ResName{{ .Resource }}, rs.Primary.ID, err) } @@ -320,17 +286,11 @@ func testAccCheck{{ .Resource }}Exists(ctx context.Context, name string, {{ .Res return create.Error(names.{{ .Service }}, create.ErrActionCheckingExistence, tf{{ .ServicePackage }}.ResName{{ .Resource }}, name, errors.New("not set")) } - conn := acctest.Provider.Meta().(*conns.AWSClient).{{ .Service }}{{ if .AWSGoSDKV2 }}Client(ctx){{ else }}Conn(ctx){{ end }} + conn := acctest.Provider.Meta().(*conns.AWSClient).{{ .Service }}Client(ctx) - {{- if .AWSGoSDKV2 }} resp, err := conn.Describe{{ .Resource }}(ctx, &{{ .SDKPackage }}.Describe{{ .Resource }}Input{ {{ .Resource }}Id: aws.String(rs.Primary.ID), }) - {{- else }} - resp, err := conn.Describe{{ .Resource }}WithContext(ctx, &{{ .SDKPackage }}.Describe{{ .Resource }}Input{ - {{ .Resource }}Id: aws.String(rs.Primary.ID), - }) - {{- end }} if err != nil { return create.Error(names.{{ .Service }}, create.ErrActionCheckingExistence, tf{{ .ServicePackage }}.ResName{{ .Resource }}, rs.Primary.ID, err) @@ -343,15 +303,11 @@ func testAccCheck{{ .Resource }}Exists(ctx context.Context, name string, {{ .Res } func testAccPreCheck(ctx context.Context, t *testing.T) { - conn := acctest.Provider.Meta().(*conns.AWSClient).{{ .Service }}{{ if .AWSGoSDKV2 }}Client(ctx){{ else }}Conn(ctx){{ end }} + conn := acctest.Provider.Meta().(*conns.AWSClient).{{ .Service }}Client(ctx) input := &{{ .SDKPackage }}.List{{ .Resource }}sInput{} - {{- if .AWSGoSDKV2 }} _, err := conn.List{{ .Resource }}s(ctx, input) - {{- else }} - _, err := conn.List{{ .Resource }}sWithContext(ctx, input) - {{- end }} if acctest.PreCheckSkipError(err) { t.Skipf("skipping acceptance testing: %s", err) @@ -363,8 +319,8 @@ func testAccPreCheck(ctx context.Context, t *testing.T) { func testAccCheck{{ .Resource }}NotRecreated(before, after *{{ .SDKPackage }}.Describe{{ .Resource }}Response) resource.TestCheckFunc { return func(s *terraform.State) error { - if before, after := {{ if .AWSGoSDKV2 }}aws.ToString{{ else }}aws.StringValue{{ end }}(before.{{ .Resource }}Id), {{ if .AWSGoSDKV2 }}aws.ToString{{ else }}aws.StringValue{{ end }}(after.{{ .Resource }}Id); before != after { - return create.Error(names.{{ .Service }}, create.ErrActionCheckingNotRecreated, tf{{ .ServicePackage }}.ResName{{ .Resource }}, {{ if .AWSGoSDKV2 }}aws.ToString{{ else }}aws.StringValue{{ end }}(before.{{ .Resource }}Id), errors.New("recreated")) + if before, after := aws.ToString(before.{{ .Resource }}Id), aws.ToString(after.{{ .Resource }}Id); before != after { + return create.Error(names.{{ .Service }}, create.ErrActionCheckingNotRecreated, tf{{ .ServicePackage }}.ResName{{ .Resource }}, aws.ToString(before.{{ .Resource }}Id), errors.New("recreated")) } return nil