Skip to content

Commit

Permalink
Updated Amazon MQ functionality
Browse files Browse the repository at this point in the history
- Add support for RabbitMQ
- Add support for LDAP Authentication
- Add support for EBS storage type
- Make security groups optional since it will use the default one if omitted
  • Loading branch information
lucastetreault authored and YakDriver committed Mar 10, 2021
1 parent 19b732b commit 6a6c996
Showing 1 changed file with 200 additions and 0 deletions.
200 changes: 200 additions & 0 deletions aws/resource_aws_mq_broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,142 @@ func TestAccAWSMqBroker_rabbitmq(t *testing.T) {
})
}

func TestAccAWSMqBroker_clusterRabbitMQ(t *testing.T) {
var broker mq.DescribeBrokerResponse
rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5))
resourceName := "aws_mq_broker.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSMq(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsMqBrokerDestroy,
Steps: []resource.TestStep{
{
Config: testAccRabbitMqClusterBrokerConfig(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsMqBrokerExists(resourceName, &broker),
resource.TestCheckResourceAttr(resourceName, "auto_minor_version_upgrade", "false"),
resource.TestCheckResourceAttr(resourceName, "broker_name", rName),
resource.TestCheckResourceAttr(resourceName, "deployment_mode", "CLUSTER_MULTI_AZ"),
resource.TestCheckResourceAttr(resourceName, "encryption_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "encryption_options.0.use_aws_owned_key", "true"),
resource.TestCheckResourceAttr(resourceName, "engine_type", "RabbitMQ"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "3.8.6"),
resource.TestCheckResourceAttr(resourceName, "host_instance_type", "mq.m5.large"),
resource.TestCheckResourceAttr(resourceName, "maintenance_window_start_time.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "maintenance_window_start_time.0.day_of_week"),
resource.TestCheckResourceAttrSet(resourceName, "maintenance_window_start_time.0.time_of_day"),
resource.TestCheckResourceAttr(resourceName, "logs.#", "1"),
resource.TestCheckResourceAttr(resourceName, "logs.0.general", "false"),
resource.TestCheckResourceAttr(resourceName, "maintenance_window_start_time.0.time_zone", "UTC"),
resource.TestCheckResourceAttr(resourceName, "publicly_accessible", "false"),
resource.TestCheckResourceAttr(resourceName, "security_groups.#", "1"),
resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "4"),
resource.TestCheckResourceAttr(resourceName, "user.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "user.*", map[string]string{
"console_access": "false",
"groups.#": "0",
"username": "Test",
"password": "TestTest1234",
}),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "mq", regexp.MustCompile(`broker:+.`)),
resource.TestCheckResourceAttr(resourceName, "instances.#", "1"),
resource.TestMatchResourceAttr(resourceName, "instances.0.console_url",
regexp.MustCompile(`^https://[a-f0-9-]+\.mq.[a-z0-9-]+.amazonaws.com$`)),
resource.TestCheckResourceAttr(resourceName, "instances.0.endpoints.#", "1"),
resource.TestMatchResourceAttr(resourceName, "instances.0.endpoints.0", regexp.MustCompile(`^amqps://[a-z0-9-\.]+:5671$`)),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"apply_immediately", "user"},
},
},
})
}

