diff --git a/.ci/.golangci2.yml b/.ci/.golangci2.yml index dc927d801be..fb7cb755ea4 100644 --- a/.ci/.golangci2.yml +++ b/.ci/.golangci2.yml @@ -173,6 +173,7 @@ linters-settings: - argument ignored-functions: # AWS Go SDK + - aws.Int32 - aws.Int64 - request.ConstantWaiterDelay - request.WithWaiterMaxAttempts diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index 1695bb17db5..caa4b24f2ed 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -195,7 +195,6 @@ import ( mediaconvert_sdkv1 "github.com/aws/aws-sdk-go/service/mediaconvert" mediastore_sdkv1 "github.com/aws/aws-sdk-go/service/mediastore" memorydb_sdkv1 "github.com/aws/aws-sdk-go/service/memorydb" - mq_sdkv1 "github.com/aws/aws-sdk-go/service/mq" mwaa_sdkv1 "github.com/aws/aws-sdk-go/service/mwaa" neptune_sdkv1 "github.com/aws/aws-sdk-go/service/neptune" networkfirewall_sdkv1 "github.com/aws/aws-sdk-go/service/networkfirewall" @@ -798,10 +797,6 @@ func (c *AWSClient) LookoutMetricsClient(ctx context.Context) *lookoutmetrics_sd return errs.Must(client[*lookoutmetrics_sdkv2.Client](ctx, c, names.LookoutMetrics, make(map[string]any))) } -func (c *AWSClient) MQConn(ctx context.Context) *mq_sdkv1.MQ { - return errs.Must(conn[*mq_sdkv1.MQ](ctx, c, names.MQ, make(map[string]any))) -} - func (c *AWSClient) MQClient(ctx context.Context) *mq_sdkv2.Client { return errs.Must(client[*mq_sdkv2.Client](ctx, c, names.MQ, make(map[string]any))) } diff --git a/internal/enum/validate.go b/internal/enum/validate.go index 5346d0c621a..37b53d7f958 100644 --- a/internal/enum/validate.go +++ b/internal/enum/validate.go @@ -11,7 +11,15 @@ import ( ) func Validate[T Valueser[T]]() schema.SchemaValidateDiagFunc { - return validation.ToDiagFunc(validation.StringInSlice(Values[T](), false)) + return validate[T](false) +} + +func ValidateIgnoreCase[T Valueser[T]]() schema.SchemaValidateDiagFunc { + return validate[T](true) +} + +func validate[T Valueser[T]](ignoreCase bool) schema.SchemaValidateDiagFunc { + return validation.ToDiagFunc(validation.StringInSlice(Values[T](), ignoreCase)) } // TODO Move to internal/framework/validators or replace with custom types. diff --git a/internal/service/lambda/event_source_mapping_test.go b/internal/service/lambda/event_source_mapping_test.go index 011337c5e94..31efbc020dc 100644 --- a/internal/service/lambda/event_source_mapping_test.go +++ b/internal/service/lambda/event_source_mapping_test.go @@ -10,10 +10,10 @@ import ( "testing" "time" + "github.com/aws/aws-sdk-go-v2/service/kafka" + "github.com/aws/aws-sdk-go-v2/service/mq" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/kafka" "github.com/aws/aws-sdk-go/service/lambda" - "github.com/aws/aws-sdk-go/service/mq" "github.com/aws/aws-sdk-go/service/secretsmanager" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" @@ -1210,11 +1210,11 @@ func TestAccLambdaEventSourceMapping_documentDB(t *testing.T) { } func testAccPreCheckMQ(ctx context.Context, t *testing.T) { - conn := acctest.Provider.Meta().(*conns.AWSClient).MQConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MQClient(ctx) input := &mq.ListBrokersInput{} - _, err := conn.ListBrokersWithContext(ctx, input) + _, err := conn.ListBrokers(ctx, input) if acctest.PreCheckSkipError(err) { t.Skipf("skipping acceptance testing: %s", err) @@ -1226,11 +1226,11 @@ func testAccPreCheckMQ(ctx context.Context, t *testing.T) { } func testAccPreCheckMSK(ctx context.Context, t *testing.T) { - conn := acctest.Provider.Meta().(*conns.AWSClient).KafkaConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).KafkaClient(ctx) input := &kafka.ListClustersInput{} - _, err := conn.ListClustersWithContext(ctx, input) + _, err := conn.ListClusters(ctx, input) if acctest.PreCheckSkipError(err) { t.Skipf("skipping acceptance testing: %s", err) diff --git a/internal/service/mq/broker.go b/internal/service/mq/broker.go index 6662dd4d308..4bd2bb81700 100644 --- a/internal/service/mq/broker.go +++ b/internal/service/mq/broker.go @@ -15,9 +15,9 @@ import ( "time" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/mq" - "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/mq" + "github.com/aws/aws-sdk-go-v2/service/mq/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" @@ -26,6 +26,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/create" + "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" @@ -38,7 +40,7 @@ import ( // @SDKResource("aws_mq_broker", name="Broker") // @Tags(identifierAttribute="arn") -func ResourceBroker() *schema.Resource { +func resourceBroker() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceBrokerCreate, ReadWithoutTimeout: resourceBrokerRead, @@ -66,10 +68,10 @@ func ResourceBroker() *schema.Resource { Computed: true, }, "authentication_strategy": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(mq.AuthenticationStrategy_Values(), true), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.ValidateIgnoreCase[types.AuthenticationStrategy](), }, "auto_minor_version_upgrade": { Type: schema.TypeBool, @@ -103,11 +105,11 @@ func ResourceBroker() *schema.Resource { }, }, "deployment_mode": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Default: mq.DeploymentModeSingleInstance, - ValidateFunc: validation.StringInSlice(mq.DeploymentMode_Values(), true), + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Default: types.DeploymentModeSingleInstance, + ValidateDiagFunc: enum.ValidateIgnoreCase[types.DeploymentMode](), }, "encryption_options": { Type: schema.TypeList, @@ -134,10 +136,10 @@ func ResourceBroker() *schema.Resource { }, }, "engine_type": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice(mq.EngineType_Values(), true), + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateDiagFunc: enum.ValidateIgnoreCase[types.EngineType](), }, "engine_version": { Type: schema.TypeString, @@ -252,9 +254,9 @@ func ResourceBroker() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "day_of_week": { - Type: schema.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice(mq.DayOfWeek_Values(), true), + Type: schema.TypeString, + Required: true, + ValidateDiagFunc: enum.ValidateIgnoreCase[types.DayOfWeek](), }, "time_of_day": { Type: schema.TypeString, @@ -280,10 +282,10 @@ func ResourceBroker() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, }, "storage_type": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(mq.BrokerStorageType_Values(), true), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.ValidateIgnoreCase[types.BrokerStorageType](), }, "subnet_ids": { Type: schema.TypeSet, @@ -302,7 +304,7 @@ func ResourceBroker() *schema.Resource { // AWS currently does not support updating the RabbitMQ users beyond resource creation. // User list is not returned back after creation. // Updates to users can only be in the RabbitMQ UI. - if v := d.Get("engine_type").(string); strings.EqualFold(v, mq.EngineTypeRabbitmq) && d.Get("arn").(string) != "" { + if v := d.Get("engine_type").(string); strings.EqualFold(v, string(types.EngineTypeRabbitmq)) && d.Get("arn").(string) != "" { return true } @@ -348,7 +350,7 @@ func ResourceBroker() *schema.Resource { CustomizeDiff: customdiff.All( verify.SetTagsDiff, func(_ context.Context, diff *schema.ResourceDiff, v interface{}) error { - if strings.EqualFold(diff.Get("engine_type").(string), mq.EngineTypeRabbitmq) { + if strings.EqualFold(diff.Get("engine_type").(string), string(types.EngineTypeRabbitmq)) { if v, ok := diff.GetOk("logs.0.audit"); ok { if v, _, _ := nullable.Bool(v.(string)).Value(); v { return errors.New("logs.audit: Can not be configured when engine is RabbitMQ") @@ -365,15 +367,15 @@ func ResourceBroker() *schema.Resource { func resourceBrokerCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MQConn(ctx) + conn := meta.(*conns.AWSClient).MQClient(ctx) name := d.Get("broker_name").(string) engineType := d.Get("engine_type").(string) - input := &mq.CreateBrokerRequest{ + input := &mq.CreateBrokerInput{ AutoMinorVersionUpgrade: aws.Bool(d.Get("auto_minor_version_upgrade").(bool)), BrokerName: aws.String(name), CreatorRequestId: aws.String(id.PrefixedUniqueId(fmt.Sprintf("tf-%s", name))), - EngineType: aws.String(engineType), + EngineType: types.EngineType(engineType), EngineVersion: aws.String(d.Get("engine_version").(string)), HostInstanceType: aws.String(d.Get("host_instance_type").(string)), PubliclyAccessible: aws.Bool(d.Get("publicly_accessible").(bool)), @@ -382,13 +384,13 @@ func resourceBrokerCreate(ctx context.Context, d *schema.ResourceData, meta inte } if v, ok := d.GetOk("authentication_strategy"); ok { - input.AuthenticationStrategy = aws.String(v.(string)) + input.AuthenticationStrategy = types.AuthenticationStrategy(v.(string)) } if v, ok := d.GetOk("configuration"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { input.Configuration = expandConfigurationId(v.([]interface{})) } if v, ok := d.GetOk("deployment_mode"); ok { - input.DeploymentMode = aws.String(v.(string)) + input.DeploymentMode = types.DeploymentMode(v.(string)) } if v, ok := d.GetOk("encryption_options"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { input.EncryptionOptions = expandEncryptionOptions(d.Get("encryption_options").([]interface{})) @@ -403,23 +405,23 @@ func resourceBrokerCreate(ctx context.Context, d *schema.ResourceData, meta inte input.MaintenanceWindowStartTime = expandWeeklyStartTime(v.([]interface{})) } if v, ok := d.GetOk("security_groups"); ok && v.(*schema.Set).Len() > 0 { - input.SecurityGroups = flex.ExpandStringSet(v.(*schema.Set)) + input.SecurityGroups = flex.ExpandStringValueSet(v.(*schema.Set)) } if v, ok := d.GetOk("storage_type"); ok { - input.StorageType = aws.String(v.(string)) + input.StorageType = types.BrokerStorageType(v.(string)) } if v, ok := d.GetOk("subnet_ids"); ok { - input.SubnetIds = flex.ExpandStringSet(v.(*schema.Set)) + input.SubnetIds = flex.ExpandStringValueSet(v.(*schema.Set)) } - out, err := conn.CreateBrokerWithContext(ctx, input) + output, err := conn.CreateBroker(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating MQ Broker (%s): %s", name, err) } - d.SetId(aws.StringValue(out.BrokerId)) - d.Set("arn", out.BrokerArn) + d.SetId(aws.ToString(output.BrokerId)) + d.Set("arn", output.BrokerArn) if _, err := waitBrokerCreated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for MQ Broker (%s) create: %s", d.Id(), err) @@ -431,11 +433,11 @@ func resourceBrokerCreate(ctx context.Context, d *schema.ResourceData, meta inte func resourceBrokerRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MQConn(ctx) + conn := meta.(*conns.AWSClient).MQClient(ctx) - output, err := FindBrokerByID(ctx, conn, d.Id()) + output, err := findBrokerByID(ctx, conn, d.Id()) - if !d.IsNewResource() && (tfresource.NotFound(err) || tfawserr.ErrCodeEquals(err, mq.ErrCodeForbiddenException)) { + if !d.IsNewResource() && (tfresource.NotFound(err) || errs.IsA[*types.ForbiddenException](err)) { log.Printf("[WARN] MQ Broker (%s) not found, removing from state", d.Id()) d.SetId("") return diags @@ -455,9 +457,9 @@ func resourceBrokerRead(ctx context.Context, d *schema.ResourceData, meta interf d.Set("host_instance_type", output.HostInstanceType) d.Set("instances", flattenBrokerInstances(output.BrokerInstances)) d.Set("publicly_accessible", output.PubliclyAccessible) - d.Set("security_groups", aws.StringValueSlice(output.SecurityGroups)) + d.Set("security_groups", output.SecurityGroups) d.Set("storage_type", output.StorageType) - d.Set("subnet_ids", aws.StringValueSlice(output.SubnetIds)) + d.Set("subnet_ids", output.SubnetIds) if err := d.Set("configuration", flattenConfiguration(output.Configurations)); err != nil { return sdkdiag.AppendErrorf(diags, "setting configuration: %s", err) @@ -502,15 +504,17 @@ func resourceBrokerRead(ctx context.Context, d *schema.ResourceData, meta interf func resourceBrokerUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MQConn(ctx) + conn := meta.(*conns.AWSClient).MQClient(ctx) requiresReboot := false if d.HasChange("security_groups") { - _, err := conn.UpdateBrokerWithContext(ctx, &mq.UpdateBrokerRequest{ + input := &mq.UpdateBrokerInput{ BrokerId: aws.String(d.Id()), - SecurityGroups: flex.ExpandStringSet(d.Get("security_groups").(*schema.Set)), - }) + SecurityGroups: flex.ExpandStringValueSet(d.Get("security_groups").(*schema.Set)), + } + + _, err := conn.UpdateBroker(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating MQ Broker (%s) security groups: %s", d.Id(), err) @@ -518,12 +522,14 @@ func resourceBrokerUpdate(ctx context.Context, d *schema.ResourceData, meta inte } if d.HasChanges("configuration", "logs", "engine_version") { - _, err := conn.UpdateBrokerWithContext(ctx, &mq.UpdateBrokerRequest{ + input := &mq.UpdateBrokerInput{ BrokerId: aws.String(d.Id()), Configuration: expandConfigurationId(d.Get("configuration").([]interface{})), EngineVersion: aws.String(d.Get("engine_version").(string)), Logs: expandLogs(d.Get("engine_type").(string), d.Get("logs").([]interface{})), - }) + } + + _, err := conn.UpdateBroker(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating MQ Broker (%s) configuration: %s", d.Id(), err) @@ -550,10 +556,12 @@ func resourceBrokerUpdate(ctx context.Context, d *schema.ResourceData, meta inte } if d.HasChange("host_instance_type") { - _, err := conn.UpdateBrokerWithContext(ctx, &mq.UpdateBrokerRequest{ + input := &mq.UpdateBrokerInput{ BrokerId: aws.String(d.Id()), HostInstanceType: aws.String(d.Get("host_instance_type").(string)), - }) + } + + _, err := conn.UpdateBroker(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating MQ Broker (%s) host instance type: %s", d.Id(), err) @@ -563,10 +571,12 @@ func resourceBrokerUpdate(ctx context.Context, d *schema.ResourceData, meta inte } if d.HasChange("auto_minor_version_upgrade") { - _, err := conn.UpdateBrokerWithContext(ctx, &mq.UpdateBrokerRequest{ - BrokerId: aws.String(d.Id()), + input := &mq.UpdateBrokerInput{ AutoMinorVersionUpgrade: aws.Bool(d.Get("auto_minor_version_upgrade").(bool)), - }) + BrokerId: aws.String(d.Id()), + } + + _, err := conn.UpdateBroker(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating MQ Broker (%s) auto minor version upgrade: %s", d.Id(), err) @@ -576,10 +586,12 @@ func resourceBrokerUpdate(ctx context.Context, d *schema.ResourceData, meta inte } if d.HasChange("maintenance_window_start_time") { - _, err := conn.UpdateBrokerWithContext(ctx, &mq.UpdateBrokerRequest{ + input := &mq.UpdateBrokerInput{ BrokerId: aws.String(d.Id()), MaintenanceWindowStartTime: expandWeeklyStartTime(d.Get("maintenance_window_start_time").([]interface{})), - }) + } + + _, err := conn.UpdateBroker(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating MQ Broker (%s) maintenance window start time: %s", d.Id(), err) @@ -589,7 +601,7 @@ func resourceBrokerUpdate(ctx context.Context, d *schema.ResourceData, meta inte } if d.Get("apply_immediately").(bool) && requiresReboot { - _, err := conn.RebootBrokerWithContext(ctx, &mq.RebootBrokerInput{ + _, err := conn.RebootBroker(ctx, &mq.RebootBrokerInput{ BrokerId: aws.String(d.Id()), }) @@ -608,14 +620,14 @@ func resourceBrokerUpdate(ctx context.Context, d *schema.ResourceData, meta inte func resourceBrokerDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MQConn(ctx) + conn := meta.(*conns.AWSClient).MQClient(ctx) log.Printf("[INFO] Deleting MQ Broker: %s", d.Id()) - _, err := conn.DeleteBrokerWithContext(ctx, &mq.DeleteBrokerInput{ + _, err := conn.DeleteBroker(ctx, &mq.DeleteBrokerInput{ BrokerId: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, mq.ErrCodeNotFoundException) { + if errs.IsA[*types.NotFoundException](err) { return diags } @@ -630,14 +642,14 @@ func resourceBrokerDelete(ctx context.Context, d *schema.ResourceData, meta inte return diags } -func FindBrokerByID(ctx context.Context, conn *mq.MQ, id string) (*mq.DescribeBrokerResponse, error) { +func findBrokerByID(ctx context.Context, conn *mq.Client, id string) (*mq.DescribeBrokerOutput, error) { input := &mq.DescribeBrokerInput{ BrokerId: aws.String(id), } - output, err := conn.DescribeBrokerWithContext(ctx, input) + output, err := conn.DescribeBroker(ctx, input) - if tfawserr.ErrCodeEquals(err, mq.ErrCodeNotFoundException) { + if errs.IsA[*types.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -655,9 +667,9 @@ func FindBrokerByID(ctx context.Context, conn *mq.MQ, id string) (*mq.DescribeBr return output, nil } -func statusBrokerState(ctx context.Context, conn *mq.MQ, id string) retry.StateRefreshFunc { +func statusBrokerState(ctx context.Context, conn *mq.Client, id string) retry.StateRefreshFunc { return func() (interface{}, string, error) { - output, err := FindBrokerByID(ctx, conn, id) + output, err := findBrokerByID(ctx, conn, id) if tfresource.NotFound(err) { return nil, "", nil @@ -667,57 +679,57 @@ func statusBrokerState(ctx context.Context, conn *mq.MQ, id string) retry.StateR return nil, "", err } - return output, aws.StringValue(output.BrokerState), nil + return output, string(output.BrokerState), nil } } -func waitBrokerCreated(ctx context.Context, conn *mq.MQ, id string, timeout time.Duration) (*mq.DescribeBrokerResponse, error) { +func waitBrokerCreated(ctx context.Context, conn *mq.Client, id string, timeout time.Duration) (*mq.DescribeBrokerOutput, error) { stateConf := retry.StateChangeConf{ - Pending: []string{mq.BrokerStateCreationInProgress, mq.BrokerStateRebootInProgress}, - Target: []string{mq.BrokerStateRunning}, + Pending: enum.Slice(types.BrokerStateCreationInProgress, types.BrokerStateRebootInProgress), + Target: enum.Slice(types.BrokerStateRunning), Timeout: timeout, Refresh: statusBrokerState(ctx, conn, id), } outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*mq.DescribeBrokerResponse); ok { + if output, ok := outputRaw.(*mq.DescribeBrokerOutput); ok { return output, err } return nil, err } -func waitBrokerDeleted(ctx context.Context, conn *mq.MQ, id string, timeout time.Duration) (*mq.DescribeBrokerResponse, error) { +func waitBrokerDeleted(ctx context.Context, conn *mq.Client, id string, timeout time.Duration) (*mq.DescribeBrokerOutput, error) { stateConf := retry.StateChangeConf{ - Pending: []string{ - mq.BrokerStateCreationFailed, - mq.BrokerStateDeletionInProgress, - mq.BrokerStateRebootInProgress, - mq.BrokerStateRunning, - }, + Pending: enum.Slice( + types.BrokerStateCreationFailed, + types.BrokerStateDeletionInProgress, + types.BrokerStateRebootInProgress, + types.BrokerStateRunning, + ), Target: []string{}, Timeout: timeout, Refresh: statusBrokerState(ctx, conn, id), } outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*mq.DescribeBrokerResponse); ok { + if output, ok := outputRaw.(*mq.DescribeBrokerOutput); ok { return output, err } return nil, err } -func waitBrokerRebooted(ctx context.Context, conn *mq.MQ, id string, timeout time.Duration) (*mq.DescribeBrokerResponse, error) { +func waitBrokerRebooted(ctx context.Context, conn *mq.Client, id string, timeout time.Duration) (*mq.DescribeBrokerOutput, error) { stateConf := retry.StateChangeConf{ - Pending: []string{mq.BrokerStateRebootInProgress}, - Target: []string{mq.BrokerStateRunning}, + Pending: enum.Slice(types.BrokerStateRebootInProgress), + Target: enum.Slice(types.BrokerStateRunning), Timeout: timeout, Refresh: statusBrokerState(ctx, conn, id), } outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*mq.DescribeBrokerResponse); ok { + if output, ok := outputRaw.(*mq.DescribeBrokerOutput); ok { return output, err } @@ -734,7 +746,7 @@ func resourceUserHash(v interface{}) int { buf.WriteString("false-") } if g, ok := m["groups"]; ok { - buf.WriteString(fmt.Sprintf("%v-", g.(*schema.Set).List())) + buf.WriteString(fmt.Sprintf("%v-", g.([]string))) } if p, ok := m["password"]; ok { buf.WriteString(fmt.Sprintf("%s-", p.(string))) @@ -744,31 +756,31 @@ func resourceUserHash(v interface{}) int { return create.StringHashcode(buf.String()) } -func updateBrokerUsers(ctx context.Context, conn *mq.MQ, bId string, oldUsers, newUsers []interface{}) (bool, error) { +func updateBrokerUsers(ctx context.Context, conn *mq.Client, id string, oldUsers, newUsers []interface{}) (bool, error) { // If there are any user creates/deletes/updates, updatedUsers will be set to true updatedUsers := false - createL, deleteL, updateL, err := DiffBrokerUsers(bId, oldUsers, newUsers) + createL, deleteL, updateL, err := DiffBrokerUsers(id, oldUsers, newUsers) if err != nil { return updatedUsers, err } for _, c := range createL { - _, err := conn.CreateUserWithContext(ctx, c) + _, err := conn.CreateUser(ctx, c) updatedUsers = true if err != nil { return updatedUsers, err } } for _, d := range deleteL { - _, err := conn.DeleteUserWithContext(ctx, d) + _, err := conn.DeleteUser(ctx, d) updatedUsers = true if err != nil { return updatedUsers, err } } for _, u := range updateL { - _, err := conn.UpdateUserWithContext(ctx, u) + _, err := conn.UpdateUser(ctx, u) updatedUsers = true if err != nil { return updatedUsers, err @@ -778,8 +790,7 @@ func updateBrokerUsers(ctx context.Context, conn *mq.MQ, bId string, oldUsers, n return updatedUsers, nil } -func DiffBrokerUsers(bId string, oldUsers, newUsers []interface{}) ( - cr []*mq.CreateUserRequest, di []*mq.DeleteUserInput, ur []*mq.UpdateUserRequest, e error) { +func DiffBrokerUsers(bId string, oldUsers, newUsers []interface{}) (cr []*mq.CreateUserInput, di []*mq.DeleteUserInput, ur []*mq.UpdateUserInput, e error) { existingUsers := make(map[string]interface{}) for _, ou := range oldUsers { u := ou.(map[string]interface{}) @@ -819,10 +830,10 @@ func DiffBrokerUsers(bId string, oldUsers, newUsers []interface{}) ( existingUserMap := eu.(map[string]interface{}) if !reflect.DeepEqual(existingUserMap, newUserMap) { - ur = append(ur, &mq.UpdateUserRequest{ + ur = append(ur, &mq.UpdateUserInput{ BrokerId: aws.String(bId), ConsoleAccess: aws.Bool(newUserMap["console_access"].(bool)), - Groups: flex.ExpandStringList(ng), + Groups: flex.ExpandStringValueList(ng), ReplicationUser: aws.Bool(newUserMap["replication_user"].(bool)), Password: aws.String(newUserMap["password"].(string)), Username: aws.String(username), @@ -832,7 +843,7 @@ func DiffBrokerUsers(bId string, oldUsers, newUsers []interface{}) ( // Delete after processing, so we know what's left for deletion delete(existingUsers, username) } else { - cur := &mq.CreateUserRequest{ + cur := &mq.CreateUserInput{ BrokerId: aws.String(bId), ConsoleAccess: aws.Bool(newUserMap["console_access"].(bool)), Password: aws.String(newUserMap["password"].(string)), @@ -840,7 +851,7 @@ func DiffBrokerUsers(bId string, oldUsers, newUsers []interface{}) ( Username: aws.String(username), } if len(ng) > 0 { - cur.Groups = flex.ExpandStringList(ng) + cur.Groups = flex.ExpandStringValueList(ng) } cr = append(cr, cur) } @@ -856,14 +867,14 @@ func DiffBrokerUsers(bId string, oldUsers, newUsers []interface{}) ( return cr, di, ur, nil } -func expandEncryptionOptions(l []interface{}) *mq.EncryptionOptions { +func expandEncryptionOptions(l []interface{}) *types.EncryptionOptions { if len(l) == 0 || l[0] == nil { return nil } m := l[0].(map[string]interface{}) - encryptionOptions := &mq.EncryptionOptions{ + encryptionOptions := &types.EncryptionOptions{ UseAwsOwnedKey: aws.Bool(m["use_aws_owned_key"].(bool)), } @@ -874,14 +885,14 @@ func expandEncryptionOptions(l []interface{}) *mq.EncryptionOptions { return encryptionOptions } -func flattenEncryptionOptions(encryptionOptions *mq.EncryptionOptions) []interface{} { +func flattenEncryptionOptions(encryptionOptions *types.EncryptionOptions) []interface{} { if encryptionOptions == nil { return []interface{}{} } m := map[string]interface{}{ - "kms_key_id": aws.StringValue(encryptionOptions.KmsKeyId), - "use_aws_owned_key": aws.BoolValue(encryptionOptions.UseAwsOwnedKey), + "kms_key_id": aws.ToString(encryptionOptions.KmsKeyId), + "use_aws_owned_key": aws.ToBool(encryptionOptions.UseAwsOwnedKey), } return []interface{}{m} @@ -912,11 +923,11 @@ func ValidBrokerPassword(v interface{}, k string) (ws []string, errors []error) return } -func expandUsers(cfg []interface{}) []*mq.User { - users := make([]*mq.User, len(cfg)) +func expandUsers(cfg []interface{}) []types.User { + users := make([]types.User, len(cfg)) for i, m := range cfg { u := m.(map[string]interface{}) - user := mq.User{ + user := types.User{ Username: aws.String(u["username"].(string)), Password: aws.String(u["password"].(string)), } @@ -927,22 +938,18 @@ func expandUsers(cfg []interface{}) []*mq.User { user.ReplicationUser = aws.Bool(v.(bool)) } if v, ok := u["groups"]; ok { - user.Groups = flex.ExpandStringSet(v.(*schema.Set)) + user.Groups = flex.ExpandStringValueSet(v.(*schema.Set)) } - users[i] = &user + users[i] = user } return users } -func expandUsersForBroker(ctx context.Context, conn *mq.MQ, brokerId string, input []*mq.UserSummary) ([]*mq.User, error) { - var rawUsers []*mq.User +func expandUsersForBroker(ctx context.Context, conn *mq.Client, brokerId string, input []types.UserSummary) ([]*types.User, error) { + var rawUsers []*types.User for _, u := range input { - if u == nil { - continue - } - - uOut, err := conn.DescribeUserWithContext(ctx, &mq.DescribeUserInput{ + uOut, err := conn.DescribeUser(ctx, &mq.DescribeUserInput{ BrokerId: aws.String(brokerId), Username: u.Username, }) @@ -951,7 +958,7 @@ func expandUsersForBroker(ctx context.Context, conn *mq.MQ, brokerId string, inp return nil, err } - user := &mq.User{ + user := &types.User{ ConsoleAccess: uOut.ConsoleAccess, Groups: uOut.Groups, ReplicationUser: uOut.ReplicationUser, @@ -965,7 +972,7 @@ func expandUsersForBroker(ctx context.Context, conn *mq.MQ, brokerId string, inp } // We use cfgdUsers to get & set the password -func flattenUsers(users []*mq.User, cfgUsers []interface{}) *schema.Set { +func flattenUsers(users []*types.User, cfgUsers []interface{}) *schema.Set { existingPairs := make(map[string]string) for _, u := range cfgUsers { user := u.(map[string]interface{}) @@ -976,89 +983,89 @@ func flattenUsers(users []*mq.User, cfgUsers []interface{}) *schema.Set { out := make([]interface{}, 0) for _, u := range users { m := map[string]interface{}{ - "username": aws.StringValue(u.Username), + "username": aws.ToString(u.Username), } password := "" - if p, ok := existingPairs[aws.StringValue(u.Username)]; ok { + if p, ok := existingPairs[aws.ToString(u.Username)]; ok { password = p } if password != "" { m["password"] = password } if u.ConsoleAccess != nil { - m["console_access"] = aws.BoolValue(u.ConsoleAccess) + m["console_access"] = aws.ToBool(u.ConsoleAccess) } if u.ReplicationUser != nil { - m["replication_user"] = aws.BoolValue(u.ReplicationUser) + m["replication_user"] = aws.ToBool(u.ReplicationUser) } if len(u.Groups) > 0 { - m["groups"] = flex.FlattenStringSet(u.Groups) + m["groups"] = u.Groups } out = append(out, m) } return schema.NewSet(resourceUserHash, out) } -func expandWeeklyStartTime(cfg []interface{}) *mq.WeeklyStartTime { +func expandWeeklyStartTime(cfg []interface{}) *types.WeeklyStartTime { if len(cfg) < 1 { return nil } m := cfg[0].(map[string]interface{}) - return &mq.WeeklyStartTime{ - DayOfWeek: aws.String(m["day_of_week"].(string)), + return &types.WeeklyStartTime{ + DayOfWeek: types.DayOfWeek(m["day_of_week"].(string)), TimeOfDay: aws.String(m["time_of_day"].(string)), TimeZone: aws.String(m["time_zone"].(string)), } } -func flattenWeeklyStartTime(wst *mq.WeeklyStartTime) []interface{} { +func flattenWeeklyStartTime(wst *types.WeeklyStartTime) []interface{} { if wst == nil { return []interface{}{} } m := make(map[string]interface{}) - if wst.DayOfWeek != nil { - m["day_of_week"] = aws.StringValue(wst.DayOfWeek) + if wst.DayOfWeek != "" { + m["day_of_week"] = wst.DayOfWeek } if wst.TimeOfDay != nil { - m["time_of_day"] = aws.StringValue(wst.TimeOfDay) + m["time_of_day"] = aws.ToString(wst.TimeOfDay) } if wst.TimeZone != nil { - m["time_zone"] = aws.StringValue(wst.TimeZone) + m["time_zone"] = aws.ToString(wst.TimeZone) } return []interface{}{m} } -func expandConfigurationId(cfg []interface{}) *mq.ConfigurationId { +func expandConfigurationId(cfg []interface{}) *types.ConfigurationId { if len(cfg) < 1 { return nil } m := cfg[0].(map[string]interface{}) - out := mq.ConfigurationId{ + out := types.ConfigurationId{ Id: aws.String(m["id"].(string)), } if v, ok := m["revision"].(int); ok && v > 0 { - out.Revision = aws.Int64(int64(v)) + out.Revision = aws.Int32(int32(v)) } return &out } -func flattenConfiguration(config *mq.Configurations) []interface{} { +func flattenConfiguration(config *types.Configurations) []interface{} { if config == nil || config.Current == nil { return []interface{}{} } m := map[string]interface{}{ - "id": aws.StringValue(config.Current.Id), - "revision": aws.Int64Value(config.Current.Revision), + "id": aws.ToString(config.Current.Id), + "revision": aws.ToInt32(config.Current.Revision), } return []interface{}{m} } -func flattenBrokerInstances(instances []*mq.BrokerInstance) []interface{} { +func flattenBrokerInstances(instances []types.BrokerInstance) []interface{} { if len(instances) == 0 { return []interface{}{} } @@ -1066,13 +1073,13 @@ func flattenBrokerInstances(instances []*mq.BrokerInstance) []interface{} { for i, instance := range instances { m := make(map[string]interface{}) if instance.ConsoleURL != nil { - m["console_url"] = aws.StringValue(instance.ConsoleURL) + m["console_url"] = aws.ToString(instance.ConsoleURL) } if len(instance.Endpoints) > 0 { - m["endpoints"] = aws.StringValueSlice(instance.Endpoints) + m["endpoints"] = instance.Endpoints } if instance.IpAddress != nil { - m["ip_address"] = aws.StringValue(instance.IpAddress) + m["ip_address"] = aws.ToString(instance.IpAddress) } l[i] = m } @@ -1080,7 +1087,7 @@ func flattenBrokerInstances(instances []*mq.BrokerInstance) []interface{} { return l } -func flattenLogs(logs *mq.LogsSummary) []interface{} { +func flattenLogs(logs *types.LogsSummary) []interface{} { if logs == nil { return []interface{}{} } @@ -1088,24 +1095,24 @@ func flattenLogs(logs *mq.LogsSummary) []interface{} { m := map[string]interface{}{} if logs.General != nil { - m["general"] = aws.BoolValue(logs.General) + m["general"] = aws.ToBool(logs.General) } if logs.Audit != nil { - m["audit"] = strconv.FormatBool(aws.BoolValue(logs.Audit)) + m["audit"] = strconv.FormatBool(aws.ToBool(logs.Audit)) } return []interface{}{m} } -func expandLogs(engineType string, l []interface{}) *mq.Logs { +func expandLogs(engineType string, l []interface{}) *types.Logs { if len(l) == 0 || l[0] == nil { return nil } m := l[0].(map[string]interface{}) - logs := &mq.Logs{} + logs := &types.Logs{} if v, ok := m["general"]; ok { logs.General = aws.Bool(v.(bool)) @@ -1114,7 +1121,7 @@ func expandLogs(engineType string, l []interface{}) *mq.Logs { // When the engine type is "RabbitMQ", the parameter audit cannot be set at all. if v, ok := m["audit"]; ok { if v, null, _ := nullable.Bool(v.(string)).Value(); !null { - if !strings.EqualFold(engineType, mq.EngineTypeRabbitmq) { + if !strings.EqualFold(engineType, string(types.EngineTypeRabbitmq)) { logs.Audit = aws.Bool(v) } } @@ -1123,7 +1130,7 @@ func expandLogs(engineType string, l []interface{}) *mq.Logs { return logs } -func flattenLDAPServerMetadata(apiObject *mq.LdapServerMetadataOutput, password string) []interface{} { +func flattenLDAPServerMetadata(apiObject *types.LdapServerMetadataOutput, password string) []interface{} { if apiObject == nil { return nil } @@ -1131,53 +1138,53 @@ func flattenLDAPServerMetadata(apiObject *mq.LdapServerMetadataOutput, password tfMap := map[string]interface{}{} if v := apiObject.Hosts; v != nil { - tfMap["hosts"] = aws.StringValueSlice(v) + tfMap["hosts"] = v } if v := apiObject.RoleBase; v != nil { - tfMap["role_base"] = aws.StringValue(v) + tfMap["role_base"] = aws.ToString(v) } if v := apiObject.RoleName; v != nil { - tfMap["role_name"] = aws.StringValue(v) + tfMap["role_name"] = aws.ToString(v) } if v := apiObject.RoleSearchMatching; v != nil { - tfMap["role_search_matching"] = aws.StringValue(v) + tfMap["role_search_matching"] = aws.ToString(v) } if v := apiObject.RoleSearchSubtree; v != nil { - tfMap["role_search_subtree"] = aws.BoolValue(v) + tfMap["role_search_subtree"] = aws.ToBool(v) } if password != "" { tfMap["service_account_password"] = password } if v := apiObject.ServiceAccountUsername; v != nil { - tfMap["service_account_username"] = aws.StringValue(v) + tfMap["service_account_username"] = aws.ToString(v) } if v := apiObject.UserBase; v != nil { - tfMap["user_base"] = aws.StringValue(v) + tfMap["user_base"] = aws.ToString(v) } if v := apiObject.UserRoleName; v != nil { - tfMap["user_role_name"] = aws.StringValue(v) + tfMap["user_role_name"] = aws.ToString(v) } if v := apiObject.UserSearchMatching; v != nil { - tfMap["user_search_matching"] = aws.StringValue(v) + tfMap["user_search_matching"] = aws.ToString(v) } if v := apiObject.UserSearchSubtree; v != nil { - tfMap["user_search_subtree"] = aws.BoolValue(v) + tfMap["user_search_subtree"] = aws.ToBool(v) } return []interface{}{tfMap} } -func expandLDAPServerMetadata(tfList []interface{}) *mq.LdapServerMetadataInput { +func expandLDAPServerMetadata(tfList []interface{}) *types.LdapServerMetadataInput { if len(tfList) == 0 || tfList[0] == nil { return nil } - apiObject := &mq.LdapServerMetadataInput{} + apiObject := &types.LdapServerMetadataInput{} tfMap := tfList[0].(map[string]interface{}) if v, ok := tfMap["hosts"]; ok && len(v.([]interface{})) > 0 { - apiObject.Hosts = flex.ExpandStringList(v.([]interface{})) + apiObject.Hosts = flex.ExpandStringValueList(v.([]interface{})) } if v, ok := tfMap["role_base"].(string); ok && v != "" { apiObject.RoleBase = aws.String(v) diff --git a/internal/service/mq/broker_data_source.go b/internal/service/mq/broker_data_source.go index 6a3b7fb553e..ca2b119d7ad 100644 --- a/internal/service/mq/broker_data_source.go +++ b/internal/service/mq/broker_data_source.go @@ -6,18 +6,21 @@ package mq import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/mq" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/mq" + "github.com/aws/aws-sdk-go-v2/service/mq/types" "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" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" + tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/types/nullable" ) -// @SDKDataSource("aws_mq_broker") -func DataSourceBroker() *schema.Resource { +// @SDKDataSource("aws_mq_broker", name="Broker") +func dataSourceBroker() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: dataSourceBrokerRead, @@ -255,48 +258,28 @@ func DataSourceBroker() *schema.Resource { func dataSourceBrokerRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MQConn(ctx) + conn := meta.(*conns.AWSClient).MQClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig input := &mq.ListBrokersInput{} - var brokers []*mq.BrokerSummary - - err := conn.ListBrokersPagesWithContext(ctx, input, func(page *mq.ListBrokersResponse, lastPage bool) bool { - if page == nil { - return !lastPage + broker, err := findBroker(ctx, conn, input, func(b *types.BrokerSummary) bool { + if v, ok := d.GetOk("broker_id"); ok && v.(string) != aws.ToString(b.BrokerId) { + return false } - for _, broker := range page.BrokerSummaries { - if broker == nil { - continue - } - - if v, ok := d.GetOk("broker_id"); ok && v.(string) != aws.StringValue(broker.BrokerId) { - continue - } - - if v, ok := d.GetOk("broker_name"); ok && v.(string) != aws.StringValue(broker.BrokerName) { - continue - } - - brokers = append(brokers, broker) + if v, ok := d.GetOk("broker_name"); ok && v.(string) != aws.ToString(b.BrokerName) { + return false } - return !lastPage + return true }) if err != nil { - return sdkdiag.AppendErrorf(diags, "reading MQ Brokers: %s", err) + return sdkdiag.AppendFromErr(diags, tfresource.SingularDataSourceFindError("MQ Broker", err)) } - if n := len(brokers); n == 0 { - return sdkdiag.AppendErrorf(diags, "no MQ Brokers matched") - } else if n > 1 { - return sdkdiag.AppendErrorf(diags, "%d MQ Brokers matched; use additional constraints to reduce matches to a single Broker", n) - } - - brokerID := aws.StringValue(brokers[0].BrokerId) - output, err := FindBrokerByID(ctx, conn, brokerID) + brokerID := aws.ToString(broker.BrokerId) + output, err := findBrokerByID(ctx, conn, brokerID) if err != nil { return sdkdiag.AppendErrorf(diags, "reading MQ Broker (%s): %s", brokerID, err) @@ -314,9 +297,9 @@ func dataSourceBrokerRead(ctx context.Context, d *schema.ResourceData, meta inte d.Set("host_instance_type", output.HostInstanceType) d.Set("instances", flattenBrokerInstances(output.BrokerInstances)) d.Set("publicly_accessible", output.PubliclyAccessible) - d.Set("security_groups", aws.StringValueSlice(output.SecurityGroups)) + d.Set("security_groups", output.SecurityGroups) d.Set("storage_type", output.StorageType) - d.Set("subnet_ids", aws.StringValueSlice(output.SubnetIds)) + d.Set("subnet_ids", output.SubnetIds) if err := d.Set("configuration", flattenConfiguration(output.Configurations)); err != nil { return sdkdiag.AppendErrorf(diags, "setting configuration: %s", err) @@ -359,3 +342,34 @@ func dataSourceBrokerRead(ctx context.Context, d *schema.ResourceData, meta inte return diags } + +func findBroker(ctx context.Context, conn *mq.Client, input *mq.ListBrokersInput, filter tfslices.Predicate[*types.BrokerSummary]) (*types.BrokerSummary, error) { + output, err := findBrokers(ctx, conn, input, filter) + + if err != nil { + return nil, err + } + + return tfresource.AssertSingleValueResult(output) +} + +func findBrokers(ctx context.Context, conn *mq.Client, input *mq.ListBrokersInput, filter tfslices.Predicate[*types.BrokerSummary]) ([]types.BrokerSummary, error) { + var output []types.BrokerSummary + + pages := mq.NewListBrokersPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if err != nil { + return nil, err + } + + for _, v := range page.BrokerSummaries { + if filter(&v) { + output = append(output, v) + } + } + } + + return output, nil +} diff --git a/internal/service/mq/broker_data_source_test.go b/internal/service/mq/broker_data_source_test.go index 15ff9ccdbb1..2a773379fc0 100644 --- a/internal/service/mq/broker_data_source_test.go +++ b/internal/service/mq/broker_data_source_test.go @@ -7,10 +7,10 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/mq" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccMQBrokerDataSource_basic(t *testing.T) { @@ -26,8 +26,8 @@ func TestAccMQBrokerDataSource_basic(t *testing.T) { dataSourceByNameName := "data.aws_mq_broker.by_name" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, mq.EndpointsID) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.MQEndpointID) }, + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/service/mq/broker_engine_types_data_source.go b/internal/service/mq/broker_engine_types_data_source.go index 912dafed251..a44bc39e8a6 100644 --- a/internal/service/mq/broker_engine_types_data_source.go +++ b/internal/service/mq/broker_engine_types_data_source.go @@ -18,7 +18,7 @@ import ( ) // @SDKDataSource("aws_mq_broker_engine_types", name="Broker Engine Types") -func DataSourceBrokerEngineTypes() *schema.Resource { +func dataSourceBrokerEngineTypes() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: dataSourceBrokerEngineTypesRead, diff --git a/internal/service/mq/broker_engine_types_data_source_test.go b/internal/service/mq/broker_engine_types_data_source_test.go index e703975aac1..ff2f75c6e1e 100644 --- a/internal/service/mq/broker_engine_types_data_source_test.go +++ b/internal/service/mq/broker_engine_types_data_source_test.go @@ -7,9 +7,9 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/mq" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccMQBrokerEngineTypesDataSource_basic(t *testing.T) { @@ -19,10 +19,10 @@ func TestAccMQBrokerEngineTypesDataSource_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/service/mq/broker_instance_type_offerings_data_source.go b/internal/service/mq/broker_instance_type_offerings_data_source.go index dbb475fa08d..17a588f0a10 100644 --- a/internal/service/mq/broker_instance_type_offerings_data_source.go +++ b/internal/service/mq/broker_instance_type_offerings_data_source.go @@ -6,18 +6,18 @@ package mq import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/mq" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/mq" + "github.com/aws/aws-sdk-go-v2/service/mq/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/sdkdiag" - "github.com/hashicorp/terraform-provider-aws/internal/flex" ) -// @SDKDataSource("aws_mq_broker_instance_type_offerings") -func DataSourceBrokerInstanceTypeOfferings() *schema.Resource { +// @SDKDataSource("aws_mq_broker_instance_type_offerings", name="Broker Instance Type Offerings") +func dataSourceBrokerInstanceTypeOfferings() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: dataSourceBrokerInstanceTypeOfferingsRead, @@ -65,18 +65,18 @@ func DataSourceBrokerInstanceTypeOfferings() *schema.Resource { }, }, "engine_type": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(mq.EngineType_Values(), false), + Type: schema.TypeString, + Optional: true, + ValidateDiagFunc: enum.Validate[types.EngineType](), }, "host_instance_type": { Type: schema.TypeString, Optional: true, }, "storage_type": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(mq.BrokerStorageType_Values(), false), + Type: schema.TypeString, + Optional: true, + ValidateDiagFunc: enum.Validate[types.BrokerStorageType](), }, }, } @@ -85,7 +85,7 @@ func DataSourceBrokerInstanceTypeOfferings() *schema.Resource { func dataSourceBrokerInstanceTypeOfferingsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MQConn(ctx) + conn := meta.(*conns.AWSClient).MQClient(ctx) input := &mq.DescribeBrokerInstanceOptionsInput{} @@ -101,7 +101,7 @@ func dataSourceBrokerInstanceTypeOfferingsRead(ctx context.Context, d *schema.Re input.StorageType = aws.String(v.(string)) } - var output []*mq.BrokerInstanceOption + var output []types.BrokerInstanceOption err := describeBrokerInstanceOptionsPages(ctx, conn, input, func(page *mq.DescribeBrokerInstanceOptionsOutput, lastPage bool) bool { if page == nil { @@ -126,7 +126,7 @@ func dataSourceBrokerInstanceTypeOfferingsRead(ctx context.Context, d *schema.Re return diags } -func flattenBrokerInstanceOptions(bios []*mq.BrokerInstanceOption) []interface{} { +func flattenBrokerInstanceOptions(bios []types.BrokerInstanceOption) []interface{} { if len(bios) == 0 { return nil } @@ -134,43 +134,28 @@ func flattenBrokerInstanceOptions(bios []*mq.BrokerInstanceOption) []interface{} var tfList []interface{} for _, bio := range bios { - if bio == nil { - continue - } - - tfMap := map[string]interface{}{} - - if bio.EngineType != nil { - tfMap["engine_type"] = aws.StringValue(bio.EngineType) - } - - if bio.StorageType != nil { - tfMap["storage_type"] = aws.StringValue(bio.StorageType) + tfMap := map[string]interface{}{ + "engine_type": bio.EngineType, + "storage_type": bio.StorageType, + "supported_deployment_modes": bio.SupportedDeploymentModes, + "supported_engine_versions": bio.SupportedEngineVersions, } if bio.HostInstanceType != nil { - tfMap["host_instance_type"] = aws.StringValue(bio.HostInstanceType) + tfMap["host_instance_type"] = aws.ToString(bio.HostInstanceType) } if bio.AvailabilityZones != nil { tfMap["availability_zones"] = flattenAvailabilityZones(bio.AvailabilityZones) } - if bio.SupportedDeploymentModes != nil { - tfMap["supported_deployment_modes"] = flex.FlattenStringSet(bio.SupportedDeploymentModes) - } - - if bio.SupportedEngineVersions != nil { - tfMap["supported_engine_versions"] = flex.FlattenStringList(bio.SupportedEngineVersions) - } - tfList = append(tfList, tfMap) } return tfList } -func flattenAvailabilityZones(azs []*mq.AvailabilityZone) []interface{} { +func flattenAvailabilityZones(azs []types.AvailabilityZone) []interface{} { if len(azs) == 0 { return nil } @@ -178,14 +163,10 @@ func flattenAvailabilityZones(azs []*mq.AvailabilityZone) []interface{} { var tfList []interface{} for _, az := range azs { - if az == nil { - continue - } - tfMap := map[string]interface{}{} if az.Name != nil { - tfMap["name"] = aws.StringValue(az.Name) + tfMap["name"] = aws.ToString(az.Name) } tfList = append(tfList, tfMap) diff --git a/internal/service/mq/broker_instance_type_offerings_data_source_test.go b/internal/service/mq/broker_instance_type_offerings_data_source_test.go index a4c806b3ff8..827099b751b 100644 --- a/internal/service/mq/broker_instance_type_offerings_data_source_test.go +++ b/internal/service/mq/broker_instance_type_offerings_data_source_test.go @@ -6,16 +6,16 @@ package mq_test import ( "testing" - "github.com/aws/aws-sdk-go/service/mq" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-aws/internal/acctest" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccMQBrokerInstanceTypeOfferingsDataSource_basic(t *testing.T) { ctx := acctest.Context(t) resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, mq.EndpointsID) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, names.MQEndpointID) }, + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ { diff --git a/internal/service/mq/broker_test.go b/internal/service/mq/broker_test.go index 8e9d7fc7fd6..00d10c9b879 100644 --- a/internal/service/mq/broker_test.go +++ b/internal/service/mq/broker_test.go @@ -10,8 +10,10 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/mq" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/mq" + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -20,6 +22,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/conns" tfmq "github.com/hashicorp/terraform-provider-aws/internal/service/mq" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestValidateBrokerName(t *testing.T) { @@ -112,9 +115,9 @@ func TestDiffUsers(t *testing.T) { OldUsers []interface{} NewUsers []interface{} - Creations []*mq.CreateUserRequest + Creations []*mq.CreateUserInput Deletions []*mq.DeleteUserInput - Updates []*mq.UpdateUserRequest + Updates []*mq.UpdateUserInput }{ { OldUsers: []interface{}{}, @@ -127,18 +130,18 @@ func TestDiffUsers(t *testing.T) { "replication_user": false, }, }, - Creations: []*mq.CreateUserRequest{ + Creations: []*mq.CreateUserInput{ { BrokerId: aws.String("test"), ConsoleAccess: aws.Bool(false), Username: aws.String("second"), Password: aws.String("TestTest2222"), - Groups: aws.StringSlice([]string{"admin"}), + Groups: []string{"admin"}, ReplicationUser: aws.Bool(false), }, }, - Deletions: []*mq.DeleteUserInput{}, - Updates: []*mq.UpdateUserRequest{}, + Deletions: nil, + Updates: nil, }, { OldUsers: []interface{}{ @@ -157,7 +160,7 @@ func TestDiffUsers(t *testing.T) { "replication_user": false, }, }, - Creations: []*mq.CreateUserRequest{ + Creations: []*mq.CreateUserInput{ { BrokerId: aws.String("test"), ConsoleAccess: aws.Bool(false), @@ -169,7 +172,7 @@ func TestDiffUsers(t *testing.T) { Deletions: []*mq.DeleteUserInput{ {BrokerId: aws.String("test"), Username: aws.String("first")}, }, - Updates: []*mq.UpdateUserRequest{}, + Updates: nil, }, { OldUsers: []interface{}{ @@ -195,17 +198,17 @@ func TestDiffUsers(t *testing.T) { "replication_user": false, }, }, - Creations: []*mq.CreateUserRequest{}, + Creations: nil, Deletions: []*mq.DeleteUserInput{ {BrokerId: aws.String("test"), Username: aws.String("first")}, }, - Updates: []*mq.UpdateUserRequest{ + Updates: []*mq.UpdateUserInput{ { BrokerId: aws.String("test"), ConsoleAccess: aws.Bool(false), Username: aws.String("second"), Password: aws.String("TestTest2222"), - Groups: aws.StringSlice([]string{"admin"}), + Groups: []string{"admin"}, ReplicationUser: aws.Bool(false), }, }, @@ -218,22 +221,19 @@ func TestDiffUsers(t *testing.T) { t.Fatal(err) } - expectedCreations := fmt.Sprintf("%s", tc.Creations) - creationsString := fmt.Sprintf("%s", creations) - if creationsString != expectedCreations { - t.Fatalf("Expected creations: %s\nGiven: %s", expectedCreations, creationsString) + var got, want any = creations, tc.Creations + if diff := cmp.Diff(got, want, cmpopts.IgnoreUnexported(mq.CreateUserInput{})); diff != "" { + t.Fatalf("unexpected CreateUserInput diff (+wanted, -got): %s", diff) } - expectedDeletions := fmt.Sprintf("%s", tc.Deletions) - deletionsString := fmt.Sprintf("%s", deletions) - if deletionsString != expectedDeletions { - t.Fatalf("Expected deletions: %s\nGiven: %s", expectedDeletions, deletionsString) + got, want = deletions, tc.Deletions + if diff := cmp.Diff(got, want, cmpopts.IgnoreUnexported(mq.DeleteUserInput{})); diff != "" { + t.Fatalf("unexpected DeleteUserInput diff (+wanted, -got): %s", diff) } - expectedUpdates := fmt.Sprintf("%s", tc.Updates) - updatesString := fmt.Sprintf("%s", updates) - if updatesString != expectedUpdates { - t.Fatalf("Expected updates: %s\nGiven: %s", expectedUpdates, updatesString) + got, want = updates, tc.Updates + if diff := cmp.Diff(got, want, cmpopts.IgnoreUnexported(mq.UpdateUserInput{})); diff != "" { + t.Fatalf("unexpected UpdateUserInput diff (+wanted, -got): %s", diff) } } } @@ -250,17 +250,17 @@ func TestAccMQBroker_basic(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -329,17 +329,17 @@ func TestAccMQBroker_disappears(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -361,17 +361,17 @@ func TestAccMQBroker_tags(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -416,17 +416,17 @@ func TestAccMQBroker_throughputOptimized(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -487,7 +487,7 @@ func TestAccMQBroker_AllFields_defaultVPC(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) rNameUpdated := sdkacctest.RandomWithPrefix("tf-acc-test-updated") resourceName := "aws_mq_broker.test" @@ -507,10 +507,10 @@ func TestAccMQBroker_AllFields_defaultVPC(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -616,7 +616,7 @@ func TestAccMQBroker_AllFields_customVPC(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) rNameUpdated := sdkacctest.RandomWithPrefix("tf-acc-test-updated") resourceName := "aws_mq_broker.test" @@ -636,10 +636,10 @@ func TestAccMQBroker_AllFields_customVPC(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -749,7 +749,7 @@ func TestAccMQBroker_EncryptionOptions_kmsKeyID(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) kmsKeyResourceName := "aws_kms_key.test" resourceName := "aws_mq_broker.test" @@ -757,10 +757,10 @@ func TestAccMQBroker_EncryptionOptions_kmsKeyID(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -789,17 +789,17 @@ func TestAccMQBroker_EncryptionOptions_managedKeyDisabled(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -827,17 +827,17 @@ func TestAccMQBroker_EncryptionOptions_managedKeyEnabled(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -865,17 +865,17 @@ func TestAccMQBroker_Update_users(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -943,17 +943,17 @@ func TestAccMQBroker_Update_securityGroup(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -1001,17 +1001,17 @@ func TestAccMQBroker_Update_engineVersion(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -1045,17 +1045,17 @@ func TestAccMQBroker_Update_hostInstanceType(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker1, broker2 mq.DescribeBrokerResponse + var broker1, broker2 mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -1084,17 +1084,17 @@ func TestAccMQBroker_RabbitMQ_basic(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -1130,17 +1130,17 @@ func TestAccMQBroker_RabbitMQ_config(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -1178,17 +1178,17 @@ func TestAccMQBroker_RabbitMQ_logs(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -1224,17 +1224,17 @@ func TestAccMQBroker_RabbitMQ_validationAuditLog(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -1263,17 +1263,17 @@ func TestAccMQBroker_RabbitMQ_cluster(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -1330,17 +1330,17 @@ func TestAccMQBroker_ldap(t *testing.T) { t.Skip("skipping long-running test in short mode") } - var broker mq.DescribeBrokerResponse + var broker mq.DescribeBrokerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_mq_broker.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckBrokerDestroy(ctx), Steps: []resource.TestStep{ @@ -1371,7 +1371,7 @@ func TestAccMQBroker_ldap(t *testing.T) { func testAccCheckBrokerDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).MQConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MQClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_mq_broker" { @@ -1395,18 +1395,14 @@ func testAccCheckBrokerDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccCheckBrokerExists(ctx context.Context, n string, v *mq.DescribeBrokerResponse) resource.TestCheckFunc { +func testAccCheckBrokerExists(ctx context.Context, n string, v *mq.DescribeBrokerOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No MQ Broker ID is set") - } - - conn := acctest.Provider.Meta().(*conns.AWSClient).MQConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MQClient(ctx) output, err := tfmq.FindBrokerByID(ctx, conn, rs.Primary.ID) @@ -1421,11 +1417,11 @@ func testAccCheckBrokerExists(ctx context.Context, n string, v *mq.DescribeBroke } func testAccPreCheck(ctx context.Context, t *testing.T) { - conn := acctest.Provider.Meta().(*conns.AWSClient).MQConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MQClient(ctx) input := &mq.ListBrokersInput{} - _, err := conn.ListBrokersWithContext(ctx, input) + _, err := conn.ListBrokers(ctx, input) if acctest.PreCheckSkipError(err) { t.Skipf("skipping acceptance testing: %s", err) @@ -1436,9 +1432,9 @@ func testAccPreCheck(ctx context.Context, t *testing.T) { } } -func testAccCheckBrokerNotRecreated(before, after *mq.DescribeBrokerResponse) resource.TestCheckFunc { +func testAccCheckBrokerNotRecreated(before, after *mq.DescribeBrokerOutput) resource.TestCheckFunc { return func(s *terraform.State) error { - if before, after := aws.StringValue(before.BrokerId), aws.StringValue(after.BrokerId); before != after { + if before, after := aws.ToString(before.BrokerId), aws.ToString(after.BrokerId); before != after { return fmt.Errorf("MQ Broker (%s/%s) recreated", before, after) } diff --git a/internal/service/mq/configuration.go b/internal/service/mq/configuration.go index 4fa59f1e4d3..8a390a946f1 100644 --- a/internal/service/mq/configuration.go +++ b/internal/service/mq/configuration.go @@ -9,15 +9,16 @@ import ( "log" "strconv" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/mq" - "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/mq" + "github.com/aws/aws-sdk-go-v2/service/mq/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "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" @@ -27,7 +28,7 @@ import ( // @SDKResource("aws_mq_configuration", name="Configuration") // @Tags(identifierAttribute="arn") -func ResourceConfiguration() *schema.Resource { +func resourceConfiguration() *schema.Resource { return &schema.Resource{ CreateWithoutTimeout: resourceConfigurationCreate, ReadWithoutTimeout: resourceConfigurationRead, @@ -62,10 +63,10 @@ func ResourceConfiguration() *schema.Resource { Computed: true, }, "authentication_strategy": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(mq.AuthenticationStrategy_Values(), true), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.ValidateIgnoreCase[types.AuthenticationStrategy](), }, "data": { Type: schema.TypeString, @@ -78,10 +79,10 @@ func ResourceConfiguration() *schema.Resource { Optional: true, }, "engine_type": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice(mq.EngineType_Values(), true), + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateDiagFunc: enum.ValidateIgnoreCase[types.EngineType](), }, "engine_version": { Type: schema.TypeString, @@ -106,30 +107,30 @@ func ResourceConfiguration() *schema.Resource { func resourceConfigurationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MQConn(ctx) + conn := meta.(*conns.AWSClient).MQClient(ctx) name := d.Get("name").(string) - input := &mq.CreateConfigurationRequest{ - EngineType: aws.String(d.Get("engine_type").(string)), + input := &mq.CreateConfigurationInput{ + EngineType: types.EngineType(d.Get("engine_type").(string)), EngineVersion: aws.String(d.Get("engine_version").(string)), Name: aws.String(name), Tags: getTagsIn(ctx), } if v, ok := d.GetOk("authentication_strategy"); ok { - input.AuthenticationStrategy = aws.String(v.(string)) + input.AuthenticationStrategy = types.AuthenticationStrategy(v.(string)) } - output, err := conn.CreateConfigurationWithContext(ctx, input) + output, err := conn.CreateConfiguration(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating MQ Configuration (%s): %s", name, err) } - d.SetId(aws.StringValue(output.Id)) + d.SetId(aws.ToString(output.Id)) if v, ok := d.GetOk("data"); ok { - input := &mq.UpdateConfigurationRequest{ + input := &mq.UpdateConfigurationInput{ ConfigurationId: aws.String(d.Id()), Data: aws.String(base64.StdEncoding.EncodeToString([]byte(v.(string)))), } @@ -138,7 +139,7 @@ func resourceConfigurationCreate(ctx context.Context, d *schema.ResourceData, me input.Description = aws.String(v.(string)) } - _, err := conn.UpdateConfigurationWithContext(ctx, input) + _, err := conn.UpdateConfiguration(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating MQ Configuration (%s): %s", d.Id(), err) @@ -151,9 +152,9 @@ func resourceConfigurationCreate(ctx context.Context, d *schema.ResourceData, me func resourceConfigurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MQConn(ctx) + conn := meta.(*conns.AWSClient).MQClient(ctx) - configuration, err := FindConfigurationByID(ctx, conn, d.Id()) + configuration, err := findConfigurationByID(ctx, conn, d.Id()) if !d.IsNewResource() && tfresource.NotFound(err) { log.Printf("[WARN] MQ Configuration (%s) not found, removing from state", d.Id()) @@ -173,8 +174,8 @@ func resourceConfigurationRead(ctx context.Context, d *schema.ResourceData, meta d.Set("latest_revision", configuration.LatestRevision.Revision) d.Set("name", configuration.Name) - revision := strconv.FormatInt(aws.Int64Value(configuration.LatestRevision.Revision), 10) - configurationRevision, err := conn.DescribeConfigurationRevisionWithContext(ctx, &mq.DescribeConfigurationRevisionInput{ + revision := strconv.FormatInt(int64(aws.ToInt32(configuration.LatestRevision.Revision)), 10) + configurationRevision, err := conn.DescribeConfigurationRevision(ctx, &mq.DescribeConfigurationRevisionInput{ ConfigurationId: aws.String(d.Id()), ConfigurationRevision: aws.String(revision), }) @@ -183,7 +184,7 @@ func resourceConfigurationRead(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "reading MQ Configuration (%s) revision (%s): %s", d.Id(), revision, err) } - data, err := base64.StdEncoding.DecodeString(aws.StringValue(configurationRevision.Data)) + data, err := base64.StdEncoding.DecodeString(aws.ToString(configurationRevision.Data)) if err != nil { return sdkdiag.AppendErrorf(diags, "base64 decoding: %s", err) @@ -199,10 +200,10 @@ func resourceConfigurationRead(ctx context.Context, d *schema.ResourceData, meta func resourceConfigurationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MQConn(ctx) + conn := meta.(*conns.AWSClient).MQClient(ctx) if d.HasChanges("data", "description") { - input := &mq.UpdateConfigurationRequest{ + input := &mq.UpdateConfigurationInput{ ConfigurationId: aws.String(d.Id()), Data: aws.String(base64.StdEncoding.EncodeToString([]byte(d.Get("data").(string)))), } @@ -211,7 +212,7 @@ func resourceConfigurationUpdate(ctx context.Context, d *schema.ResourceData, me input.Description = aws.String(v.(string)) } - _, err := conn.UpdateConfigurationWithContext(ctx, input) + _, err := conn.UpdateConfiguration(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating MQ Configuration (%s): %s", d.Id(), err) @@ -221,14 +222,14 @@ func resourceConfigurationUpdate(ctx context.Context, d *schema.ResourceData, me return append(diags, resourceConfigurationRead(ctx, d, meta)...) } -func FindConfigurationByID(ctx context.Context, conn *mq.MQ, id string) (*mq.DescribeConfigurationOutput, error) { +func findConfigurationByID(ctx context.Context, conn *mq.Client, id string) (*mq.DescribeConfigurationOutput, error) { input := &mq.DescribeConfigurationInput{ ConfigurationId: aws.String(id), } - output, err := conn.DescribeConfigurationWithContext(ctx, input) + output, err := conn.DescribeConfiguration(ctx, input) - if tfawserr.ErrCodeEquals(err, mq.ErrCodeNotFoundException) { + if errs.IsA[*types.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/mq/configuration_test.go b/internal/service/mq/configuration_test.go index 04581a78e66..e68fedf6ac3 100644 --- a/internal/service/mq/configuration_test.go +++ b/internal/service/mq/configuration_test.go @@ -9,13 +9,13 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/mq" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" tfmq "github.com/hashicorp/terraform-provider-aws/internal/service/mq" + "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccMQConfiguration_basic(t *testing.T) { @@ -26,10 +26,10 @@ func TestAccMQConfiguration_basic(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: acctest.CheckDestroyNoop, Steps: []resource.TestStep{ @@ -75,10 +75,10 @@ func TestAccMQConfiguration_withActiveMQData(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: acctest.CheckDestroyNoop, Steps: []resource.TestStep{ @@ -111,10 +111,10 @@ func TestAccMQConfiguration_withActiveMQLdapData(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: acctest.CheckDestroyNoop, Steps: []resource.TestStep{ @@ -148,10 +148,10 @@ func TestAccMQConfiguration_withRabbitMQData(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: acctest.CheckDestroyNoop, Steps: []resource.TestStep{ @@ -185,10 +185,10 @@ func TestAccMQConfiguration_tags(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) - acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + acctest.PreCheckPartitionHasService(t, names.MQEndpointID) testAccPreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ErrorCheck: acctest.ErrorCheck(t, names.MQEndpointID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: acctest.CheckDestroyNoop, Steps: []resource.TestStep{ @@ -233,11 +233,7 @@ func testAccCheckConfigurationExists(ctx context.Context, n string) resource.Tes return fmt.Errorf("Not found: %s", n) } - if rs.Primary.ID == "" { - return fmt.Errorf("No MQ Configuration ID is set") - } - - conn := acctest.Provider.Meta().(*conns.AWSClient).MQConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).MQClient(ctx) _, err := tfmq.FindConfigurationByID(ctx, conn, rs.Primary.ID) diff --git a/internal/service/mq/exports_test.go b/internal/service/mq/exports_test.go new file mode 100644 index 00000000000..515e63f19c5 --- /dev/null +++ b/internal/service/mq/exports_test.go @@ -0,0 +1,13 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package mq + +// Exports for use in tests only. +var ( + ResourceBroker = resourceBroker + ResourceConfiguration = resourceConfiguration + + FindBrokerByID = findBrokerByID + FindConfigurationByID = findConfigurationByID +) diff --git a/internal/service/mq/generate.go b/internal/service/mq/generate.go index f541c1e7d3f..18e7e2fdf8d 100644 --- a/internal/service/mq/generate.go +++ b/internal/service/mq/generate.go @@ -1,8 +1,7 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeBrokerInstanceOptions -//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=ListTags -ServiceTagsMap -TagOp=CreateTags -UntagOp=DeleteTags -UpdateTags +//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ListTags -ListTagsOp=ListTags -ServiceTagsMap -TagOp=CreateTags -UntagOp=DeleteTags -UpdateTags -KVTValues -SkipTypesImp //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/mq/list_pages.go b/internal/service/mq/list_pages.go new file mode 100644 index 00000000000..f9c8b6d8ac1 --- /dev/null +++ b/internal/service/mq/list_pages.go @@ -0,0 +1,29 @@ +// Code generated by "internal/generate/listpages/main.go -ListOps=DescribeBrokerInstanceOptions"; DO NOT EDIT. + +package mq + +import ( + "context" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/mq" +) + +// Custom MQ service lister functions using the same format as generated code. + +func describeBrokerInstanceOptionsPages(ctx context.Context, conn *mq.Client, input *mq.DescribeBrokerInstanceOptionsInput, fn func(*mq.DescribeBrokerInstanceOptionsOutput, bool) bool) error { + for { + output, err := conn.DescribeBrokerInstanceOptions(ctx, input) + if err != nil { + return err + } + + lastPage := aws.ToString(output.NextToken) == "" + if !fn(output, lastPage) || lastPage { + break + } + + input.NextToken = output.NextToken + } + return nil +} diff --git a/internal/service/mq/list_pages_gen.go b/internal/service/mq/list_pages_gen.go deleted file mode 100644 index 2b8481c05b0..00000000000 --- a/internal/service/mq/list_pages_gen.go +++ /dev/null @@ -1,28 +0,0 @@ -// Code generated by "internal/generate/listpages/main.go -ListOps=DescribeBrokerInstanceOptions"; DO NOT EDIT. - -package mq - -import ( - "context" - - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/mq" - "github.com/aws/aws-sdk-go/service/mq/mqiface" -) - -func describeBrokerInstanceOptionsPages(ctx context.Context, conn mqiface.MQAPI, input *mq.DescribeBrokerInstanceOptionsInput, fn func(*mq.DescribeBrokerInstanceOptionsOutput, bool) bool) error { - for { - output, err := conn.DescribeBrokerInstanceOptionsWithContext(ctx, input) - if err != nil { - return err - } - - lastPage := aws.StringValue(output.NextToken) == "" - if !fn(output, lastPage) || lastPage { - break - } - - input.NextToken = output.NextToken - } - return nil -} diff --git a/internal/service/mq/service_package_gen.go b/internal/service/mq/service_package_gen.go index aa815cc431d..0295385cf28 100644 --- a/internal/service/mq/service_package_gen.go +++ b/internal/service/mq/service_package_gen.go @@ -7,9 +7,6 @@ import ( aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" mq_sdkv2 "github.com/aws/aws-sdk-go-v2/service/mq" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - mq_sdkv1 "github.com/aws/aws-sdk-go/service/mq" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -28,17 +25,19 @@ func (p *servicePackage) FrameworkResources(ctx context.Context) []*types.Servic func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePackageSDKDataSource { return []*types.ServicePackageSDKDataSource{ { - Factory: DataSourceBroker, + Factory: dataSourceBroker, TypeName: "aws_mq_broker", + Name: "Broker", }, { - Factory: DataSourceBrokerEngineTypes, + Factory: dataSourceBrokerEngineTypes, TypeName: "aws_mq_broker_engine_types", Name: "Broker Engine Types", }, { - Factory: DataSourceBrokerInstanceTypeOfferings, + Factory: dataSourceBrokerInstanceTypeOfferings, TypeName: "aws_mq_broker_instance_type_offerings", + Name: "Broker Instance Type Offerings", }, } } @@ -46,7 +45,7 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePackageSDKResource { return []*types.ServicePackageSDKResource{ { - Factory: ResourceBroker, + Factory: resourceBroker, TypeName: "aws_mq_broker", Name: "Broker", Tags: &types.ServicePackageResourceTags{ @@ -54,7 +53,7 @@ func (p *servicePackage) SDKResources(ctx context.Context) []*types.ServicePacka }, }, { - Factory: ResourceConfiguration, + Factory: resourceConfiguration, TypeName: "aws_mq_configuration", Name: "Configuration", Tags: &types.ServicePackageResourceTags{ @@ -68,13 +67,6 @@ func (p *servicePackage) ServicePackageName() string { return names.MQ } -// 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) (*mq_sdkv1.MQ, error) { - sess := config["session"].(*session_sdkv1.Session) - - return mq_sdkv1.New(sess.Copy(&aws_sdkv1.Config{Endpoint: aws_sdkv1.String(config["endpoint"].(string))})), nil -} - // 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) (*mq_sdkv2.Client, error) { cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) diff --git a/internal/service/mq/sweep.go b/internal/service/mq/sweep.go index 58ec60e2682..630ebc254f4 100644 --- a/internal/service/mq/sweep.go +++ b/internal/service/mq/sweep.go @@ -7,11 +7,11 @@ import ( "fmt" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/mq" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/mq" "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() { @@ -27,33 +27,30 @@ func sweepBrokers(region string) error { if err != nil { return fmt.Errorf("error getting client: %s", err) } - input := &mq.ListBrokersInput{MaxResults: aws.Int64(100)} - conn := client.MQConn(ctx) + input := &mq.ListBrokersInput{MaxResults: aws.Int32(100)} + conn := client.MQClient(ctx) sweepResources := make([]sweep.Sweepable, 0) - err = conn.ListBrokersPagesWithContext(ctx, input, func(page *mq.ListBrokersResponse, lastPage bool) bool { - if page == nil { - return !lastPage + pages := mq.NewListBrokersPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + + if awsv2.SkipSweepError(err) { + log.Printf("[WARN] Skipping MQ Broker sweep for %s: %s", region, err) + return nil + } + + if err != nil { + return fmt.Errorf("error listing MQ Brokers (%s): %w", region, err) } for _, v := range page.BrokerSummaries { - r := ResourceBroker() + r := resourceBroker() d := r.Data(nil) - d.SetId(aws.StringValue(v.BrokerId)) + d.SetId(aws.ToString(v.BrokerId)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping MQ Broker sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("error listing MQ Brokers (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) diff --git a/internal/service/mq/tags_gen.go b/internal/service/mq/tags_gen.go index d890a723f62..a7252d4e23c 100644 --- a/internal/service/mq/tags_gen.go +++ b/internal/service/mq/tags_gen.go @@ -5,9 +5,8 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/mq" - "github.com/aws/aws-sdk-go/service/mq/mqiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/mq" "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 mq 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 mqiface.MQAPI, identifier string) (tftags.KeyValueTags, error) { +func listTags(ctx context.Context, conn *mq.Client, identifier string, optFns ...func(*mq.Options)) (tftags.KeyValueTags, error) { input := &mq.ListTagsInput{ ResourceArn: aws.String(identifier), } - output, err := conn.ListTagsWithContext(ctx, input) + output, err := conn.ListTags(ctx, input, optFns...) if err != nil { return tftags.New(ctx, nil), err @@ -36,7 +35,7 @@ func listTags(ctx context.Context, conn mqiface.MQAPI, identifier string) (tftag // ListTags lists mq 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).MQConn(ctx), identifier) + tags, err := listTags(ctx, meta.(*conns.AWSClient).MQClient(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 mq 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 mq 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 mq 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 mq 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 mq 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 mqiface.MQAPI, identifier string, oldTagsMap, newTagsMap any) error { +func updateTags(ctx context.Context, conn *mq.Client, identifier string, oldTagsMap, newTagsMap any, optFns ...func(*mq.Options)) error { oldTags := tftags.New(ctx, oldTagsMap) newTags := tftags.New(ctx, newTagsMap) @@ -94,10 +93,10 @@ func updateTags(ctx context.Context, conn mqiface.MQAPI, identifier string, oldT if len(removedTags) > 0 { input := &mq.DeleteTagsInput{ ResourceArn: aws.String(identifier), - TagKeys: aws.StringSlice(removedTags.Keys()), + TagKeys: removedTags.Keys(), } - _, err := conn.DeleteTagsWithContext(ctx, input) + _, err := conn.DeleteTags(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 mqiface.MQAPI, identifier string, oldT Tags: Tags(updatedTags), } - _, err := conn.CreateTagsWithContext(ctx, input) + _, err := conn.CreateTags(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 mqiface.MQAPI, identifier string, oldT // UpdateTags updates mq 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).MQConn(ctx), identifier, oldTags, newTags) + return updateTags(ctx, meta.(*conns.AWSClient).MQClient(ctx), identifier, oldTags, newTags) } diff --git a/names/data/names_data.csv b/names/data/names_data.csv index d50bcc91a0f..45c15404d66 100644 --- a/names/data/names_data.csv +++ b/names/data/names_data.csv @@ -251,7 +251,7 @@ mobile,mobile,mobile,mobile,,mobile,,,Mobile,Mobile,,1,,,aws_mobile_,,mobile_,Mo ,,,,,,,,,,,,,,,,,Mobile SDK for Unity,AWS,x,,,,,,No SDK support ,,,,,,,,,,,,,,,,,Mobile SDK for Xamarin,AWS,x,,,,,,No SDK support ,,,,,,,,,,,,,,,,,Monitron,Amazon,x,,,,,,No SDK support -mq,mq,mq,mq,,mq,,,MQ,MQ,,1,2,,aws_mq_,,mq_,MQ,Amazon,,,,,,, +mq,mq,mq,mq,,mq,,,MQ,MQ,,,2,,aws_mq_,,mq_,MQ,Amazon,,,,,,, mturk,mturk,mturk,mturk,,mturk,,,MTurk,MTurk,,1,,,aws_mturk_,,mturk_,MTurk (Mechanical Turk),Amazon,,x,,,,, mwaa,mwaa,mwaa,mwaa,,mwaa,,,MWAA,MWAA,,1,,,aws_mwaa_,,mwaa_,MWAA (Managed Workflows for Apache Airflow),Amazon,,,,,,, neptune,neptune,neptune,neptune,,neptune,,,Neptune,Neptune,,1,,,aws_neptune_,,neptune_,Neptune,Amazon,,,,,,, diff --git a/names/names.go b/names/names.go index b40714b4082..03078f105a7 100644 --- a/names/names.go +++ b/names/names.go @@ -65,6 +65,7 @@ const ( LambdaEndpointID = "lambda" LexV2ModelsEndpointID = "models-v2-lex" MediaLiveEndpointID = "medialive" + MQEndpointID = "mq" ObservabilityAccessManagerEndpointID = "oam" OpenSearchServerlessEndpointID = "aoss" PipesEndpointID = "pipes"