From 78e208c2bd6d2e8b56f2a03a5750200da8b6d426 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Thu, 2 Nov 2023 18:14:10 -0400 Subject: [PATCH 1/8] d/ mq broker versions --- .../service/mq/engine_versions_data_source.go | 125 ++++++++++++++++++ .../mq/engine_versions_data_source_test.go | 48 +++++++ internal/service/mq/service_package_gen.go | 5 + .../docs/d/mq_engine_versions.html.markdown | 44 ++++++ 4 files changed, 222 insertions(+) create mode 100644 internal/service/mq/engine_versions_data_source.go create mode 100644 internal/service/mq/engine_versions_data_source_test.go create mode 100644 website/docs/d/mq_engine_versions.html.markdown diff --git a/internal/service/mq/engine_versions_data_source.go b/internal/service/mq/engine_versions_data_source.go new file mode 100644 index 00000000000..0dfd17b7805 --- /dev/null +++ b/internal/service/mq/engine_versions_data_source.go @@ -0,0 +1,125 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package mq + +import ( + "context" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/mq" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/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/create" + "github.com/hashicorp/terraform-provider-aws/names" +) + +// Function annotations are used for datasource registration to the Provider. DO NOT EDIT. +// @SDKDataSource("aws_mq_engine_versions", name="Engine Versions") +func DataSourceEngineVersions() *schema.Resource { + return &schema.Resource{ + ReadWithoutTimeout: dataSourceEngineVersionsRead, + Schema: map[string]*schema.Schema{ + "filters": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "engine_type": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{"ACTIVEMQ", "RABBITMQ"}, false), + }, + }, + }, + }, + "broker_engine_types": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "engine_type": { + Type: schema.TypeString, + Computed: true, + }, + "engine_versions": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +const ( + DSNameEngineVersions = "Engine Versions Data Source" +) + +func dataSourceEngineVersionsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).MQConn(ctx) + + input := &mq.DescribeBrokerEngineTypesInput{} + if v, ok := d.GetOk("filters"); ok { + filters := v.(*schema.Set).List() + for _, filter := range filters { + f := filter.(map[string]interface{}) + if v, ok := f["engine_type"]; ok { + input.EngineType = aws.String(v.(string)) + } + } + } + d.SetId(id.UniqueId()) + + var types []*mq.BrokerEngineType + for { + out, err := conn.DescribeBrokerEngineTypes(input) + if err != nil { + return append(diags, create.DiagError(names.MQ, create.ErrActionReading, DSNameEngineVersions, "", err)...) + } + + types = append(types, out.BrokerEngineTypes...) + if out.NextToken == nil { + break + } + input.NextToken = out.NextToken + } + if err := d.Set("broker_engine_types", flattenBrokerList(types)); err != nil { + return append(diags, create.DiagError(names.MQ, create.ErrActionSetting, DSNameEngineVersions, d.Id(), err)...) + } + + return diags +} + +func flattenBrokerList(types []*mq.BrokerEngineType) (brokers []map[string]interface{}) { + for _, broker := range types { + brokers = append(brokers, map[string]interface{}{ + "engine_type": broker.EngineType, + "engine_versions": flattenEngineVersions(broker.EngineVersions), + }) + } + return +} + +func flattenEngineVersions(engines []*mq.EngineVersion) (versions []map[string]string) { + for _, engine := range engines { + versions = append(versions, map[string]string{ + "name": aws.StringValue(engine.Name), + }) + } + return +} diff --git a/internal/service/mq/engine_versions_data_source_test.go b/internal/service/mq/engine_versions_data_source_test.go new file mode 100644 index 00000000000..73bdcd62a93 --- /dev/null +++ b/internal/service/mq/engine_versions_data_source_test.go @@ -0,0 +1,48 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package mq_test + +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" +) + +func TestAccMQEngineVersionsDataSource_basic(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_mq_engine_versions.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + acctest.PreCheck(ctx, t) + acctest.PreCheckPartitionHasService(t, mq.EndpointsID) + testAccPreCheck(ctx, t) + }, + ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: acctest.CheckDestroyNoop, + Steps: []resource.TestStep{ + { + Config: testAccEngineVersionsDataSourceConfig_basic("ACTIVEMQ"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "broker_engine_types.#", "1"), + resource.TestCheckResourceAttr(dataSourceName, "broker_engine_types.0.engine_type", "ACTIVEMQ"), + ), + }, + }, + }) +} + +func testAccEngineVersionsDataSourceConfig_basic(engineType string) string { + return fmt.Sprintf(` +data "aws_mq_engine_versions" "test" { + filters { + engine_type = %[1]q + } +} +`, engineType) +} diff --git a/internal/service/mq/service_package_gen.go b/internal/service/mq/service_package_gen.go index 65642098572..c47197f82db 100644 --- a/internal/service/mq/service_package_gen.go +++ b/internal/service/mq/service_package_gen.go @@ -33,6 +33,11 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac Factory: DataSourceBrokerInstanceTypeOfferings, TypeName: "aws_mq_broker_instance_type_offerings", }, + { + Factory: DataSourceEngineVersions, + TypeName: "aws_mq_engine_versions", + Name: "Engine Versions", + }, } } diff --git a/website/docs/d/mq_engine_versions.html.markdown b/website/docs/d/mq_engine_versions.html.markdown new file mode 100644 index 00000000000..4dea6b8723b --- /dev/null +++ b/website/docs/d/mq_engine_versions.html.markdown @@ -0,0 +1,44 @@ +--- +subcategory: "MQ" +layout: "aws" +page_title: "AWS: aws_mq_engine_versions" +description: |- + Terraform data source for managing an AWS MQ Engine Versions. +--- + +# Data Source: aws_mq_engine_versions + +Terraform data source for managing an AWS MQ Engine Versions. + +## Example Usage + +### Basic Usage + +```terraform +data "aws_mq_engine_versions" "example" { + filters { + engine_type = "ACTIVEMQ" + } +} +``` + +## Argument Reference + +* `filters` - Filters the results of the request. See [Filters](#filters). + +### filter + +The following filters are optional. + +* `engine_type` - (Optional) The database engine to return version details for. + +## Attribute Reference + +This data source exports the following attributes in addition to the arguments above: + +* `broker_engine_types` - A list of available engine types and versions. See [Engine Types](#engine-types). + +### engine-types + +* `engine_type` - The broker's engine type. +* `engine_versions` - The list of engine versions. From 8eb7bf5f6789decf7eee13c4f41c7e22ade03167 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Thu, 2 Nov 2023 18:23:47 -0400 Subject: [PATCH 2/8] changelog --- .changelog/34232.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/34232.txt diff --git a/.changelog/34232.txt b/.changelog/34232.txt new file mode 100644 index 00000000000..0f3e7ff3eb8 --- /dev/null +++ b/.changelog/34232.txt @@ -0,0 +1,3 @@ +```release-note:new-data-source +aws_mq_engine_versions +``` From f72325007e61b998dfc218e3abb9d73078a37ecf Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Thu, 2 Nov 2023 18:28:16 -0400 Subject: [PATCH 3/8] add with context --- internal/service/mq/engine_versions_data_source.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/mq/engine_versions_data_source.go b/internal/service/mq/engine_versions_data_source.go index 0dfd17b7805..8515fc011fb 100644 --- a/internal/service/mq/engine_versions_data_source.go +++ b/internal/service/mq/engine_versions_data_source.go @@ -87,7 +87,7 @@ func dataSourceEngineVersionsRead(ctx context.Context, d *schema.ResourceData, m var types []*mq.BrokerEngineType for { - out, err := conn.DescribeBrokerEngineTypes(input) + out, err := conn.DescribeBrokerEngineTypesWithContext(ctx, input) if err != nil { return append(diags, create.DiagError(names.MQ, create.ErrActionReading, DSNameEngineVersions, "", err)...) } From 4010b11bd334b12a4098595a314c140aba764cd8 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Fri, 3 Nov 2023 09:11:12 -0400 Subject: [PATCH 4/8] plural --- website/docs/d/mq_engine_versions.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/d/mq_engine_versions.html.markdown b/website/docs/d/mq_engine_versions.html.markdown index 4dea6b8723b..fbc9c4c1d22 100644 --- a/website/docs/d/mq_engine_versions.html.markdown +++ b/website/docs/d/mq_engine_versions.html.markdown @@ -26,7 +26,7 @@ data "aws_mq_engine_versions" "example" { * `filters` - Filters the results of the request. See [Filters](#filters). -### filter +### filters The following filters are optional. From 6a02fdd63a45420e2214db4f96ab6509ef00eae6 Mon Sep 17 00:00:00 2001 From: Daniel Quackenbush <25692880+danquack@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:41:53 -0400 Subject: [PATCH 5/8] SDK V2 --- go.mod | 1 + go.sum | 2 ++ internal/conns/awsclient_gen.go | 5 +++++ .../service/mq/engine_versions_data_source.go | 22 ++++++++++--------- internal/service/mq/service_package_gen.go | 13 +++++++++++ names/names_data.csv | 2 +- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 90071ce15dd..bf419177feb 100644 --- a/go.mod +++ b/go.mod @@ -45,6 +45,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/mediaconnect v1.23.0 github.com/aws/aws-sdk-go-v2/service/medialive v1.40.0 github.com/aws/aws-sdk-go-v2/service/mediapackage v1.26.0 + github.com/aws/aws-sdk-go-v2/service/mq v1.19.0 github.com/aws/aws-sdk-go-v2/service/oam v1.6.0 github.com/aws/aws-sdk-go-v2/service/opensearchserverless v1.8.0 github.com/aws/aws-sdk-go-v2/service/pipes v1.6.0 diff --git a/go.sum b/go.sum index cd069fb6136..ce2f3eaace7 100644 --- a/go.sum +++ b/go.sum @@ -133,6 +133,8 @@ github.com/aws/aws-sdk-go-v2/service/medialive v1.40.0 h1:KXNXlxUVcsovV20L4AN0Sd github.com/aws/aws-sdk-go-v2/service/medialive v1.40.0/go.mod h1:eGKrvycmxzpiY8McGBQirqAu5aG/FUDlEnfcWdRByuE= github.com/aws/aws-sdk-go-v2/service/mediapackage v1.26.0 h1:P7LmCFgek9AFt0qVXdi+UmLQCNtzvIBjjt+BEeN7yzA= github.com/aws/aws-sdk-go-v2/service/mediapackage v1.26.0/go.mod h1:bVWnSoPOtMkeXpacWU4SrZkZVTBH8oXFuqhTfcQSBXQ= +github.com/aws/aws-sdk-go-v2/service/mq v1.19.0 h1:9gf5yIYxN+ASrWlgpLC5w2FgL+CTu7hxx4HWFS60NUE= +github.com/aws/aws-sdk-go-v2/service/mq v1.19.0/go.mod h1:taU41fCZSh94vkDwHlxMn+JeRPwu+lCzDLF1WCsTNUk= github.com/aws/aws-sdk-go-v2/service/oam v1.6.0 h1:XP1GGbtv6hIc+sW7Ox7FbWpnUu8r3kpvilzDX16M/IY= github.com/aws/aws-sdk-go-v2/service/oam v1.6.0/go.mod h1:vpZZihQNeatrVSplIVGqqALTmNqy9hAZztlrIJ1m/us= github.com/aws/aws-sdk-go-v2/service/opensearchserverless v1.8.0 h1:gXOVrOah9FrDG/DjTIqJYTudJSqlnDRlWB5TP4z9aXU= diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index 961e333f78c..4ca6c8eb73e 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -39,6 +39,7 @@ import ( mediaconnect_sdkv2 "github.com/aws/aws-sdk-go-v2/service/mediaconnect" medialive_sdkv2 "github.com/aws/aws-sdk-go-v2/service/medialive" mediapackage_sdkv2 "github.com/aws/aws-sdk-go-v2/service/mediapackage" + mq_sdkv2 "github.com/aws/aws-sdk-go-v2/service/mq" oam_sdkv2 "github.com/aws/aws-sdk-go-v2/service/oam" opensearchserverless_sdkv2 "github.com/aws/aws-sdk-go-v2/service/opensearchserverless" pipes_sdkv2 "github.com/aws/aws-sdk-go-v2/service/pipes" @@ -755,6 +756,10 @@ func (c *AWSClient) MQConn(ctx context.Context) *mq_sdkv1.MQ { return errs.Must(conn[*mq_sdkv1.MQ](ctx, c, names.MQ)) } +func (c *AWSClient) MQClient(ctx context.Context) *mq_sdkv2.Client { + return errs.Must(client[*mq_sdkv2.Client](ctx, c, names.MQ)) +} + func (c *AWSClient) MWAAConn(ctx context.Context) *mwaa_sdkv1.MWAA { return errs.Must(conn[*mwaa_sdkv1.MWAA](ctx, c, names.MWAA)) } diff --git a/internal/service/mq/engine_versions_data_source.go b/internal/service/mq/engine_versions_data_source.go index 8515fc011fb..3bcc4b54b76 100644 --- a/internal/service/mq/engine_versions_data_source.go +++ b/internal/service/mq/engine_versions_data_source.go @@ -6,8 +6,9 @@ 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/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -71,7 +72,7 @@ const ( func dataSourceEngineVersionsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).MQConn(ctx) + client := meta.(*conns.AWSClient).MQClient(ctx) input := &mq.DescribeBrokerEngineTypesInput{} if v, ok := d.GetOk("filters"); ok { @@ -85,27 +86,28 @@ func dataSourceEngineVersionsRead(ctx context.Context, d *schema.ResourceData, m } d.SetId(id.UniqueId()) - var types []*mq.BrokerEngineType + var engineTypes []types.BrokerEngineType for { - out, err := conn.DescribeBrokerEngineTypesWithContext(ctx, input) + out, err := client.DescribeBrokerEngineTypes(ctx, input) if err != nil { return append(diags, create.DiagError(names.MQ, create.ErrActionReading, DSNameEngineVersions, "", err)...) } - types = append(types, out.BrokerEngineTypes...) + engineTypes = append(engineTypes, out.BrokerEngineTypes...) if out.NextToken == nil { break } input.NextToken = out.NextToken } - if err := d.Set("broker_engine_types", flattenBrokerList(types)); err != nil { + + if err := d.Set("broker_engine_types", flattenBrokerList(engineTypes)); err != nil { return append(diags, create.DiagError(names.MQ, create.ErrActionSetting, DSNameEngineVersions, d.Id(), err)...) } return diags } -func flattenBrokerList(types []*mq.BrokerEngineType) (brokers []map[string]interface{}) { +func flattenBrokerList(types []types.BrokerEngineType) (brokers []map[string]interface{}) { for _, broker := range types { brokers = append(brokers, map[string]interface{}{ "engine_type": broker.EngineType, @@ -115,10 +117,10 @@ func flattenBrokerList(types []*mq.BrokerEngineType) (brokers []map[string]inter return } -func flattenEngineVersions(engines []*mq.EngineVersion) (versions []map[string]string) { +func flattenEngineVersions(engines []types.EngineVersion) (versions []map[string]string) { for _, engine := range engines { versions = append(versions, map[string]string{ - "name": aws.StringValue(engine.Name), + "name": aws.ToString(engine.Name), }) } return diff --git a/internal/service/mq/service_package_gen.go b/internal/service/mq/service_package_gen.go index c47197f82db..d6ff59beda0 100644 --- a/internal/service/mq/service_package_gen.go +++ b/internal/service/mq/service_package_gen.go @@ -5,6 +5,8 @@ package mq import ( "context" + 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" @@ -73,6 +75,17 @@ func (p *servicePackage) NewConn(ctx context.Context, config map[string]any) (*m 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)) + + return mq_sdkv2.NewFromConfig(cfg, func(o *mq_sdkv2.Options) { + if endpoint := config["endpoint"].(string); endpoint != "" { + o.BaseEndpoint = aws_sdkv2.String(endpoint) + } + }), nil +} + func ServicePackage(ctx context.Context) conns.ServicePackage { return &servicePackage{} } diff --git a/names/names_data.csv b/names/names_data.csv index 851099c2745..7e4e62adb2b 100644 --- a/names/names_data.csv +++ b/names/names_data.csv @@ -249,7 +249,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,,,aws_mq_,,mq_,MQ,Amazon,,,,,, +mq,mq,mq,mq,,mq,,,MQ,MQ,,1,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,,,,,, From c51d42f8fa28456ba9532361b20c329f38bbce43 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 22 Dec 2023 11:05:44 -0500 Subject: [PATCH 6/8] d/aws_mq_engine_versions: 'filter' -> 'engine_type'. --- .../service/mq/engine_versions_data_source.go | 58 +++++++------------ .../mq/engine_versions_data_source_test.go | 5 +- .../docs/d/mq_engine_versions.html.markdown | 12 +--- 3 files changed, 25 insertions(+), 50 deletions(-) diff --git a/internal/service/mq/engine_versions_data_source.go b/internal/service/mq/engine_versions_data_source.go index 3bcc4b54b76..c2e52e95a70 100644 --- a/internal/service/mq/engine_versions_data_source.go +++ b/internal/service/mq/engine_versions_data_source.go @@ -12,10 +12,9 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/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/create" - "github.com/hashicorp/terraform-provider-aws/names" + "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" ) // Function annotations are used for datasource registration to the Provider. DO NOT EDIT. @@ -23,21 +22,8 @@ import ( func DataSourceEngineVersions() *schema.Resource { return &schema.Resource{ ReadWithoutTimeout: dataSourceEngineVersionsRead, + Schema: map[string]*schema.Schema{ - "filters": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "engine_type": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{"ACTIVEMQ", "RABBITMQ"}, false), - }, - }, - }, - }, "broker_engine_types": { Type: schema.TypeList, Computed: true, @@ -62,46 +48,46 @@ func DataSourceEngineVersions() *schema.Resource { }, }, }, + "engine_type": { + Type: schema.TypeString, + Optional: true, + ValidateDiagFunc: enum.Validate[types.EngineType](), + }, }, } } -const ( - DSNameEngineVersions = "Engine Versions Data Source" -) - func dataSourceEngineVersionsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics client := meta.(*conns.AWSClient).MQClient(ctx) input := &mq.DescribeBrokerEngineTypesInput{} - if v, ok := d.GetOk("filters"); ok { - filters := v.(*schema.Set).List() - for _, filter := range filters { - f := filter.(map[string]interface{}) - if v, ok := f["engine_type"]; ok { - input.EngineType = aws.String(v.(string)) - } - } + + if v, ok := d.GetOk("engine_type"); ok { + input.EngineType = aws.String(v.(string)) } - d.SetId(id.UniqueId()) var engineTypes []types.BrokerEngineType for { - out, err := client.DescribeBrokerEngineTypes(ctx, input) + output, err := client.DescribeBrokerEngineTypes(ctx, input) + if err != nil { - return append(diags, create.DiagError(names.MQ, create.ErrActionReading, DSNameEngineVersions, "", err)...) + return sdkdiag.AppendErrorf(diags, "reading MQ Broker Engine Types: %s", err) } - engineTypes = append(engineTypes, out.BrokerEngineTypes...) - if out.NextToken == nil { + engineTypes = append(engineTypes, output.BrokerEngineTypes...) + + if output.NextToken == nil { break } - input.NextToken = out.NextToken + + input.NextToken = output.NextToken } + d.SetId(id.UniqueId()) + if err := d.Set("broker_engine_types", flattenBrokerList(engineTypes)); err != nil { - return append(diags, create.DiagError(names.MQ, create.ErrActionSetting, DSNameEngineVersions, d.Id(), err)...) + return sdkdiag.AppendErrorf(diags, "setting broker_engine_types: %s", err) } return diags diff --git a/internal/service/mq/engine_versions_data_source_test.go b/internal/service/mq/engine_versions_data_source_test.go index 73bdcd62a93..00d6f26c27c 100644 --- a/internal/service/mq/engine_versions_data_source_test.go +++ b/internal/service/mq/engine_versions_data_source_test.go @@ -24,7 +24,6 @@ func TestAccMQEngineVersionsDataSource_basic(t *testing.T) { }, ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: acctest.CheckDestroyNoop, Steps: []resource.TestStep{ { Config: testAccEngineVersionsDataSourceConfig_basic("ACTIVEMQ"), @@ -40,9 +39,7 @@ func TestAccMQEngineVersionsDataSource_basic(t *testing.T) { func testAccEngineVersionsDataSourceConfig_basic(engineType string) string { return fmt.Sprintf(` data "aws_mq_engine_versions" "test" { - filters { - engine_type = %[1]q - } + engine_type = %[1]q } `, engineType) } diff --git a/website/docs/d/mq_engine_versions.html.markdown b/website/docs/d/mq_engine_versions.html.markdown index fbc9c4c1d22..82dc9509e38 100644 --- a/website/docs/d/mq_engine_versions.html.markdown +++ b/website/docs/d/mq_engine_versions.html.markdown @@ -16,21 +16,13 @@ Terraform data source for managing an AWS MQ Engine Versions. ```terraform data "aws_mq_engine_versions" "example" { - filters { - engine_type = "ACTIVEMQ" - } + engine_type = "ACTIVEMQ" } ``` ## Argument Reference -* `filters` - Filters the results of the request. See [Filters](#filters). - -### filters - -The following filters are optional. - -* `engine_type` - (Optional) The database engine to return version details for. +* `engine_type` - (Optional) The MQ engine type to return version details for. ## Attribute Reference From 0ad3cd4939b98d79cead7b9707159275de0cf635 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 22 Dec 2023 11:11:16 -0500 Subject: [PATCH 7/8] 'aws_mq_engine_versions' -> 'aws_mq_broker_engine_types'. --- .changelog/34232.txt | 2 +- ...source.go => broker_engine_types_data_source.go} | 13 ++++++------- ...t.go => broker_engine_types_data_source_test.go} | 10 +++++----- internal/service/mq/service_package_gen.go | 10 +++++----- ...l.markdown => broker_engine_types.html.markdown} | 10 +++++----- 5 files changed, 22 insertions(+), 23 deletions(-) rename internal/service/mq/{engine_versions_data_source.go => broker_engine_types_data_source.go} (85%) rename internal/service/mq/{engine_versions_data_source_test.go => broker_engine_types_data_source_test.go} (75%) rename website/docs/d/{mq_engine_versions.html.markdown => broker_engine_types.html.markdown} (69%) diff --git a/.changelog/34232.txt b/.changelog/34232.txt index 0f3e7ff3eb8..eaddc04a996 100644 --- a/.changelog/34232.txt +++ b/.changelog/34232.txt @@ -1,3 +1,3 @@ ```release-note:new-data-source -aws_mq_engine_versions +aws_mq_broker_engine_types ``` diff --git a/internal/service/mq/engine_versions_data_source.go b/internal/service/mq/broker_engine_types_data_source.go similarity index 85% rename from internal/service/mq/engine_versions_data_source.go rename to internal/service/mq/broker_engine_types_data_source.go index c2e52e95a70..912dafed251 100644 --- a/internal/service/mq/engine_versions_data_source.go +++ b/internal/service/mq/broker_engine_types_data_source.go @@ -17,11 +17,10 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" ) -// Function annotations are used for datasource registration to the Provider. DO NOT EDIT. -// @SDKDataSource("aws_mq_engine_versions", name="Engine Versions") -func DataSourceEngineVersions() *schema.Resource { +// @SDKDataSource("aws_mq_broker_engine_types", name="Broker Engine Types") +func DataSourceBrokerEngineTypes() *schema.Resource { return &schema.Resource{ - ReadWithoutTimeout: dataSourceEngineVersionsRead, + ReadWithoutTimeout: dataSourceBrokerEngineTypesRead, Schema: map[string]*schema.Schema{ "broker_engine_types": { @@ -49,15 +48,15 @@ func DataSourceEngineVersions() *schema.Resource { }, }, "engine_type": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, ValidateDiagFunc: enum.Validate[types.EngineType](), }, }, } } -func dataSourceEngineVersionsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { +func dataSourceBrokerEngineTypesRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics client := meta.(*conns.AWSClient).MQClient(ctx) diff --git a/internal/service/mq/engine_versions_data_source_test.go b/internal/service/mq/broker_engine_types_data_source_test.go similarity index 75% rename from internal/service/mq/engine_versions_data_source_test.go rename to internal/service/mq/broker_engine_types_data_source_test.go index 00d6f26c27c..e703975aac1 100644 --- a/internal/service/mq/engine_versions_data_source_test.go +++ b/internal/service/mq/broker_engine_types_data_source_test.go @@ -12,9 +12,9 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/acctest" ) -func TestAccMQEngineVersionsDataSource_basic(t *testing.T) { +func TestAccMQBrokerEngineTypesDataSource_basic(t *testing.T) { ctx := acctest.Context(t) - dataSourceName := "data.aws_mq_engine_versions.test" + dataSourceName := "data.aws_mq_broker_engine_types.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { @@ -26,7 +26,7 @@ func TestAccMQEngineVersionsDataSource_basic(t *testing.T) { ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccEngineVersionsDataSourceConfig_basic("ACTIVEMQ"), + Config: testAccBrokerEngineTypesDataSourceConfig_basic("ACTIVEMQ"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "broker_engine_types.#", "1"), resource.TestCheckResourceAttr(dataSourceName, "broker_engine_types.0.engine_type", "ACTIVEMQ"), @@ -36,9 +36,9 @@ func TestAccMQEngineVersionsDataSource_basic(t *testing.T) { }) } -func testAccEngineVersionsDataSourceConfig_basic(engineType string) string { +func testAccBrokerEngineTypesDataSourceConfig_basic(engineType string) string { return fmt.Sprintf(` -data "aws_mq_engine_versions" "test" { +data "aws_mq_broker_engine_types" "test" { engine_type = %[1]q } `, engineType) diff --git a/internal/service/mq/service_package_gen.go b/internal/service/mq/service_package_gen.go index d6ff59beda0..aa815cc431d 100644 --- a/internal/service/mq/service_package_gen.go +++ b/internal/service/mq/service_package_gen.go @@ -32,13 +32,13 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac TypeName: "aws_mq_broker", }, { - Factory: DataSourceBrokerInstanceTypeOfferings, - TypeName: "aws_mq_broker_instance_type_offerings", + Factory: DataSourceBrokerEngineTypes, + TypeName: "aws_mq_broker_engine_types", + Name: "Broker Engine Types", }, { - Factory: DataSourceEngineVersions, - TypeName: "aws_mq_engine_versions", - Name: "Engine Versions", + Factory: DataSourceBrokerInstanceTypeOfferings, + TypeName: "aws_mq_broker_instance_type_offerings", }, } } diff --git a/website/docs/d/mq_engine_versions.html.markdown b/website/docs/d/broker_engine_types.html.markdown similarity index 69% rename from website/docs/d/mq_engine_versions.html.markdown rename to website/docs/d/broker_engine_types.html.markdown index 82dc9509e38..0a711a21659 100644 --- a/website/docs/d/mq_engine_versions.html.markdown +++ b/website/docs/d/broker_engine_types.html.markdown @@ -1,21 +1,21 @@ --- subcategory: "MQ" layout: "aws" -page_title: "AWS: aws_mq_engine_versions" +page_title: "AWS: aws_mq_broker_engine_types" description: |- - Terraform data source for managing an AWS MQ Engine Versions. + Retrieve information about available broker engines. --- -# Data Source: aws_mq_engine_versions +# Data Source: aws_mq_broker_engine_types -Terraform data source for managing an AWS MQ Engine Versions. +Retrieve information about available broker engines. ## Example Usage ### Basic Usage ```terraform -data "aws_mq_engine_versions" "example" { +data "aws_mq_broker_engine_types" "example" { engine_type = "ACTIVEMQ" } ``` From b0f3b7144c99278c71fd95f0e793a236e0f453ef Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 22 Dec 2023 11:25:55 -0500 Subject: [PATCH 8/8] Correct documentation file name. --- ...e_types.html.markdown => mq_broker_engine_types.html.markdown} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename website/docs/d/{broker_engine_types.html.markdown => mq_broker_engine_types.html.markdown} (100%) diff --git a/website/docs/d/broker_engine_types.html.markdown b/website/docs/d/mq_broker_engine_types.html.markdown similarity index 100% rename from website/docs/d/broker_engine_types.html.markdown rename to website/docs/d/mq_broker_engine_types.html.markdown