Skip to content

Commit

Permalink
Merge pull request #33496 from vicyap/t-aws-mq-update-tests-for-rabbi…
Browse files Browse the repository at this point in the history
…tmq-configuration

t/aws-mq-update-tests-for-rabbitmq-configuration
  • Loading branch information
ewbankkit authored Sep 19, 2023
2 parents dd99384 + 7373732 commit d6517bb
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 11 deletions.
95 changes: 93 additions & 2 deletions internal/service/mq/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,55 @@ func TestAccMQBroker_RabbitMQ_basic(t *testing.T) {
Config: testAccBrokerConfig_rabbit(rName, testAccRabbitVersion),
Check: resource.ComposeTestCheckFunc(
testAccCheckBrokerExists(ctx, resourceName, &broker),
resource.TestCheckResourceAttr(resourceName, "configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "configuration.#", "1"),
resource.TestCheckResourceAttr(resourceName, "engine_type", "RabbitMQ"),
resource.TestCheckResourceAttr(resourceName, "engine_version", testAccRabbitVersion),
resource.TestCheckResourceAttr(resourceName, "host_instance_type", "mq.t3.micro"),
resource.TestCheckResourceAttr(resourceName, "instances.#", "1"),
resource.TestCheckResourceAttr(resourceName, "instances.0.endpoints.#", "1"),
resource.TestMatchResourceAttr(resourceName, "instances.0.endpoints.0", regexache.MustCompile(`^amqps://[0-9a-z.-]+:5671$`)),
resource.TestCheckResourceAttr(resourceName, "logs.#", "1"),
resource.TestCheckResourceAttr(resourceName, "logs.0.general", "false"),
resource.TestCheckResourceAttr(resourceName, "logs.0.audit", ""),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"apply_immediately", "user"},
},
},
})
}