func TestAccAWSMqBroker_ldap(t *testing.T) {
var broker mq.DescribeBrokerResponse
rName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5))
resourceName := "aws_mq_broker.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSMq(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsMqBrokerDestroy,
Steps: []resource.TestStep{
{
Config: testAccMqBrokerConfig_ldap(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsMqBrokerExists(resourceName, &broker),
resource.TestCheckResourceAttr(resourceName, "auto_minor_version_upgrade", "false"),
resource.TestCheckResourceAttr(resourceName, "broker_name", rName),
resource.TestCheckResourceAttr(resourceName, "configuration.#", "1"),
resource.TestMatchResourceAttr(resourceName, "configuration.0.id", regexp.MustCompile(`^c-[a-z0-9-]+$`)),
resource.TestMatchResourceAttr(resourceName, "configuration.0.revision", regexp.MustCompile(`^[0-9]+$`)),
resource.TestCheckResourceAttr(resourceName, "deployment_mode", "SINGLE_INSTANCE"),
resource.TestCheckResourceAttr(resourceName, "encryption_options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "encryption_options.0.use_aws_owned_key", "true"),
resource.TestCheckResourceAttr(resourceName, "engine_type", "ActiveMQ"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "5.15.0"),
resource.TestCheckResourceAttr(resourceName, "host_instance_type", "mq.t2.micro"),
resource.TestCheckResourceAttr(resourceName, "maintenance_window_start_time.#", "1"),
resource.TestCheckResourceAttrSet(resourceName, "maintenance_window_start_time.0.day_of_week"),
resource.TestCheckResourceAttrSet(resourceName, "maintenance_window_start_time.0.time_of_day"),
resource.TestCheckResourceAttr(resourceName, "logs.#", "1"),
resource.TestCheckResourceAttr(resourceName, "logs.0.general", "true"),
resource.TestCheckResourceAttr(resourceName, "logs.0.audit", "false"),
resource.TestCheckResourceAttr(resourceName, "maintenance_window_start_time.0.time_zone", "UTC"),
resource.TestCheckResourceAttr(resourceName, "publicly_accessible", "false"),
resource.TestCheckResourceAttr(resourceName, "security_groups.#", "1"),
resource.TestCheckResourceAttr(resourceName, "subnet_ids.#", "1"),
resource.TestCheckResourceAttr(resourceName, "user.#", "1"),
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "user.*", map[string]string{
"console_access": "false",
"groups.#": "0",
"username": "Test",
"password": "TestTest1234",
}),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "mq", regexp.MustCompile(`broker:+.`)),
resource.TestCheckResourceAttr(resourceName, "instances.#", "1"),
resource.TestMatchResourceAttr(resourceName, "instances.0.console_url",
regexp.MustCompile(`^https://[a-f0-9-]+\.mq.[a-z0-9-]+.amazonaws.com:8162$`)),
resource.TestMatchResourceAttr(resourceName, "instances.0.ip_address",
regexp.MustCompile(`^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$`)),
resource.TestCheckResourceAttr(resourceName, "instances.0.endpoints.#", "5"),
resource.TestMatchResourceAttr(resourceName, "instances.0.endpoints.0", regexp.MustCompile(`^ssl://[a-z0-9-\.]+:61617$`)),
resource.TestMatchResourceAttr(resourceName, "instances.0.endpoints.1", regexp.MustCompile(`^amqp\+ssl://[a-z0-9-\.]+:5671$`)),
resource.TestMatchResourceAttr(resourceName, "instances.0.endpoints.2", regexp.MustCompile(`^stomp\+ssl://[a-z0-9-\.]+:61614$`)),
resource.TestMatchResourceAttr(resourceName, "instances.0.endpoints.3", regexp.MustCompile(`^mqtt\+ssl://[a-z0-9-\.]+:8883$`)),
resource.TestMatchResourceAttr(resourceName, "instances.0.endpoints.4", regexp.MustCompile(`^wss://[a-z0-9-\.]+:61619$`)),
resource.TestCheckResourceAttr(resourceName, "authentication_strategy", "ldap"),
resource.TestCheckResourceAttr(resourceName, "ldap_server_metadata.0.hosts.#", "2"),
resource.TestCheckResourceAttr(resourceName, "ldap_server_metadata.0.hosts.0", "my.ldap.server-1.com"),
resource.TestCheckResourceAttr(resourceName, "ldap_server_metadata.0.hosts.1", "my.ldap.server-2.com"),
resource.TestCheckResourceAttr(resourceName, "ldap_server_metadata.0.role_base", "role.base"),
resource.TestCheckResourceAttr(resourceName, "ldap_server_metadata.0.role_name", "role.name"),
resource.TestCheckResourceAttr(resourceName, "ldap_server_metadata.0.role_search_matching", "role.search.matching"),
resource.TestCheckResourceAttr(resourceName, "ldap_server_metadata.0.role_search_subtree", "true"),
resource.TestCheckResourceAttr(resourceName, "ldap_server_metadata.0.service_account_password", "supersecret"),
resource.TestCheckResourceAttr(resourceName, "ldap_server_metadata.0.service_account_username", "admin"),
resource.TestCheckResourceAttr(resourceName, "ldap_server_metadata.0.user_base", "user.base"),
resource.TestCheckResourceAttr(resourceName, "ldap_server_metadata.0.user_role_name", "user.role.name"),
resource.TestCheckResourceAttr(resourceName, "ldap_server_metadata.0.user_search_matching", "user.search.matching"),
resource.TestCheckResourceAttr(resourceName, "ldap_server_metadata.0.user_search_subtree", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"apply_immediately", "user", "ldap_server_metadata"},
},
},
})
}

func testAccCheckAwsMqBrokerDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).mqconn

Expand Down Expand Up @@ -1617,3 +1753,67 @@ resource "aws_mq_broker" "test" {
}
`, rName)
}

func testAccRabbitMqClusterBrokerConfig(rName string) string {
return fmt.Sprintf(`
resource "aws_security_group" "test" {
name = %[1]q
}
resource "aws_mq_broker" "test" {
broker_name = %[1]q
engine_type = "RabbitMQ"
engine_version = "3.8.6"
host_instance_type = "mq.m5.large"
security_groups = [aws_security_group.test.id]
storage_type = "ebs"
deployment_mode = "CLUSTER_MULTI_AZ"
user {
username = "Test"
password = "TestTest1234"
}
}
`, rName)
}

func testAccMqBrokerConfig_ldap(rName string) string {
return fmt.Sprintf(`
resource "aws_security_group" "test" {
name = %[1]q
}
resource "aws_mq_broker" "test" {
broker_name = %[1]q
engine_type = "ActiveMQ"
engine_version = "5.15.0"
host_instance_type = "mq.t2.micro"
security_groups = [aws_security_group.test.id]
logs {
general = true
}
user {
username = "Test"
password = "TestTest1234"
}
authentication_strategy = "ldap"
ldap_server_metadata {
hosts = ["my.ldap.server-1.com", "my.ldap.server-2.com"]
role_base = "role.base"
role_name = "role.name"
role_search_matching = "role.search.matching"
role_search_subtree = true
service_account_password = "supersecret"
service_account_username = "admin"
user_base = "user.base"
user_role_name = "user.role.name"
user_search_matching = "user.search.matching"
user_search_subtree = true
}
}
`, rName)
}

0 comments on commit 6a6c996

Please sign in to comment.