diff --git a/go.mod b/go.mod index 8028b705f73..a141ae9e6d7 100644 --- a/go.mod +++ b/go.mod @@ -103,6 +103,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing v1.26.3 github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.33.3 github.com/aws/aws-sdk-go-v2/service/emr v1.42.2 + github.com/aws/aws-sdk-go-v2/service/emrcontainers v1.30.4 github.com/aws/aws-sdk-go-v2/service/emrserverless v1.23.3 github.com/aws/aws-sdk-go-v2/service/eventbridge v1.33.3 github.com/aws/aws-sdk-go-v2/service/evidently v1.21.3 diff --git a/go.sum b/go.sum index 398244426a4..3ab04ce61fe 100644 --- a/go.sum +++ b/go.sum @@ -226,6 +226,8 @@ github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.33.3 h1:yiBmRRlVw github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2 v1.33.3/go.mod h1:L5bVuO4PeXuDuMYZfL3IW69E6mz6PDCYpp6IKDlcLMA= github.com/aws/aws-sdk-go-v2/service/emr v1.42.2 h1:j3aHjEsxFGCNGOCJjJM6AtPhdvn1pw2i2hGqxLU0qeI= github.com/aws/aws-sdk-go-v2/service/emr v1.42.2/go.mod h1:rN91rXF7gucnSnArDWbv9xDdZjBEetO4LFoJgGK/Wqw= +github.com/aws/aws-sdk-go-v2/service/emrcontainers v1.30.4 h1:3GUbTjfuJM3GFWkgth1pIa63v/4UKcLznHqubWcbLWc= +github.com/aws/aws-sdk-go-v2/service/emrcontainers v1.30.4/go.mod h1:JzEDBk3bq/xt5PM+OG+B6abbT/fBsoK3ia4EyLh3JMA= github.com/aws/aws-sdk-go-v2/service/emrserverless v1.23.3 h1:zxpxkpY1h+kPWquiUSG8u2CJ3AtEJPqqBqiMKxLwPjI= github.com/aws/aws-sdk-go-v2/service/emrserverless v1.23.3/go.mod h1:9+NjcAre2lLrpGvCrb9V+TUDii5D+Z8xER/vCPZdZFg= github.com/aws/aws-sdk-go-v2/service/eventbridge v1.33.3 h1:pjZzcXU25gsD2WmlmlayEsyXIWMVOK3//x4BXvK9c0U= diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index 0eedb6dc32f..09189978b78 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -95,6 +95,7 @@ import ( elasticloadbalancing_sdkv2 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing" elasticloadbalancingv2_sdkv2 "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2" emr_sdkv2 "github.com/aws/aws-sdk-go-v2/service/emr" + emrcontainers_sdkv2 "github.com/aws/aws-sdk-go-v2/service/emrcontainers" emrserverless_sdkv2 "github.com/aws/aws-sdk-go-v2/service/emrserverless" eventbridge_sdkv2 "github.com/aws/aws-sdk-go-v2/service/eventbridge" evidently_sdkv2 "github.com/aws/aws-sdk-go-v2/service/evidently" @@ -214,7 +215,6 @@ import ( elasticsearchservice_sdkv1 "github.com/aws/aws-sdk-go/service/elasticsearchservice" elastictranscoder_sdkv1 "github.com/aws/aws-sdk-go/service/elastictranscoder" emr_sdkv1 "github.com/aws/aws-sdk-go/service/emr" - emrcontainers_sdkv1 "github.com/aws/aws-sdk-go/service/emrcontainers" fsx_sdkv1 "github.com/aws/aws-sdk-go/service/fsx" gamelift_sdkv1 "github.com/aws/aws-sdk-go/service/gamelift" glue_sdkv1 "github.com/aws/aws-sdk-go/service/glue" @@ -630,8 +630,8 @@ func (c *AWSClient) EMRClient(ctx context.Context) *emr_sdkv2.Client { return errs.Must(client[*emr_sdkv2.Client](ctx, c, names.EMR, make(map[string]any))) } -func (c *AWSClient) EMRContainersConn(ctx context.Context) *emrcontainers_sdkv1.EMRContainers { - return errs.Must(conn[*emrcontainers_sdkv1.EMRContainers](ctx, c, names.EMRContainers, make(map[string]any))) +func (c *AWSClient) EMRContainersClient(ctx context.Context) *emrcontainers_sdkv2.Client { + return errs.Must(client[*emrcontainers_sdkv2.Client](ctx, c, names.EMRContainers, make(map[string]any))) } func (c *AWSClient) EMRServerlessClient(ctx context.Context) *emrserverless_sdkv2.Client { diff --git a/internal/service/emrcontainers/exports_test.go b/internal/service/emrcontainers/exports_test.go new file mode 100644 index 00000000000..56da566c74a --- /dev/null +++ b/internal/service/emrcontainers/exports_test.go @@ -0,0 +1,13 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package emrcontainers + +// Exports for use in tests only. +var ( + ResourceJobTemplate = resourceJobTemplate + ResourceVirtualCluster = resourceVirtualCluster + + FindJobTemplateByID = findJobTemplateByID + FindVirtualClusterByID = findVirtualClusterByID +) diff --git a/internal/service/emrcontainers/generate.go b/internal/service/emrcontainers/generate.go index 3a048572da2..9ec4e069b45 100644 --- a/internal/service/emrcontainers/generate.go +++ b/internal/service/emrcontainers/generate.go @@ -1,7 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -//go:generate go run ../../generate/tags/main.go -ListTags -ServiceTagsMap -UpdateTags +//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -KVTValues -ListTags -ServiceTagsMap -SkipTypesImp -UpdateTags //go:generate go run ../../generate/servicepackage/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. diff --git a/internal/service/emrcontainers/job_template.go b/internal/service/emrcontainers/job_template.go index 8f34a3da7f3..4ecc7c54c3f 100644 --- a/internal/service/emrcontainers/job_template.go +++ b/internal/service/emrcontainers/job_template.go @@ -9,15 +9,17 @@ import ( "time" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/emrcontainers" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/emrcontainers" + awstypes "github.com/aws/aws-sdk-go-v2/service/emrcontainers/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -28,7 +30,7 @@ import ( // @SDKResource("aws_emrcontainers_job_template", name="Job Template") // @Tags(identifierAttribute="arn") -func ResourceJobTemplate() *schema.Resource { +func resourceJobTemplate() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceJobTemplateCreate, ReadWithoutTimeout: resourceJobTemplateRead, @@ -130,10 +132,10 @@ func ResourceJobTemplate() *schema.Resource { }, }, "persistent_app_ui": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice(emrcontainers.PersistentAppUI_Values(), false), + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateDiagFunc: enum.Validate[awstypes.PersistentAppUI](), }, "s3_monitoring_configuration": { Type: schema.TypeList, @@ -259,8 +261,7 @@ func ResourceJobTemplate() *schema.Resource { func resourceJobTemplateCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - - conn := meta.(*conns.AWSClient).EMRContainersConn(ctx) + conn := meta.(*conns.AWSClient).EMRContainersClient(ctx) name := d.Get(names.AttrName).(string) input := &emrcontainers.CreateJobTemplateInput{ @@ -277,23 +278,22 @@ func resourceJobTemplateCreate(ctx context.Context, d *schema.ResourceData, meta input.KmsKeyArn = aws.String(v.(string)) } - output, err := conn.CreateJobTemplateWithContext(ctx, input) + output, err := conn.CreateJobTemplate(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating EMR Containers Job Template (%s): %s", name, err) } - d.SetId(aws.StringValue(output.Id)) + d.SetId(aws.ToString(output.Id)) return append(diags, resourceJobTemplateRead(ctx, d, meta)...) } func resourceJobTemplateRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).EMRContainersClient(ctx) - conn := meta.(*conns.AWSClient).EMRContainersConn(ctx) - - vc, err := FindJobTemplateByID(ctx, conn, d.Id()) + vc, err := findJobTemplateByID(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] EMR Containers Job Template %s not found, removing from state", d.Id()) @@ -313,8 +313,8 @@ func resourceJobTemplateRead(ctx context.Context, d *schema.ResourceData, meta i } else { d.Set("job_template_data", nil) } - d.Set(names.AttrName, vc.Name) d.Set(names.AttrKMSKeyARN, vc.KmsKeyArn) + d.Set(names.AttrName, vc.Name) setTagsOut(ctx, vc.Tags) @@ -323,20 +323,19 @@ func resourceJobTemplateRead(ctx context.Context, d *schema.ResourceData, meta i func resourceJobTemplateDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - - conn := meta.(*conns.AWSClient).EMRContainersConn(ctx) + conn := meta.(*conns.AWSClient).EMRContainersClient(ctx) log.Printf("[INFO] Deleting EMR Containers Job Template: %s", d.Id()) - _, err := conn.DeleteJobTemplateWithContext(ctx, &emrcontainers.DeleteJobTemplateInput{ + _, err := conn.DeleteJobTemplate(ctx, &emrcontainers.DeleteJobTemplateInput{ Id: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, emrcontainers.ErrCodeResourceNotFoundException) { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return diags } // Not actually a validation exception - if tfawserr.ErrMessageContains(err, emrcontainers.ErrCodeValidationException, "Template does not exist") { + if errs.IsAErrorMessageContains[*awstypes.ValidationException](err, "Template does not exist") { return diags } @@ -351,12 +350,47 @@ func resourceJobTemplateDelete(ctx context.Context, d *schema.ResourceData, meta return diags } -func expandJobTemplateData(tfMap map[string]interface{}) *emrcontainers.JobTemplateData { +func findJobTemplate(ctx context.Context, conn *emrcontainers.Client, input *emrcontainers.DescribeJobTemplateInput) (*awstypes.JobTemplate, error) { + output, err := conn.DescribeJobTemplate(ctx, input) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, err + } + + if output == nil || output.JobTemplate == nil { + return nil, tfresource.NewEmptyResultError(input) + } + + return output.JobTemplate, nil +} + +func findJobTemplateByID(ctx context.Context, conn *emrcontainers.Client, id string) (*awstypes.JobTemplate, error) { + input := &emrcontainers.DescribeJobTemplateInput{ + Id: aws.String(id), + } + + output, err := findJobTemplate(ctx, conn, input) + + if err != nil { + return nil, err + } + + return output, nil +} + +func expandJobTemplateData(tfMap map[string]interface{}) *awstypes.JobTemplateData { if tfMap == nil { return nil } - apiObject := &emrcontainers.JobTemplateData{} + apiObject := &awstypes.JobTemplateData{} if v, ok := tfMap["configuration_overrides"].([]interface{}); ok && len(v) > 0 { apiObject.ConfigurationOverrides = expandConfigurationOverrides(v[0].(map[string]interface{})) @@ -371,7 +405,7 @@ func expandJobTemplateData(tfMap map[string]interface{}) *emrcontainers.JobTempl } if v, ok := tfMap["job_tags"].(map[string]interface{}); ok && len(v) > 0 { - apiObject.JobTags = flex.ExpandStringMap(v) + apiObject.JobTags = flex.ExpandStringValueMap(v) } if v, ok := tfMap["release_label"].(string); ok && v != "" { @@ -381,12 +415,12 @@ func expandJobTemplateData(tfMap map[string]interface{}) *emrcontainers.JobTempl return apiObject } -func expandConfigurationOverrides(tfMap map[string]interface{}) *emrcontainers.ParametricConfigurationOverrides { +func expandConfigurationOverrides(tfMap map[string]interface{}) *awstypes.ParametricConfigurationOverrides { if tfMap == nil { return nil } - apiObject := &emrcontainers.ParametricConfigurationOverrides{} + apiObject := &awstypes.ParametricConfigurationOverrides{} if v, ok := tfMap["application_configuration"].([]interface{}); ok && len(v) > 0 { apiObject.ApplicationConfiguration = expandConfigurations(v) @@ -398,12 +432,12 @@ func expandConfigurationOverrides(tfMap map[string]interface{}) *emrcontainers.P return apiObject } -func expandConfigurations(tfList []interface{}) []*emrcontainers.Configuration { +func expandConfigurations(tfList []interface{}) []awstypes.Configuration { if len(tfList) == 0 { return nil } - var apiObjects []*emrcontainers.Configuration + var apiObjects []awstypes.Configuration for _, tfMapRaw := range tfList { tfMap, ok := tfMapRaw.(map[string]interface{}) @@ -414,22 +448,14 @@ func expandConfigurations(tfList []interface{}) []*emrcontainers.Configuration { apiObject := expandConfiguration(tfMap) - if apiObject == nil { - continue - } - apiObjects = append(apiObjects, apiObject) } return apiObjects } -func expandConfiguration(tfMap map[string]interface{}) *emrcontainers.Configuration { - if tfMap == nil { - return nil - } - - apiObject := &emrcontainers.Configuration{} +func expandConfiguration(tfMap map[string]interface{}) awstypes.Configuration { + apiObject := awstypes.Configuration{} if v, ok := tfMap["classification"].(string); ok && v != "" { apiObject.Classification = aws.String(v) @@ -440,18 +466,18 @@ func expandConfiguration(tfMap map[string]interface{}) *emrcontainers.Configurat } if v, ok := tfMap[names.AttrProperties].(map[string]interface{}); ok && len(v) > 0 { - apiObject.Properties = flex.ExpandStringMap(v) + apiObject.Properties = flex.ExpandStringValueMap(v) } return apiObject } -func expandMonitoringConfiguration(tfMap map[string]interface{}) *emrcontainers.ParametricMonitoringConfiguration { +func expandMonitoringConfiguration(tfMap map[string]interface{}) *awstypes.ParametricMonitoringConfiguration { if tfMap == nil { return nil } - apiObject := &emrcontainers.ParametricMonitoringConfiguration{} + apiObject := &awstypes.ParametricMonitoringConfiguration{} if v, ok := tfMap["cloud_watch_monitoring_configuration"].([]interface{}); ok && len(v) > 0 { apiObject.CloudWatchMonitoringConfiguration = expandCloudWatchMonitoringConfiguration(v[0].(map[string]interface{})) @@ -468,12 +494,12 @@ func expandMonitoringConfiguration(tfMap map[string]interface{}) *emrcontainers. return apiObject } -func expandCloudWatchMonitoringConfiguration(tfMap map[string]interface{}) *emrcontainers.ParametricCloudWatchMonitoringConfiguration { +func expandCloudWatchMonitoringConfiguration(tfMap map[string]interface{}) *awstypes.ParametricCloudWatchMonitoringConfiguration { if tfMap == nil { return nil } - apiObject := &emrcontainers.ParametricCloudWatchMonitoringConfiguration{} + apiObject := &awstypes.ParametricCloudWatchMonitoringConfiguration{} if v, ok := tfMap["log_group_mame"].(string); ok && v != "" { apiObject.LogGroupName = aws.String(v) @@ -486,12 +512,12 @@ func expandCloudWatchMonitoringConfiguration(tfMap map[string]interface{}) *emrc return apiObject } -func expandS3MonitoringConfiguration(tfMap map[string]interface{}) *emrcontainers.ParametricS3MonitoringConfiguration { +func expandS3MonitoringConfiguration(tfMap map[string]interface{}) *awstypes.ParametricS3MonitoringConfiguration { if tfMap == nil { return nil } - apiObject := &emrcontainers.ParametricS3MonitoringConfiguration{} + apiObject := &awstypes.ParametricS3MonitoringConfiguration{} if v, ok := tfMap["log_uri"].(string); ok && v != "" { apiObject.LogUri = aws.String(v) @@ -500,12 +526,12 @@ func expandS3MonitoringConfiguration(tfMap map[string]interface{}) *emrcontainer return apiObject } -func expandJobDriver(tfMap map[string]interface{}) *emrcontainers.JobDriver { +func expandJobDriver(tfMap map[string]interface{}) *awstypes.JobDriver { if tfMap == nil { return nil } - apiObject := &emrcontainers.JobDriver{} + apiObject := &awstypes.JobDriver{} if v, ok := tfMap["spark_sql_job_driver"].([]interface{}); ok && len(v) > 0 { apiObject.SparkSqlJobDriver = expandSparkSQLJobDriver(v[0].(map[string]interface{})) @@ -518,12 +544,12 @@ func expandJobDriver(tfMap map[string]interface{}) *emrcontainers.JobDriver { return apiObject } -func expandSparkSQLJobDriver(tfMap map[string]interface{}) *emrcontainers.SparkSqlJobDriver { +func expandSparkSQLJobDriver(tfMap map[string]interface{}) *awstypes.SparkSqlJobDriver { if tfMap == nil { return nil } - apiObject := &emrcontainers.SparkSqlJobDriver{} + apiObject := &awstypes.SparkSqlJobDriver{} if v, ok := tfMap["entry_point"].(string); ok && v != "" { apiObject.EntryPoint = aws.String(v) @@ -536,19 +562,19 @@ func expandSparkSQLJobDriver(tfMap map[string]interface{}) *emrcontainers.SparkS return apiObject } -func expandSparkSubmitJobDriver(tfMap map[string]interface{}) *emrcontainers.SparkSubmitJobDriver { +func expandSparkSubmitJobDriver(tfMap map[string]interface{}) *awstypes.SparkSubmitJobDriver { if tfMap == nil { return nil } - apiObject := &emrcontainers.SparkSubmitJobDriver{} + apiObject := &awstypes.SparkSubmitJobDriver{} if v, ok := tfMap["entry_point"].(string); ok && v != "" { apiObject.EntryPoint = aws.String(v) } if v, ok := tfMap["entry_point_arguments"].(*schema.Set); ok && v.Len() > 0 { - apiObject.EntryPointArguments = flex.ExpandStringSet(v) + apiObject.EntryPointArguments = flex.ExpandStringValueSet(v) } if v, ok := tfMap["spark_submit_parameters"].(string); ok && v != "" { @@ -558,7 +584,7 @@ func expandSparkSubmitJobDriver(tfMap map[string]interface{}) *emrcontainers.Spa return apiObject } -func flattenJobTemplateData(apiObject *emrcontainers.JobTemplateData) map[string]interface{} { +func flattenJobTemplateData(apiObject *awstypes.JobTemplateData) map[string]interface{} { if apiObject == nil { return nil } @@ -570,7 +596,7 @@ func flattenJobTemplateData(apiObject *emrcontainers.JobTemplateData) map[string } if v := apiObject.ExecutionRoleArn; v != nil { - tfMap[names.AttrExecutionRoleARN] = aws.StringValue(v) + tfMap[names.AttrExecutionRoleARN] = aws.ToString(v) } if v := apiObject.JobDriver; v != nil { @@ -578,17 +604,17 @@ func flattenJobTemplateData(apiObject *emrcontainers.JobTemplateData) map[string } if v := apiObject.JobTags; v != nil { - tfMap["job_tags"] = aws.StringValueMap(v) + tfMap["job_tags"] = v } if v := apiObject.ReleaseLabel; v != nil { - tfMap["release_label"] = aws.StringValue(v) + tfMap["release_label"] = aws.ToString(v) } return tfMap } -func flattenConfigurationOverrides(apiObject *emrcontainers.ParametricConfigurationOverrides) map[string]interface{} { +func flattenConfigurationOverrides(apiObject *awstypes.ParametricConfigurationOverrides) map[string]interface{} { if apiObject == nil { return nil } @@ -606,7 +632,7 @@ func flattenConfigurationOverrides(apiObject *emrcontainers.ParametricConfigurat return tfMap } -func flattenConfigurations(apiObjects []*emrcontainers.Configuration) []interface{} { +func flattenConfigurations(apiObjects []awstypes.Configuration) []interface{} { if len(apiObjects) == 0 { return nil } @@ -614,35 +640,27 @@ func flattenConfigurations(apiObjects []*emrcontainers.Configuration) []interfac var tfList []interface{} for _, apiObject := range apiObjects { - if apiObject == nil { - continue - } - tfList = append(tfList, flattenConfiguration(apiObject)) } return tfList } -func flattenConfiguration(apiObject *emrcontainers.Configuration) map[string]interface{} { - if apiObject == nil { - return nil - } - +func flattenConfiguration(apiObject awstypes.Configuration) map[string]interface{} { tfMap := map[string]interface{}{} if v := apiObject.Classification; v != nil { - tfMap["classification"] = aws.StringValue(v) + tfMap["classification"] = aws.ToString(v) } if v := apiObject.Properties; v != nil { - tfMap[names.AttrProperties] = aws.StringValueMap(v) + tfMap[names.AttrProperties] = v } return tfMap } -func flattenMonitoringConfiguration(apiObject *emrcontainers.ParametricMonitoringConfiguration) map[string]interface{} { +func flattenMonitoringConfiguration(apiObject *awstypes.ParametricMonitoringConfiguration) map[string]interface{} { if apiObject == nil { return nil } @@ -654,7 +672,7 @@ func flattenMonitoringConfiguration(apiObject *emrcontainers.ParametricMonitorin } if v := apiObject.PersistentAppUI; v != nil { - tfMap["persistent_app_ui"] = aws.StringValue(v) + tfMap["persistent_app_ui"] = aws.ToString(v) } if v := apiObject.S3MonitoringConfiguration; v != nil { @@ -664,7 +682,7 @@ func flattenMonitoringConfiguration(apiObject *emrcontainers.ParametricMonitorin return tfMap } -func flattenCloudWatchMonitoringConfiguration(apiObject *emrcontainers.ParametricCloudWatchMonitoringConfiguration) map[string]interface{} { +func flattenCloudWatchMonitoringConfiguration(apiObject *awstypes.ParametricCloudWatchMonitoringConfiguration) map[string]interface{} { if apiObject == nil { return nil } @@ -672,17 +690,17 @@ func flattenCloudWatchMonitoringConfiguration(apiObject *emrcontainers.Parametri tfMap := map[string]interface{}{} if v := apiObject.LogGroupName; v != nil { - tfMap[names.AttrLogGroupName] = aws.StringValue(v) + tfMap[names.AttrLogGroupName] = aws.ToString(v) } if v := apiObject.LogStreamNamePrefix; v != nil { - tfMap["log_stream_name_prefix"] = aws.StringValue(v) + tfMap["log_stream_name_prefix"] = aws.ToString(v) } return tfMap } -func flattenS3MonitoringConfiguration(apiObject *emrcontainers.ParametricS3MonitoringConfiguration) map[string]interface{} { +func flattenS3MonitoringConfiguration(apiObject *awstypes.ParametricS3MonitoringConfiguration) map[string]interface{} { if apiObject == nil { return nil } @@ -690,13 +708,13 @@ func flattenS3MonitoringConfiguration(apiObject *emrcontainers.ParametricS3Monit tfMap := map[string]interface{}{} if v := apiObject.LogUri; v != nil { - tfMap["log_uri"] = aws.StringValue(v) + tfMap["log_uri"] = aws.ToString(v) } return tfMap } -func flattenJobDriver(apiObject *emrcontainers.JobDriver) map[string]interface{} { +func flattenJobDriver(apiObject *awstypes.JobDriver) map[string]interface{} { if apiObject == nil { return nil } @@ -714,7 +732,7 @@ func flattenJobDriver(apiObject *emrcontainers.JobDriver) map[string]interface{} return tfMap } -func flattenSparkSQLJobDriver(apiObject *emrcontainers.SparkSqlJobDriver) map[string]interface{} { +func flattenSparkSQLJobDriver(apiObject *awstypes.SparkSqlJobDriver) map[string]interface{} { if apiObject == nil { return nil } @@ -722,17 +740,17 @@ func flattenSparkSQLJobDriver(apiObject *emrcontainers.SparkSqlJobDriver) map[st tfMap := map[string]interface{}{} if v := apiObject.EntryPoint; v != nil { - tfMap["entry_point"] = aws.StringValue(v) + tfMap["entry_point"] = aws.ToString(v) } if v := apiObject.SparkSqlParameters; v != nil { - tfMap["spark_sql_parameters"] = aws.StringValue(v) + tfMap["spark_sql_parameters"] = aws.ToString(v) } return tfMap } -func flattenSparkSubmitJobDriver(apiObject *emrcontainers.SparkSubmitJobDriver) map[string]interface{} { +func flattenSparkSubmitJobDriver(apiObject *awstypes.SparkSubmitJobDriver) map[string]interface{} { if apiObject == nil { return nil } @@ -740,51 +758,16 @@ func flattenSparkSubmitJobDriver(apiObject *emrcontainers.SparkSubmitJobDriver) tfMap := map[string]interface{}{} if v := apiObject.EntryPoint; v != nil { - tfMap["entry_point"] = aws.StringValue(v) + tfMap["entry_point"] = aws.ToString(v) } if v := apiObject.EntryPointArguments; v != nil { - tfMap["entry_point_arguments"] = flex.FlattenStringSet(v) + tfMap["entry_point_arguments"] = flex.FlattenStringValueSet(v) } if v := apiObject.SparkSubmitParameters; v != nil { - tfMap["spark_submit_parameters"] = aws.StringValue(v) + tfMap["spark_submit_parameters"] = aws.ToString(v) } return tfMap } - -func findJobTemplate(ctx context.Context, conn *emrcontainers.EMRContainers, input *emrcontainers.DescribeJobTemplateInput) (*emrcontainers.JobTemplate, error) { - output, err := conn.DescribeJobTemplateWithContext(ctx, input) - - if tfawserr.ErrCodeEquals(err, emrcontainers.ErrCodeResourceNotFoundException) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, - } - } - - if err != nil { - return nil, err - } - - if output == nil || output.JobTemplate == nil { - return nil, tfresource.NewEmptyResultError(input) - } - - return output.JobTemplate, nil -} - -func FindJobTemplateByID(ctx context.Context, conn *emrcontainers.EMRContainers, id string) (*emrcontainers.JobTemplate, error) { - input := &emrcontainers.DescribeJobTemplateInput{ - Id: aws.String(id), - } - - output, err := findJobTemplate(ctx, conn, input) - - if err != nil { - return nil, err - } - - return output, nil -} diff --git a/internal/service/emrcontainers/job_template_test.go b/internal/service/emrcontainers/job_template_test.go index 8991e059b2c..636a1a34e8b 100644 --- a/internal/service/emrcontainers/job_template_test.go +++ b/internal/service/emrcontainers/job_template_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/emrcontainers" + awstypes "github.com/aws/aws-sdk-go-v2/service/emrcontainers/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -21,7 +21,7 @@ import ( func TestAccEMRContainersJobTemplate_basic(t *testing.T) { ctx := acctest.Context(t) - var v emrcontainers.JobTemplate + var v awstypes.JobTemplate rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_emrcontainers_job_template.test" @@ -58,7 +58,7 @@ func TestAccEMRContainersJobTemplate_basic(t *testing.T) { func TestAccEMRContainersJobTemplate_disappears(t *testing.T) { ctx := acctest.Context(t) - var v emrcontainers.JobTemplate + var v awstypes.JobTemplate rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_emrcontainers_job_template.test" @@ -84,7 +84,7 @@ func TestAccEMRContainersJobTemplate_disappears(t *testing.T) { func TestAccEMRContainersJobTemplate_tags(t *testing.T) { ctx := acctest.Context(t) - var v emrcontainers.JobTemplate + var v awstypes.JobTemplate rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_emrcontainers_job_template.test" @@ -113,7 +113,7 @@ func TestAccEMRContainersJobTemplate_tags(t *testing.T) { }) } -func testAccCheckJobTemplateExists(ctx context.Context, n string, v *emrcontainers.JobTemplate) resource.TestCheckFunc { +func testAccCheckJobTemplateExists(ctx context.Context, n string, v *awstypes.JobTemplate) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -124,7 +124,7 @@ func testAccCheckJobTemplateExists(ctx context.Context, n string, v *emrcontaine return fmt.Errorf("No EMR Containers Job Template ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).EMRContainersConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EMRContainersClient(ctx) output, err := tfemrcontainers.FindJobTemplateByID(ctx, conn, rs.Primary.ID) @@ -140,7 +140,7 @@ func testAccCheckJobTemplateExists(ctx context.Context, n string, v *emrcontaine func testAccCheckJobTemplateDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).EMRContainersConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EMRContainersClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_emrcontainers_job_template" { diff --git a/internal/service/emrcontainers/service_endpoint_resolver_gen.go b/internal/service/emrcontainers/service_endpoint_resolver_gen.go index 9f03022d390..2836eabb49a 100644 --- a/internal/service/emrcontainers/service_endpoint_resolver_gen.go +++ b/internal/service/emrcontainers/service_endpoint_resolver_gen.go @@ -6,65 +6,63 @@ import ( "context" "fmt" "net" - "net/url" - endpoints_sdkv1 "github.com/aws/aws-sdk-go/aws/endpoints" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + emrcontainers_sdkv2 "github.com/aws/aws-sdk-go-v2/service/emrcontainers" + smithyendpoints "github.com/aws/smithy-go/endpoints" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/errs" ) -var _ endpoints_sdkv1.Resolver = resolverSDKv1{} +var _ emrcontainers_sdkv2.EndpointResolverV2 = resolverSDKv2{} -type resolverSDKv1 struct { - ctx context.Context +type resolverSDKv2 struct { + defaultResolver emrcontainers_sdkv2.EndpointResolverV2 } -func newEndpointResolverSDKv1(ctx context.Context) resolverSDKv1 { - return resolverSDKv1{ - ctx: ctx, +func newEndpointResolverSDKv2() resolverSDKv2 { + return resolverSDKv2{ + defaultResolver: emrcontainers_sdkv2.NewDefaultEndpointResolverV2(), } } -func (r resolverSDKv1) EndpointFor(service, region string, opts ...func(*endpoints_sdkv1.Options)) (endpoint endpoints_sdkv1.ResolvedEndpoint, err error) { - ctx := r.ctx +func (r resolverSDKv2) ResolveEndpoint(ctx context.Context, params emrcontainers_sdkv2.EndpointParameters) (endpoint smithyendpoints.Endpoint, err error) { + params = params.WithDefaults() + useFIPS := aws_sdkv2.ToBool(params.UseFIPS) - var opt endpoints_sdkv1.Options - opt.Set(opts...) - - useFIPS := opt.UseFIPSEndpoint == endpoints_sdkv1.FIPSEndpointStateEnabled + if eps := params.Endpoint; aws_sdkv2.ToString(eps) != "" { + tflog.Debug(ctx, "setting endpoint", map[string]any{ + "tf_aws.endpoint": endpoint, + }) - defaultResolver := endpoints_sdkv1.DefaultResolver() + if useFIPS { + tflog.Debug(ctx, "endpoint set, ignoring UseFIPSEndpoint setting") + params.UseFIPS = aws_sdkv2.Bool(false) + } - if useFIPS { + return r.defaultResolver.ResolveEndpoint(ctx, params) + } else if useFIPS { ctx = tflog.SetField(ctx, "tf_aws.use_fips", useFIPS) - endpoint, err = defaultResolver.EndpointFor(service, region, opts...) + endpoint, err = r.defaultResolver.ResolveEndpoint(ctx, params) if err != nil { return endpoint, err } tflog.Debug(ctx, "endpoint resolved", map[string]any{ - "tf_aws.endpoint": endpoint.URL, + "tf_aws.endpoint": endpoint.URI.String(), }) - var endpointURL *url.URL - endpointURL, err = url.Parse(endpoint.URL) - if err != nil { - return endpoint, err - } - - hostname := endpointURL.Hostname() + hostname := endpoint.URI.Hostname() _, err = net.LookupHost(hostname) if err != nil { if dnsErr, ok := errs.As[*net.DNSError](err); ok && dnsErr.IsNotFound { tflog.Debug(ctx, "default endpoint host not found, disabling FIPS", map[string]any{ "tf_aws.hostname": hostname, }) - opts = append(opts, func(o *endpoints_sdkv1.Options) { - o.UseFIPSEndpoint = endpoints_sdkv1.FIPSEndpointStateDisabled - }) + params.UseFIPS = aws_sdkv2.Bool(false) } else { - err = fmt.Errorf("looking up accessanalyzer endpoint %q: %s", hostname, err) + err = fmt.Errorf("looking up emrcontainers endpoint %q: %s", hostname, err) return } } else { @@ -72,5 +70,13 @@ func (r resolverSDKv1) EndpointFor(service, region string, opts ...func(*endpoin } } - return defaultResolver.EndpointFor(service, region, opts...) + return r.defaultResolver.ResolveEndpoint(ctx, params) +} + +func withBaseEndpoint(endpoint string) func(*emrcontainers_sdkv2.Options) { + return func(o *emrcontainers_sdkv2.Options) { + if endpoint != "" { + o.BaseEndpoint = aws_sdkv2.String(endpoint) + } + } } diff --git a/internal/service/emrcontainers/service_endpoints_gen_test.go b/internal/service/emrcontainers/service_endpoints_gen_test.go index 5acb2473bcd..6ea12550bf7 100644 --- a/internal/service/emrcontainers/service_endpoints_gen_test.go +++ b/internal/service/emrcontainers/service_endpoints_gen_test.go @@ -4,18 +4,22 @@ package emrcontainers_test import ( "context" + "errors" "fmt" "maps" "net" "net/url" "os" "path/filepath" + "reflect" "strings" "testing" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/endpoints" - emrcontainers_sdkv1 "github.com/aws/aws-sdk-go/service/emrcontainers" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" + emrcontainers_sdkv2 "github.com/aws/aws-sdk-go-v2/service/emrcontainers" + "github.com/aws/smithy-go/middleware" + smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" "github.com/hashicorp/aws-sdk-go-base/v2/servicemocks" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" @@ -240,54 +244,63 @@ func TestEndpointConfiguration(t *testing.T) { //nolint:paralleltest // uses t.S } func defaultEndpoint(region string) (url.URL, error) { - r := endpoints.DefaultResolver() + r := emrcontainers_sdkv2.NewDefaultEndpointResolverV2() - ep, err := r.EndpointFor(emrcontainers_sdkv1.EndpointsID, region) + ep, err := r.ResolveEndpoint(context.Background(), emrcontainers_sdkv2.EndpointParameters{ + Region: aws_sdkv2.String(region), + }) if err != nil { return url.URL{}, err } - url, _ := url.Parse(ep.URL) - - if url.Path == "" { - url.Path = "/" + if ep.URI.Path == "" { + ep.URI.Path = "/" } - return *url, nil + return ep.URI, nil } func defaultFIPSEndpoint(region string) (url.URL, error) { - r := endpoints.DefaultResolver() + r := emrcontainers_sdkv2.NewDefaultEndpointResolverV2() - ep, err := r.EndpointFor(emrcontainers_sdkv1.EndpointsID, region, func(opt *endpoints.Options) { - opt.UseFIPSEndpoint = endpoints.FIPSEndpointStateEnabled + ep, err := r.ResolveEndpoint(context.Background(), emrcontainers_sdkv2.EndpointParameters{ + Region: aws_sdkv2.String(region), + UseFIPS: aws_sdkv2.Bool(true), }) if err != nil { return url.URL{}, err } - url, _ := url.Parse(ep.URL) - - if url.Path == "" { - url.Path = "/" + if ep.URI.Path == "" { + ep.URI.Path = "/" } - return *url, nil + return ep.URI, nil } func callService(ctx context.Context, t *testing.T, meta *conns.AWSClient) apiCallParams { t.Helper() - client := meta.EMRContainersConn(ctx) + client := meta.EMRContainersClient(ctx) - req, _ := client.ListVirtualClustersRequest(&emrcontainers_sdkv1.ListVirtualClustersInput{}) + var result apiCallParams - req.HTTPRequest.URL.Path = "/" - - return apiCallParams{ - endpoint: req.HTTPRequest.URL.String(), - region: aws_sdkv1.StringValue(client.Config.Region), + _, err := client.ListVirtualClusters(ctx, &emrcontainers_sdkv2.ListVirtualClustersInput{}, + func(opts *emrcontainers_sdkv2.Options) { + opts.APIOptions = append(opts.APIOptions, + addRetrieveEndpointURLMiddleware(t, &result.endpoint), + addRetrieveRegionMiddleware(&result.region), + addCancelRequestMiddleware(), + ) + }, + ) + if err == nil { + t.Fatal("Expected an error, got none") + } else if !errors.Is(err, errCancelOperation) { + t.Fatalf("Unexpected error: %s", err) } + + return result } func withNoConfig(_ *caseSetup) { @@ -466,6 +479,89 @@ func testEndpointCase(t *testing.T, region string, testcase endpointTestCase, ca } } +func addRetrieveEndpointURLMiddleware(t *testing.T, endpoint *string) func(*middleware.Stack) error { + return func(stack *middleware.Stack) error { + return stack.Finalize.Add( + retrieveEndpointURLMiddleware(t, endpoint), + middleware.After, + ) + } +} + +func retrieveEndpointURLMiddleware(t *testing.T, endpoint *string) middleware.FinalizeMiddleware { + return middleware.FinalizeMiddlewareFunc( + "Test: Retrieve Endpoint", + func(ctx context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (middleware.FinalizeOutput, middleware.Metadata, error) { + t.Helper() + + request, ok := in.Request.(*smithyhttp.Request) + if !ok { + t.Fatalf("Expected *github.com/aws/smithy-go/transport/http.Request, got %s", fullTypeName(in.Request)) + } + + url := request.URL + url.RawQuery = "" + url.Path = "/" + + *endpoint = url.String() + + return next.HandleFinalize(ctx, in) + }) +} + +func addRetrieveRegionMiddleware(region *string) func(*middleware.Stack) error { + return func(stack *middleware.Stack) error { + return stack.Serialize.Add( + retrieveRegionMiddleware(region), + middleware.After, + ) + } +} + +func retrieveRegionMiddleware(region *string) middleware.SerializeMiddleware { + return middleware.SerializeMiddlewareFunc( + "Test: Retrieve Region", + func(ctx context.Context, in middleware.SerializeInput, next middleware.SerializeHandler) (middleware.SerializeOutput, middleware.Metadata, error) { + *region = awsmiddleware.GetRegion(ctx) + + return next.HandleSerialize(ctx, in) + }, + ) +} + +var errCancelOperation = fmt.Errorf("Test: Canceling request") + +func addCancelRequestMiddleware() func(*middleware.Stack) error { + return func(stack *middleware.Stack) error { + return stack.Finalize.Add( + cancelRequestMiddleware(), + middleware.After, + ) + } +} + +// cancelRequestMiddleware creates a Smithy middleware that intercepts the request before sending and cancels it +func cancelRequestMiddleware() middleware.FinalizeMiddleware { + return middleware.FinalizeMiddlewareFunc( + "Test: Cancel Requests", + func(_ context.Context, in middleware.FinalizeInput, next middleware.FinalizeHandler) (middleware.FinalizeOutput, middleware.Metadata, error) { + return middleware.FinalizeOutput{}, middleware.Metadata{}, errCancelOperation + }) +} + +func fullTypeName(i interface{}) string { + return fullValueTypeName(reflect.ValueOf(i)) +} + +func fullValueTypeName(v reflect.Value) string { + if v.Kind() == reflect.Ptr { + return "*" + fullValueTypeName(reflect.Indirect(v)) + } + + requestType := v.Type() + return fmt.Sprintf("%s.%s", requestType.PkgPath(), requestType.Name()) +} + func generateSharedConfigFile(config configFile) string { var buf strings.Builder diff --git a/internal/service/emrcontainers/service_package_gen.go b/internal/service/emrcontainers/service_package_gen.go index f247f7faa4f..87ce0530473 100644 --- a/internal/service/emrcontainers/service_package_gen.go +++ b/internal/service/emrcontainers/service_package_gen.go @@ -5,10 +5,8 @@ package emrcontainers import ( "context" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - emrcontainers_sdkv1 "github.com/aws/aws-sdk-go/service/emrcontainers" - "github.com/hashicorp/terraform-plugin-log/tflog" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + emrcontainers_sdkv2 "github.com/aws/aws-sdk-go-v2/service/emrcontainers" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -27,8 +25,10 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.Servic func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePackageSDKDataSource { return []*types.ServicePackageSDKDataSource{ { - Factory: DataSourceVirtualCluster, + Factory: dataSourceVirtualCluster, TypeName: "aws_emrcontainers_virtual_cluster", + Name: "Virtual Cluster", + Tags: &types.ServicePackageResourceTags{}, }, } } @@ -36,7 +36,7 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePackageSDKResource { return []*types.ServicePackageSDKResource{ { - Factory: ResourceJobTemplate, + Factory: resourceJobTemplate, TypeName: "aws_emrcontainers_job_template", Name: "Job Template", Tags: &types.ServicePackageResourceTags{ @@ -44,7 +44,7 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka }, }, { - Factory: ResourceVirtualCluster, + Factory: resourceVirtualCluster, TypeName: "aws_emrcontainers_virtual_cluster", Name: "Virtual Cluster", Tags: &types.ServicePackageResourceTags{ @@ -58,22 +58,14 @@ func (p *servicePackage) ServicePackageName() string { return names.EMRContainers } -// NewConn returns a new AWS SDK for Go v1 client for this service package's AWS API. -func (p *servicePackage) NewConn(ctx context.Context, config map[string]any) (*emrcontainers_sdkv1.EMRContainers, error) { - sess := config[names.AttrSession].(*session_sdkv1.Session) - - cfg := aws_sdkv1.Config{} - - if endpoint := config[names.AttrEndpoint].(string); endpoint != "" { - tflog.Debug(ctx, "setting endpoint", map[string]any{ - "tf_aws.endpoint": endpoint, - }) - cfg.Endpoint = aws_sdkv1.String(endpoint) - } else { - cfg.EndpointResolver = newEndpointResolverSDKv1(ctx) - } +// NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API. +func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*emrcontainers_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) - return emrcontainers_sdkv1.New(sess.Copy(&cfg)), nil + return emrcontainers_sdkv2.NewFromConfig(cfg, + emrcontainers_sdkv2.WithEndpointResolverV2(newEndpointResolverSDKv2()), + withBaseEndpoint(config[names.AttrEndpoint].(string)), + ), nil } func ServicePackage(ctx context.Context) conns.ServicePackage { diff --git a/internal/service/emrcontainers/sweep.go b/internal/service/emrcontainers/sweep.go index a355f85f0f8..24fa1296fbd 100644 --- a/internal/service/emrcontainers/sweep.go +++ b/internal/service/emrcontainers/sweep.go @@ -7,11 +7,12 @@ import ( "fmt" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/emrcontainers" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/emrcontainers" + awstypes "github.com/aws/aws-sdk-go-v2/service/emrcontainers/types" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/sweep" - "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv1" + "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv2" ) func RegisterSweepers() { @@ -32,37 +33,34 @@ func sweepVirtualClusters(region string) error { if err != nil { return fmt.Errorf("error getting client: %s", err) } - conn := client.EMRContainersConn(ctx) + conn := client.EMRContainersClient(ctx) input := &emrcontainers.ListVirtualClustersInput{} sweepResources := make([]sweep.Sweepable, 0) - err = conn.ListVirtualClustersPagesWithContext(ctx, input, func(page *emrcontainers.ListVirtualClustersOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := emrcontainers.NewListVirtualClustersPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping EMR Containers Virtual Cluster sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("error listing EMR Containers Virtual Clusters (%s): %w", region, err) } for _, v := range page.VirtualClusters { - if aws.StringValue(v.State) == emrcontainers.VirtualClusterStateTerminated { + if v.State == awstypes.VirtualClusterStateTerminated { continue } - r := ResourceVirtualCluster() + r := resourceVirtualCluster() d := r.Data(nil) - d.SetId(aws.StringValue(v.Id)) + d.SetId(aws.ToString(v.Id)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping EMR Containers Virtual Cluster sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("error listing EMR Containers Virtual Clusters (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) @@ -80,33 +78,30 @@ func sweepJobTemplates(region string) error { if err != nil { return fmt.Errorf("error getting client: %s", err) } - conn := client.EMRContainersConn(ctx) + conn := client.EMRContainersClient(ctx) input := &emrcontainers.ListJobTemplatesInput{} sweepResources := make([]sweep.Sweepable, 0) - err = conn.ListJobTemplatesPagesWithContext(ctx, input, func(page *emrcontainers.ListJobTemplatesOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := emrcontainers.NewListJobTemplatesPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping EMR Containers Job Template sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("error listing EMR Containers Job Templates (%s): %w", region, err) } for _, v := range page.Templates { - r := ResourceJobTemplate() + r := resourceJobTemplate() d := r.Data(nil) - d.SetId(aws.StringValue(v.Id)) + d.SetId(aws.ToString(v.Id)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping EMR Containers Job Template sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("error listing EMR Containers Job Templates (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) diff --git a/internal/service/emrcontainers/tags_gen.go b/internal/service/emrcontainers/tags_gen.go index fe3aa0070f9..23cc8c83739 100644 --- a/internal/service/emrcontainers/tags_gen.go +++ b/internal/service/emrcontainers/tags_gen.go @@ -5,9 +5,8 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/emrcontainers" - "github.com/aws/aws-sdk-go/service/emrcontainers/emrcontainersiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/emrcontainers" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/logging" @@ -19,12 +18,12 @@ import ( // listTags lists emrcontainers service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. -func listTags(ctx context.Context, conn emrcontainersiface.EMRContainersAPI, identifier string) (tftags.KeyValueTags, error) { +func listTags(ctx context.Context, conn *emrcontainers.Client, identifier string, optFns ...func(*emrcontainers.Options)) (tftags.KeyValueTags, error) { input := &emrcontainers.ListTagsForResourceInput{ ResourceArn: aws.String(identifier), } - output, err := conn.ListTagsForResourceWithContext(ctx, input) + output, err := conn.ListTagsForResource(ctx, input, optFns...) if err != nil { return tftags.New(ctx, nil), err @@ -36,7 +35,7 @@ func listTags(ctx context.Context, conn emrcontainersiface.EMRContainersAPI, ide // ListTags lists emrcontainers service tags and set them in Context. // It is called from outside this package. func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier string) error { - tags, err := listTags(ctx, meta.(*conns.AWSClient).EMRContainersConn(ctx), identifier) + tags, err := listTags(ctx, meta.(*conns.AWSClient).EMRContainersClient(ctx), identifier) if err != nil { return err @@ -49,21 +48,21 @@ func (p *servicePackage) ListTags(ctx context.Context, meta any, identifier stri return nil } -// map[string]*string handling +// map[string]string handling // Tags returns emrcontainers service tags. -func Tags(tags tftags.KeyValueTags) map[string]*string { - return aws.StringMap(tags.Map()) +func Tags(tags tftags.KeyValueTags) map[string]string { + return tags.Map() } // KeyValueTags creates tftags.KeyValueTags from emrcontainers service tags. -func KeyValueTags(ctx context.Context, tags map[string]*string) tftags.KeyValueTags { +func KeyValueTags(ctx context.Context, tags map[string]string) tftags.KeyValueTags { return tftags.New(ctx, tags) } // getTagsIn returns emrcontainers service tags from Context. // nil is returned if there are no input tags. -func getTagsIn(ctx context.Context) map[string]*string { +func getTagsIn(ctx context.Context) map[string]string { if inContext, ok := tftags.FromContext(ctx); ok { if tags := Tags(inContext.TagsIn.UnwrapOrDefault()); len(tags) > 0 { return tags @@ -74,7 +73,7 @@ func getTagsIn(ctx context.Context) map[string]*string { } // setTagsOut sets emrcontainers service tags in Context. -func setTagsOut(ctx context.Context, tags map[string]*string) { +func setTagsOut(ctx context.Context, tags map[string]string) { if inContext, ok := tftags.FromContext(ctx); ok { inContext.TagsOut = option.Some(KeyValueTags(ctx, tags)) } @@ -83,7 +82,7 @@ func setTagsOut(ctx context.Context, tags map[string]*string) { // updateTags updates emrcontainers service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. -func updateTags(ctx context.Context, conn emrcontainersiface.EMRContainersAPI, identifier string, oldTagsMap, newTagsMap any) error { +func updateTags(ctx context.Context, conn *emrcontainers.Client, identifier string, oldTagsMap, newTagsMap any, optFns ...func(*emrcontainers.Options)) error { oldTags := tftags.New(ctx, oldTagsMap) newTags := tftags.New(ctx, newTagsMap) @@ -94,10 +93,10 @@ func updateTags(ctx context.Context, conn emrcontainersiface.EMRContainersAPI, i if len(removedTags) > 0 { input := &emrcontainers.UntagResourceInput{ ResourceArn: aws.String(identifier), - TagKeys: aws.StringSlice(removedTags.Keys()), + TagKeys: removedTags.Keys(), } - _, err := conn.UntagResourceWithContext(ctx, input) + _, err := conn.UntagResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("untagging resource (%s): %w", identifier, err) @@ -112,7 +111,7 @@ func updateTags(ctx context.Context, conn emrcontainersiface.EMRContainersAPI, i Tags: Tags(updatedTags), } - _, err := conn.TagResourceWithContext(ctx, input) + _, err := conn.TagResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("tagging resource (%s): %w", identifier, err) @@ -125,5 +124,5 @@ func updateTags(ctx context.Context, conn emrcontainersiface.EMRContainersAPI, i // UpdateTags updates emrcontainers service tags. // It is called from outside this package. func (p *servicePackage) UpdateTags(ctx context.Context, meta any, identifier string, oldTags, newTags any) error { - return updateTags(ctx, meta.(*conns.AWSClient).EMRContainersConn(ctx), identifier, oldTags, newTags) + return updateTags(ctx, meta.(*conns.AWSClient).EMRContainersClient(ctx), identifier, oldTags, newTags) } diff --git a/internal/service/emrcontainers/virtual_cluster.go b/internal/service/emrcontainers/virtual_cluster.go index 8f85f7ac99f..7e6e48bf9c2 100644 --- a/internal/service/emrcontainers/virtual_cluster.go +++ b/internal/service/emrcontainers/virtual_cluster.go @@ -9,14 +9,16 @@ import ( "time" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/emrcontainers" - "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/emrcontainers" + awstypes "github.com/aws/aws-sdk-go-v2/service/emrcontainers/types" "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" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -26,7 +28,7 @@ import ( // @SDKResource("aws_emrcontainers_virtual_cluster", name="Virtual Cluster") // @Tags(identifierAttribute="arn") -func ResourceVirtualCluster() *schema.Resource { +func resourceVirtualCluster() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceVirtualClusterCreate, ReadWithoutTimeout: resourceVirtualClusterRead, @@ -86,10 +88,10 @@ func ResourceVirtualCluster() *schema.Resource { }, }, names.AttrType: { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice(emrcontainers.ContainerProviderType_Values(), false), + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateDiagFunc: enum.Validate[awstypes.ContainerProviderType](), }, }, }, @@ -113,8 +115,7 @@ func ResourceVirtualCluster() *schema.Resource { func resourceVirtualClusterCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - - conn := meta.(*conns.AWSClient).EMRContainersConn(ctx) + conn := meta.(*conns.AWSClient).EMRContainersClient(ctx) name := d.Get(names.AttrName).(string) input := &emrcontainers.CreateVirtualClusterInput{ @@ -126,23 +127,22 @@ func resourceVirtualClusterCreate(ctx context.Context, d *schema.ResourceData, m input.ContainerProvider = expandContainerProvider(v.([]interface{})[0].(map[string]interface{})) } - output, err := conn.CreateVirtualClusterWithContext(ctx, input) + output, err := conn.CreateVirtualCluster(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating EMR Containers Virtual Cluster (%s): %s", name, err) } - d.SetId(aws.StringValue(output.Id)) + d.SetId(aws.ToString(output.Id)) return append(diags, resourceVirtualClusterRead(ctx, d, meta)...) } func resourceVirtualClusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).EMRContainersClient(ctx) - conn := meta.(*conns.AWSClient).EMRContainersConn(ctx) - - vc, err := FindVirtualClusterByID(ctx, conn, d.Id()) + vc, err := findVirtualClusterByID(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] EMR Containers Virtual Cluster %s not found, removing from state", d.Id()) @@ -176,25 +176,24 @@ func resourceVirtualClusterUpdate(ctx context.Context, d *schema.ResourceData, m func resourceVirtualClusterDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - - conn := meta.(*conns.AWSClient).EMRContainersConn(ctx) + conn := meta.(*conns.AWSClient).EMRContainersClient(ctx) log.Printf("[INFO] Deleting EMR Containers Virtual Cluster: %s", d.Id()) - _, err := conn.DeleteVirtualClusterWithContext(ctx, &emrcontainers.DeleteVirtualClusterInput{ + _, err := conn.DeleteVirtualCluster(ctx, &emrcontainers.DeleteVirtualClusterInput{ Id: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, emrcontainers.ErrCodeResourceNotFoundException) { + if errs.IsA[*awstypes.ResourceNotFoundException](err) { return diags } // Not actually a validation exception - if tfawserr.ErrMessageContains(err, emrcontainers.ErrCodeValidationException, "not found") { + if errs.IsAErrorMessageContains[*awstypes.ValidationException](err, "not found") { return diags } // Not actually a validation exception - if tfawserr.ErrMessageContains(err, emrcontainers.ErrCodeValidationException, "already terminated") { + if errs.IsAErrorMessageContains[*awstypes.ValidationException](err, "already terminated") { return diags } @@ -202,19 +201,95 @@ func resourceVirtualClusterDelete(ctx context.Context, d *schema.ResourceData, m return sdkdiag.AppendErrorf(diags, "deleting EMR Containers Virtual Cluster (%s): %s", d.Id(), err) } - if _, err = waitVirtualClusterDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { + if _, err := waitVirtualClusterDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for EMR Containers Virtual Cluster (%s) delete: %s", d.Id(), err) } return diags } -func expandContainerProvider(tfMap map[string]interface{}) *emrcontainers.ContainerProvider { +func findVirtualCluster(ctx context.Context, conn *emrcontainers.Client, input *emrcontainers.DescribeVirtualClusterInput) (*awstypes.VirtualCluster, error) { + output, err := conn.DescribeVirtualCluster(ctx, input) + + if errs.IsA[*awstypes.ResourceNotFoundException](err) { + return nil, &retry.NotFoundError{ + LastError: err, + LastRequest: input, + } + } + + if err != nil { + return nil, err + } + + if output == nil || output.VirtualCluster == nil { + return nil, tfresource.NewEmptyResultError(input) + } + + return output.VirtualCluster, nil +} + +func findVirtualClusterByID(ctx context.Context, conn *emrcontainers.Client, id string) (*awstypes.VirtualCluster, error) { + input := &emrcontainers.DescribeVirtualClusterInput{ + Id: aws.String(id), + } + + output, err := findVirtualCluster(ctx, conn, input) + + if err != nil { + return nil, err + } + + if output.State == awstypes.VirtualClusterStateTerminated { + return nil, &retry.NotFoundError{ + Message: string(output.State), + LastRequest: input, + } + } + + return output, nil +} + +func statusVirtualCluster(ctx context.Context, conn *emrcontainers.Client, id string) retry.StateRefreshFunc { + return func() (interface{}, string, error) { + output, err := findVirtualClusterByID(ctx, conn, id) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return output, string(output.State), nil + } +} + +func waitVirtualClusterDeleted(ctx context.Context, conn *emrcontainers.Client, id string, timeout time.Duration) (*awstypes.VirtualCluster, error) { + stateConf := &retry.StateChangeConf{ + Pending: enum.Slice(awstypes.VirtualClusterStateTerminating), + Target: []string{}, + Refresh: statusVirtualCluster(ctx, conn, id), + Timeout: timeout, + Delay: 1 * time.Minute, + } + + outputRaw, err := stateConf.WaitForStateContext(ctx) + + if v, ok := outputRaw.(*awstypes.VirtualCluster); ok { + return v, err + } + + return nil, err +} + +func expandContainerProvider(tfMap map[string]interface{}) *awstypes.ContainerProvider { if tfMap == nil { return nil } - apiObject := &emrcontainers.ContainerProvider{} + apiObject := &awstypes.ContainerProvider{} if v, ok := tfMap[names.AttrID].(string); ok && v != "" { apiObject.Id = aws.String(v) @@ -225,32 +300,28 @@ func expandContainerProvider(tfMap map[string]interface{}) *emrcontainers.Contai } if v, ok := tfMap[names.AttrType].(string); ok && v != "" { - apiObject.Type = aws.String(v) + apiObject.Type = awstypes.ContainerProviderType(v) } return apiObject } -func expandContainerInfo(tfMap map[string]interface{}) *emrcontainers.ContainerInfo { +func expandContainerInfo(tfMap map[string]interface{}) awstypes.ContainerInfo { if tfMap == nil { return nil } - apiObject := &emrcontainers.ContainerInfo{} + apiObject := &awstypes.ContainerInfoMemberEksInfo{} if v, ok := tfMap["eks_info"].([]interface{}); ok && len(v) > 0 { - apiObject.EksInfo = expandEKSInfo(v[0].(map[string]interface{})) + apiObject.Value = expandEKSInfo(v[0].(map[string]interface{})) } return apiObject } -func expandEKSInfo(tfMap map[string]interface{}) *emrcontainers.EksInfo { - if tfMap == nil { - return nil - } - - apiObject := &emrcontainers.EksInfo{} +func expandEKSInfo(tfMap map[string]interface{}) awstypes.EksInfo { + apiObject := awstypes.EksInfo{} if v, ok := tfMap[names.AttrNamespace].(string); ok && v != "" { apiObject.Namespace = aws.String(v) @@ -259,7 +330,7 @@ func expandEKSInfo(tfMap map[string]interface{}) *emrcontainers.EksInfo { return apiObject } -func flattenContainerProvider(apiObject *emrcontainers.ContainerProvider) map[string]interface{} { +func flattenContainerProvider(apiObject *awstypes.ContainerProvider) map[string]interface{} { if apiObject == nil { return nil } @@ -267,35 +338,34 @@ func flattenContainerProvider(apiObject *emrcontainers.ContainerProvider) map[st tfMap := map[string]interface{}{} if v := apiObject.Id; v != nil { - tfMap[names.AttrID] = aws.StringValue(v) + tfMap[names.AttrID] = aws.ToString(v) } if v := apiObject.Info; v != nil { tfMap["info"] = []interface{}{flattenContainerInfo(v)} } - if v := apiObject.Type; v != nil { - tfMap[names.AttrType] = aws.StringValue(v) - } + tfMap[names.AttrType] = string(apiObject.Type) return tfMap } -func flattenContainerInfo(apiObject *emrcontainers.ContainerInfo) map[string]interface{} { +func flattenContainerInfo(apiObject awstypes.ContainerInfo) map[string]interface{} { if apiObject == nil { return nil } tfMap := map[string]interface{}{} - if v := apiObject.EksInfo; v != nil { - tfMap["eks_info"] = []interface{}{flattenEKSInfo(v)} + switch v := apiObject.(type) { + case *awstypes.ContainerInfoMemberEksInfo: + tfMap["eks_info"] = []interface{}{flattenEKSInfo(&v.Value)} } return tfMap } -func flattenEKSInfo(apiObject *emrcontainers.EksInfo) map[string]interface{} { +func flattenEKSInfo(apiObject *awstypes.EksInfo) map[string]interface{} { if apiObject == nil { return nil } @@ -303,84 +373,8 @@ func flattenEKSInfo(apiObject *emrcontainers.EksInfo) map[string]interface{} { tfMap := map[string]interface{}{} if v := apiObject.Namespace; v != nil { - tfMap[names.AttrNamespace] = aws.StringValue(v) + tfMap[names.AttrNamespace] = aws.ToString(v) } return tfMap } - -func findVirtualCluster(ctx context.Context, conn *emrcontainers.EMRContainers, input *emrcontainers.DescribeVirtualClusterInput) (*emrcontainers.VirtualCluster, error) { - output, err := conn.DescribeVirtualClusterWithContext(ctx, input) - - if tfawserr.ErrCodeEquals(err, emrcontainers.ErrCodeResourceNotFoundException) { - return nil, &retry.NotFoundError{ - LastError: err, - LastRequest: input, - } - } - - if err != nil { - return nil, err - } - - if output == nil || output.VirtualCluster == nil { - return nil, tfresource.NewEmptyResultError(input) - } - - return output.VirtualCluster, nil -} - -func FindVirtualClusterByID(ctx context.Context, conn *emrcontainers.EMRContainers, id string) (*emrcontainers.VirtualCluster, error) { - input := &emrcontainers.DescribeVirtualClusterInput{ - Id: aws.String(id), - } - - output, err := findVirtualCluster(ctx, conn, input) - - if err != nil { - return nil, err - } - - if state := aws.StringValue(output.State); state == emrcontainers.VirtualClusterStateTerminated { - return nil, &retry.NotFoundError{ - Message: state, - LastRequest: input, - } - } - - return output, nil -} - -func statusVirtualCluster(ctx context.Context, conn *emrcontainers.EMRContainers, id string) retry.StateRefreshFunc { - return func() (interface{}, string, error) { - output, err := FindVirtualClusterByID(ctx, conn, id) - - if tfresource.NotFound(err) { - return nil, "", nil - } - - if err != nil { - return nil, "", err - } - - return output, aws.StringValue(output.State), nil - } -} - -func waitVirtualClusterDeleted(ctx context.Context, conn *emrcontainers.EMRContainers, id string, timeout time.Duration) (*emrcontainers.VirtualCluster, error) { - stateConf := &retry.StateChangeConf{ - Pending: []string{emrcontainers.VirtualClusterStateTerminating}, - Target: []string{}, - Refresh: statusVirtualCluster(ctx, conn, id), - Timeout: timeout, - Delay: 1 * time.Minute, - } - - outputRaw, err := stateConf.WaitForStateContext(ctx) - - if v, ok := outputRaw.(*emrcontainers.VirtualCluster); ok { - return v, err - } - - return nil, err -} diff --git a/internal/service/emrcontainers/virtual_cluster_data_source.go b/internal/service/emrcontainers/virtual_cluster_data_source.go index 0781a864ba7..58b51966847 100644 --- a/internal/service/emrcontainers/virtual_cluster_data_source.go +++ b/internal/service/emrcontainers/virtual_cluster_data_source.go @@ -6,7 +6,7 @@ package emrcontainers import ( "context" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -15,8 +15,9 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -// @SDKDataSource("aws_emrcontainers_virtual_cluster") -func DataSourceVirtualCluster() *schema.Resource { +// @SDKDataSource("aws_emrcontainers_virtual_cluster", name="Virtual Cluster") +// @Tags +func dataSourceVirtualCluster() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: dataSourceVirtualClusterRead, @@ -84,18 +85,16 @@ func DataSourceVirtualCluster() *schema.Resource { func dataSourceVirtualClusterRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - - conn := meta.(*conns.AWSClient).EMRContainersConn(ctx) - ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig + conn := meta.(*conns.AWSClient).EMRContainersClient(ctx) id := d.Get("virtual_cluster_id").(string) - vc, err := FindVirtualClusterByID(ctx, conn, id) + vc, err := findVirtualClusterByID(ctx, conn, id) if err != nil { return sdkdiag.AppendErrorf(diags, "reading EMR Containers Virtual Cluster (%s): %s", id, err) } - d.SetId(aws.StringValue(vc.Id)) + d.SetId(aws.ToString(vc.Id)) d.Set(names.AttrARN, vc.Arn) if vc.ContainerProvider != nil { if err := d.Set("container_provider", []interface{}{flattenContainerProvider(vc.ContainerProvider)}); err != nil { @@ -104,14 +103,12 @@ func dataSourceVirtualClusterRead(ctx context.Context, d *schema.ResourceData, m } else { d.Set("container_provider", nil) } - d.Set(names.AttrCreatedAt, aws.TimeValue(vc.CreatedAt).String()) + d.Set(names.AttrCreatedAt, aws.ToTime(vc.CreatedAt).String()) d.Set(names.AttrName, vc.Name) d.Set(names.AttrState, vc.State) d.Set("virtual_cluster_id", vc.Id) - if err := d.Set(names.AttrTags, KeyValueTags(ctx, vc.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { - return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) - } + setTagsOut(ctx, vc.Tags) return diags } diff --git a/internal/service/emrcontainers/virtual_cluster_test.go b/internal/service/emrcontainers/virtual_cluster_test.go index 1a0e4e221d0..00fd339d298 100644 --- a/internal/service/emrcontainers/virtual_cluster_test.go +++ b/internal/service/emrcontainers/virtual_cluster_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/emrcontainers" + awstypes "github.com/aws/aws-sdk-go-v2/service/emrcontainers/types" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -21,7 +21,7 @@ import ( func TestAccEMRContainersVirtualCluster_basic(t *testing.T) { ctx := acctest.Context(t) - var v emrcontainers.VirtualCluster + var v awstypes.VirtualCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_emrcontainers_virtual_cluster.test" testExternalProviders := map[string]resource.ExternalProvider{ @@ -77,7 +77,7 @@ func TestAccEMRContainersVirtualCluster_basic(t *testing.T) { func TestAccEMRContainersVirtualCluster_disappears(t *testing.T) { ctx := acctest.Context(t) - var v emrcontainers.VirtualCluster + var v awstypes.VirtualCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_emrcontainers_virtual_cluster.test" testExternalProviders := map[string]resource.ExternalProvider{ @@ -111,7 +111,7 @@ func TestAccEMRContainersVirtualCluster_disappears(t *testing.T) { func TestAccEMRContainersVirtualCluster_tags(t *testing.T) { ctx := acctest.Context(t) - var v emrcontainers.VirtualCluster + var v awstypes.VirtualCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_emrcontainers_virtual_cluster.test" testExternalProviders := map[string]resource.ExternalProvider{ @@ -160,7 +160,7 @@ func TestAccEMRContainersVirtualCluster_tags(t *testing.T) { }) } -func testAccCheckVirtualClusterExists(ctx context.Context, n string, v *emrcontainers.VirtualCluster) resource.TestCheckFunc { +func testAccCheckVirtualClusterExists(ctx context.Context, n string, v *awstypes.VirtualCluster) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -171,7 +171,7 @@ func testAccCheckVirtualClusterExists(ctx context.Context, n string, v *emrconta return fmt.Errorf("No EMR Containers Virtual Cluster ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).EMRContainersConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EMRContainersClient(ctx) output, err := tfemrcontainers.FindVirtualClusterByID(ctx, conn, rs.Primary.ID) @@ -187,7 +187,7 @@ func testAccCheckVirtualClusterExists(ctx context.Context, n string, v *emrconta func testAccCheckVirtualClusterDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).EMRContainersConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).EMRContainersClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_emrcontainers_virtual_cluster" { diff --git a/names/data/names_data.hcl b/names/data/names_data.hcl index 22e80790113..db22ffc049f 100644 --- a/names/data/names_data.hcl +++ b/names/data/names_data.hcl @@ -3800,7 +3800,7 @@ service "emrcontainers" { sdk { id = "EMR containers" - client_version = [1] + client_version = [2] } names {