func TestAccMQBroker_RabbitMQ_config(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var broker mq.DescribeBrokerResponse
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)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, mq.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckBrokerDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccBrokerConfig_rabbitConfig(rName, testAccRabbitVersion),
Check: resource.ComposeTestCheckFunc(
testAccCheckBrokerExists(ctx, resourceName, &broker),
resource.TestCheckResourceAttr(resourceName, "configuration.#", "1"),
resource.TestMatchResourceAttr(resourceName, "configuration.0.id", regexache.MustCompile(`^c-[0-9a-z-]+$`)),
resource.TestCheckResourceAttr(resourceName, "configuration.0.revision", "2"),
resource.TestCheckResourceAttr(resourceName, "engine_type", "RabbitMQ"),
resource.TestCheckResourceAttr(resourceName, "engine_version", testAccRabbitVersion),
resource.TestCheckResourceAttr(resourceName, "host_instance_type", "mq.t3.micro"),
Expand Down Expand Up @@ -1148,7 +1196,7 @@ func TestAccMQBroker_RabbitMQ_logs(t *testing.T) {
Config: testAccBrokerConfig_rabbitLogs(rName, testAccRabbitVersion),
Check: resource.ComposeTestCheckFunc(
testAccCheckBrokerExists(ctx, resourceName, &broker),
resource.TestCheckResourceAttr(resourceName, "configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "configuration.#", "1"),
resource.TestCheckResourceAttr(resourceName, "engine_type", "RabbitMQ"),
resource.TestCheckResourceAttr(resourceName, "engine_version", testAccRabbitVersion),
resource.TestCheckResourceAttr(resourceName, "host_instance_type", "mq.t3.micro"),
Expand Down Expand Up @@ -1973,6 +2021,49 @@ resource "aws_mq_broker" "test" {
`, rName, version)
}

func testAccBrokerConfig_rabbitConfig(rName, version string) string {
return fmt.Sprintf(`
resource "aws_security_group" "test" {
name = %[1]q
tags = {
Name = %[1]q
}
}
resource "aws_mq_configuration" "test" {
description = "TfAccTest MQ Configuration"
name = %[1]q
engine_type = "RabbitMQ"
engine_version = %[2]q
data = <<DATA
# Default RabbitMQ delivery acknowledgement timeout is 30 minutes
consumer_timeout = 1800000
DATA
}
resource "aws_mq_broker" "test" {
broker_name = %[1]q
engine_type = "RabbitMQ"
engine_version = %[2]q
host_instance_type = "mq.t3.micro"
security_groups = [aws_security_group.test.id]
configuration {
id = aws_mq_configuration.test.id
revision = aws_mq_configuration.test.latest_revision
}
user {
username = "Test"
password = "TestTest1234"
}
}
`, rName, version)
}

func testAccBrokerConfig_rabbitLogs(rName, version string) string {
return fmt.Sprintf(`
resource "aws_mq_broker" "test" {
Expand Down
64 changes: 58 additions & 6 deletions internal/service/mq/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestAccMQConfiguration_basic(t *testing.T) {
})
}

func TestAccMQConfiguration_withData(t *testing.T) {
func TestAccMQConfiguration_withActiveMQData(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_mq_configuration.test"
Expand All @@ -83,7 +83,7 @@ func TestAccMQConfiguration_withData(t *testing.T) {
CheckDestroy: acctest.CheckDestroyNoop,
Steps: []resource.TestStep{
{
Config: testAccConfigurationConfig_data(rName),
Config: testAccConfigurationConfig_activeData(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckConfigurationExists(ctx, resourceName),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "mq", regexache.MustCompile(`configuration:+.`)),
Expand All @@ -103,7 +103,7 @@ func TestAccMQConfiguration_withData(t *testing.T) {
})
}

func TestAccMQConfiguration_withLdapData(t *testing.T) {
func TestAccMQConfiguration_withActiveMQLdapData(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_mq_configuration.test"
Expand All @@ -119,7 +119,7 @@ func TestAccMQConfiguration_withLdapData(t *testing.T) {
CheckDestroy: acctest.CheckDestroyNoop,
Steps: []resource.TestStep{
{
Config: testAccConfigurationConfig_ldapData(rName),
Config: testAccConfigurationConfig_activeLdapData(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckConfigurationExists(ctx, resourceName),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "mq", regexache.MustCompile(`configuration:+.`)),
Expand All @@ -140,6 +140,43 @@ func TestAccMQConfiguration_withLdapData(t *testing.T) {
})
}

func TestAccMQConfiguration_withRabbitMQData(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_mq_configuration.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: testAccConfigurationConfig_rabbitData(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckConfigurationExists(ctx, resourceName),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "mq", regexache.MustCompile(`configuration:+.`)),
resource.TestCheckResourceAttr(resourceName, "description", "TfAccTest MQ Configuration"),
resource.TestCheckResourceAttr(resourceName, "engine_type", "RabbitMQ"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "3.11.16"),
resource.TestCheckResourceAttr(resourceName, "latest_revision", "2"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "data", "consumer_timeout = 60000\n"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccMQConfiguration_tags(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand Down Expand Up @@ -243,7 +280,7 @@ DATA
`, rName)
}

func testAccConfigurationConfig_data(rName string) string {
func testAccConfigurationConfig_activeData(rName string) string {
return fmt.Sprintf(`
resource "aws_mq_configuration" "test" {
description = "TfAccTest MQ Configuration"
Expand Down Expand Up @@ -278,7 +315,7 @@ DATA
`, rName)
}

func testAccConfigurationConfig_ldapData(rName string) string {
func testAccConfigurationConfig_activeLdapData(rName string) string {
return fmt.Sprintf(`
resource "aws_mq_configuration" "test" {
description = "TfAccTest MQ Configuration"
Expand Down Expand Up @@ -306,6 +343,21 @@ DATA
`, rName)
}

func testAccConfigurationConfig_rabbitData(rName string) string {
return fmt.Sprintf(`
resource "aws_mq_configuration" "test" {
description = "TfAccTest MQ Configuration"
name = %[1]q
engine_type = "RabbitMQ"
engine_version = "3.11.16"
data = <<DATA
consumer_timeout = 60000
DATA
}
`, rName)
}

func testAccConfigurationConfig_tags1(rName, tagKey1, tagValue1 string) string {
return fmt.Sprintf(`
resource "aws_mq_configuration" "test" {
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/mq_broker.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Provides an Amazon MQ broker resource. This resources also manages users for the

-> For more information on Amazon MQ, see [Amazon MQ documentation](https://docs.aws.amazon.com/amazon-mq/latest/developer-guide/welcome.html).

~> **NOTE:** Amazon MQ currently places limits on **RabbitMQ** brokers. For example, a RabbitMQ broker cannot have: instances with an associated IP address of an ENI attached to the broker, an associated LDAP server to authenticate and authorize broker connections, storage type `EFS`, audit logging, or `configuration` blocks. Although this resource allows you to create RabbitMQ users, RabbitMQ users cannot have console access or groups. Also, Amazon MQ does not return information about RabbitMQ users so drift detection is not possible.
~> **NOTE:** Amazon MQ currently places limits on **RabbitMQ** brokers. For example, a RabbitMQ broker cannot have: instances with an associated IP address of an ENI attached to the broker, an associated LDAP server to authenticate and authorize broker connections, storage type `EFS`, or audit logging. Although this resource allows you to create RabbitMQ users, RabbitMQ users cannot have console access or groups. Also, Amazon MQ does not return information about RabbitMQ users so drift detection is not possible.

~> **NOTE:** Changes to an MQ Broker can occur when you change a parameter, such as `configuration` or `user`, and are reflected in the next maintenance window. Because of this, Terraform may report a difference in its planning phase because a modification has not yet taken place. You can use the `apply_immediately` flag to instruct the service to apply the change immediately (see documentation below). Using `apply_immediately` can result in a brief downtime as the broker reboots.

Expand Down Expand Up @@ -84,7 +84,7 @@ The following arguments are optional:
* `apply_immediately` - (Optional) Specifies whether any broker modifications are applied immediately, or during the next maintenance window. Default is `false`.
* `authentication_strategy` - (Optional) Authentication strategy used to secure the broker. Valid values are `simple` and `ldap`. `ldap` is not supported for `engine_type` `RabbitMQ`.
* `auto_minor_version_upgrade` - (Optional) Whether to automatically upgrade to new minor versions of brokers as Amazon MQ makes releases available.
* `configuration` - (Optional) Configuration block for broker configuration. Applies to `engine_type` of `ActiveMQ` only. Detailed below.
* `configuration` - (Optional) Configuration block for broker configuration. Applies to `engine_type` of `ActiveMQ` and `RabbitMQ` only. Detailed below.
* `deployment_mode` - (Optional) Deployment mode of the broker. Valid values are `SINGLE_INSTANCE`, `ACTIVE_STANDBY_MULTI_AZ`, and `CLUSTER_MULTI_AZ`. Default is `SINGLE_INSTANCE`.
* `encryption_options` - (Optional) Configuration block containing encryption options. Detailed below.
* `ldap_server_metadata` - (Optional) Configuration block for the LDAP server used to authenticate and authorize connections to the broker. Not supported for `engine_type` `RabbitMQ`. Detailed below. (Currently, AWS may not process changes to LDAP server metadata.)
Expand Down
20 changes: 19 additions & 1 deletion website/docs/r/mq_configuration.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ For more information on Amazon MQ, see [Amazon MQ documentation](https://docs.aw

## Example Usage

### ActiveMQ

```terraform
resource "aws_mq_configuration" "example" {
description = "Example Configuration"
Expand All @@ -34,11 +36,27 @@ DATA
}
```

### RabbitMQ

```terraform
resource "aws_mq_configuration" "example" {
description = "Example Configuration"
name = "example"
engine_type = "RabbitMQ"
engine_version = "3.11.16"
data = <<DATA
# Default RabbitMQ delivery acknowledgement timeout is 30 minutes in milliseconds
consumer_timeout = 1800000
DATA
}
```

## Argument Reference

The following arguments are required:

* `data` - (Required) Broker configuration in XML format. See [official docs](https://docs.aws.amazon.com/amazon-mq/latest/developer-guide/amazon-mq-broker-configuration-parameters.html) for supported parameters and format of the XML.
* `data` - (Required) Broker configuration in XML format for `ActiveMQ` or [Cuttlefish](https://github.com/Kyorai/cuttlefish) format for `RabbitMQ`. See [official docs](https://docs.aws.amazon.com/amazon-mq/latest/developer-guide/amazon-mq-broker-configuration-parameters.html) for supported parameters and format of the XML.
* `engine_type` - (Required) Type of broker engine. Valid values are `ActiveMQ` and `RabbitMQ`.
* `engine_version` - (Required) Version of the broker engine.
* `name` - (Required) Name of the configuration.
Expand Down

0 comments on commit d6517bb

Please sign in to comment.