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

r/mq_configuration - add import tests + remove call to list tags #11843

Merged
merged 2 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions aws/resource_aws_mq_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/mq"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

Expand Down Expand Up @@ -53,6 +54,9 @@ func resourceAwsMqConfiguration() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
mq.EngineTypeActivemq,
}, true),
},
"engine_version": {
Type: schema.TypeString,
Expand Down Expand Up @@ -106,7 +110,7 @@ func resourceAwsMqConfigurationRead(d *schema.ResourceData, meta interface{}) er
ConfigurationId: aws.String(d.Id()),
})
if err != nil {
if isAWSErr(err, "NotFoundException", "") {
if isAWSErr(err, mq.ErrCodeNotFoundException, "") {
log.Printf("[WARN] MQ Configuration %q not found, removing from state", d.Id())
d.SetId("")
return nil
Expand Down Expand Up @@ -136,11 +140,7 @@ func resourceAwsMqConfigurationRead(d *schema.ResourceData, meta interface{}) er

d.Set("data", string(b))

tags, err := keyvaluetags.MqListTags(conn, aws.StringValue(out.Arn))
if err != nil {
return fmt.Errorf("error listing tags for MQ Configuration (%s): %s", d.Id(), err)
}
if err := d.Set("tags", tags.IgnoreAws().Map()); err != nil {
if err := d.Set("tags", keyvaluetags.MqKeyValueTags(out.Tags).IgnoreAws().Map()); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}

Expand Down
83 changes: 51 additions & 32 deletions aws/resource_aws_mq_configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -13,6 +14,7 @@ import (

func TestAccAWSMqConfiguration_basic(t *testing.T) {
configurationName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5))
resourceName := "aws_mq_configuration.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSMq(t) },
Expand All @@ -22,25 +24,30 @@ func TestAccAWSMqConfiguration_basic(t *testing.T) {
{
Config: testAccMqConfigurationConfig(configurationName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsMqConfigurationExists("aws_mq_configuration.test"),
resource.TestCheckResourceAttrSet("aws_mq_configuration.test", "arn"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "description", "TfAccTest MQ Configuration"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "engine_type", "ActiveMQ"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "engine_version", "5.15.0"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "latest_revision", "2"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "name", configurationName),
testAccCheckAwsMqConfigurationExists(resourceName),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "mq", regexp.MustCompile(`configuration:+.`)),
resource.TestCheckResourceAttr(resourceName, "description", "TfAccTest MQ Configuration"),
resource.TestCheckResourceAttr(resourceName, "engine_type", "ActiveMQ"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "5.15.0"),
resource.TestCheckResourceAttr(resourceName, "latest_revision", "2"),
resource.TestCheckResourceAttr(resourceName, "name", configurationName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccMqConfigurationConfig_descriptionUpdated(configurationName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsMqConfigurationExists("aws_mq_configuration.test"),
resource.TestCheckResourceAttrSet("aws_mq_configuration.test", "arn"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "description", "TfAccTest MQ Configuration Updated"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "engine_type", "ActiveMQ"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "engine_version", "5.15.0"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "latest_revision", "3"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "name", configurationName),
testAccCheckAwsMqConfigurationExists(resourceName),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "mq", regexp.MustCompile(`configuration:+.`)),
resource.TestCheckResourceAttr(resourceName, "description", "TfAccTest MQ Configuration Updated"),
resource.TestCheckResourceAttr(resourceName, "engine_type", "ActiveMQ"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "5.15.0"),
resource.TestCheckResourceAttr(resourceName, "latest_revision", "3"),
resource.TestCheckResourceAttr(resourceName, "name", configurationName),
),
},
},
Expand All @@ -49,6 +56,7 @@ func TestAccAWSMqConfiguration_basic(t *testing.T) {

func TestAccAWSMqConfiguration_withData(t *testing.T) {
configurationName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5))
resourceName := "aws_mq_configuration.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSMq(t) },
Expand All @@ -58,21 +66,27 @@ func TestAccAWSMqConfiguration_withData(t *testing.T) {
{
Config: testAccMqConfigurationWithDataConfig(configurationName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsMqConfigurationExists("aws_mq_configuration.test"),
resource.TestCheckResourceAttrSet("aws_mq_configuration.test", "arn"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "description", "TfAccTest MQ Configuration"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "engine_type", "ActiveMQ"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "engine_version", "5.15.0"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "latest_revision", "2"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "name", configurationName),
testAccCheckAwsMqConfigurationExists(resourceName),
testAccMatchResourceAttrRegionalARN(resourceName, "arn", "mq", regexp.MustCompile(`configuration:+.`)),
resource.TestCheckResourceAttr(resourceName, "description", "TfAccTest MQ Configuration"),
resource.TestCheckResourceAttr(resourceName, "engine_type", "ActiveMQ"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "5.15.0"),
resource.TestCheckResourceAttr(resourceName, "latest_revision", "2"),
resource.TestCheckResourceAttr(resourceName, "name", configurationName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSMqConfiguration_updateTags(t *testing.T) {
configurationName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5))
resourceName := "aws_mq_configuration.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSMq(t) },
Expand All @@ -82,26 +96,31 @@ func TestAccAWSMqConfiguration_updateTags(t *testing.T) {
{
Config: testAccMqConfigurationConfig_updateTags1(configurationName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsMqConfigurationExists("aws_mq_configuration.test"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "tags.%", "1"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "tags.env", "test"),
testAccCheckAwsMqConfigurationExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.env", "test"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccMqConfigurationConfig_updateTags2(configurationName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsMqConfigurationExists("aws_mq_configuration.test"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "tags.%", "2"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "tags.env", "test2"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "tags.role", "test-role"),
testAccCheckAwsMqConfigurationExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.env", "test2"),
resource.TestCheckResourceAttr(resourceName, "tags.role", "test-role"),
),
},
{
Config: testAccMqConfigurationConfig_updateTags3(configurationName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsMqConfigurationExists("aws_mq_configuration.test"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "tags.%", "1"),
resource.TestCheckResourceAttr("aws_mq_configuration.test", "tags.role", "test-role"),
testAccCheckAwsMqConfigurationExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(resourceName, "tags.role", "test-role"),
),
},
},
Expand All @@ -122,7 +141,7 @@ func testAccCheckAwsMqConfigurationDestroy(s *terraform.State) error {

_, err := conn.DescribeConfiguration(input)
if err != nil {
if isAWSErr(err, "NotFoundException", "") {
if isAWSErr(err, mq.ErrCodeNotFoundException, "") {
return nil
}
return err
Expand Down