Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d/aws_mq_engine_versions + add sdkv2 client for mq #34232

Merged
merged 9 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/34232.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_mq_engine_versions
```
125 changes: 125 additions & 0 deletions internal/service/mq/engine_versions_data_source.go
Original file line number Diff line number Diff line change
@@ -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"
danquack marked this conversation as resolved.
Show resolved Hide resolved
"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.DescribeBrokerEngineTypesWithContext(ctx, 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
}
48 changes: 48 additions & 0 deletions internal/service/mq/engine_versions_data_source_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
5 changes: 5 additions & 0 deletions internal/service/mq/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions website/docs/d/mq_engine_versions.html.markdown
Original file line number Diff line number Diff line change
@@ -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).

### filters

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.
Loading