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/aws_sqs_queue: Backwards compatibility fix for default kms_data_key_reuse_period_seconds #19834

Merged
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
3 changes: 3 additions & 0 deletions .changelog/19834.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_sqs_queue: Correctly handle the default `kms_data_key_reuse_period_seconds` value of `300` for unencrypted queues
```
1 change: 1 addition & 0 deletions aws/internal/service/sqs/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (

const (
DefaultQueueDelaySeconds = 0
DefaultQueueKmsDataKeyReusePeriodSeconds = 300
DefaultQueueMaximumMessageSize = 262_144 // 256 KiB.
DefaultQueueMessageRetentionPeriod = 345_600 // 4 days.
DefaultQueueReceiveMessageWaitTimeSeconds = 0
Expand Down
18 changes: 15 additions & 3 deletions aws/internal/service/sqs/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package waiter

import (
"fmt"
"strconv"
"time"

"github.com/aws/aws-sdk-go/service/sqs"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
awspolicy "github.com/jen20/awspolicyequivalence"
tfjson "github.com/terraform-providers/terraform-provider-aws/aws/internal/json"
tfsqs "github.com/terraform-providers/terraform-provider-aws/aws/internal/service/sqs"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/sqs/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)
Expand Down Expand Up @@ -35,6 +37,16 @@ func QueueAttributesPropagated(conn *sqs.SQS, url string, expected map[string]st
g, ok := got[k]

if !ok {
// Missing attribute equivalent to empty expected value.
if e == "" {
continue
}

// Backwards compatibility: https://github.com/hashicorp/terraform-provider-aws/issues/19786.
if k == sqs.QueueAttributeNameKmsDataKeyReusePeriodSeconds && e == strconv.Itoa(tfsqs.DefaultQueueKmsDataKeyReusePeriodSeconds) {
continue
}

return fmt.Errorf("SQS Queue attribute (%s) not available", k)
}

Expand Down Expand Up @@ -90,10 +102,10 @@ func QueueAttributesPropagated(conn *sqs.SQS, url string, expected map[string]st
}

err = attributesMatch(got)
}

if err != nil {
return err
}
if err != nil {
return err
}

return nil
Expand Down
5 changes: 5 additions & 0 deletions aws/resource_aws_sqs_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ func resourceAwsSqsQueueRead(d *schema.ResourceData, meta interface{}) error {
return err
}

// Backwards compatibility: https://github.com/hashicorp/terraform-provider-aws/issues/19786.
if d.Get("kms_data_key_reuse_period_seconds").(int) == 0 {
d.Set("kms_data_key_reuse_period_seconds", tfsqs.DefaultQueueKmsDataKeyReusePeriodSeconds)
}

d.Set("name", name)
if d.Get("fifo_queue").(bool) {
d.Set("name_prefix", naming.NamePrefixFromNameWithSuffix(name, tfsqs.FifoQueueNameSuffix))
Expand Down
43 changes: 40 additions & 3 deletions aws/resource_aws_sqs_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestAccAWSSQSQueue_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "delay_seconds", strconv.Itoa(tfsqs.DefaultQueueDelaySeconds)),
resource.TestCheckResourceAttr(resourceName, "fifo_queue", "false"),
resource.TestCheckResourceAttr(resourceName, "fifo_throughput_limit", ""),
resource.TestCheckResourceAttr(resourceName, "kms_data_key_reuse_period_seconds", "0"),
resource.TestCheckResourceAttr(resourceName, "kms_data_key_reuse_period_seconds", strconv.Itoa(tfsqs.DefaultQueueKmsDataKeyReusePeriodSeconds)),
resource.TestCheckResourceAttr(resourceName, "kms_master_key_id", ""),
resource.TestCheckResourceAttr(resourceName, "max_message_size", strconv.Itoa(tfsqs.DefaultQueueMaximumMessageSize)),
resource.TestCheckResourceAttr(resourceName, "message_retention_seconds", strconv.Itoa(tfsqs.DefaultQueueMessageRetentionPeriod)),
Expand Down Expand Up @@ -323,7 +323,7 @@ func TestAccAWSSQSQueue_Update(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "delay_seconds", strconv.Itoa(tfsqs.DefaultQueueDelaySeconds)),
resource.TestCheckResourceAttr(resourceName, "fifo_queue", "false"),
resource.TestCheckResourceAttr(resourceName, "fifo_throughput_limit", ""),
resource.TestCheckResourceAttr(resourceName, "kms_data_key_reuse_period_seconds", "0"),
resource.TestCheckResourceAttr(resourceName, "kms_data_key_reuse_period_seconds", strconv.Itoa(tfsqs.DefaultQueueKmsDataKeyReusePeriodSeconds)),
resource.TestCheckResourceAttr(resourceName, "kms_master_key_id", ""),
resource.TestCheckResourceAttr(resourceName, "max_message_size", strconv.Itoa(tfsqs.DefaultQueueMaximumMessageSize)),
resource.TestCheckResourceAttr(resourceName, "message_retention_seconds", strconv.Itoa(tfsqs.DefaultQueueMessageRetentionPeriod)),
Expand All @@ -346,7 +346,7 @@ func TestAccAWSSQSQueue_Update(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "delay_seconds", "90"),
resource.TestCheckResourceAttr(resourceName, "fifo_queue", "false"),
resource.TestCheckResourceAttr(resourceName, "fifo_throughput_limit", ""),
resource.TestCheckResourceAttr(resourceName, "kms_data_key_reuse_period_seconds", "0"),
resource.TestCheckResourceAttr(resourceName, "kms_data_key_reuse_period_seconds", strconv.Itoa(tfsqs.DefaultQueueKmsDataKeyReusePeriodSeconds)),
resource.TestCheckResourceAttr(resourceName, "kms_master_key_id", ""),
resource.TestCheckResourceAttr(resourceName, "max_message_size", "2048"),
resource.TestCheckResourceAttr(resourceName, "message_retention_seconds", "86400"),
Expand Down Expand Up @@ -650,6 +650,34 @@ func TestAccAWSSQSQueue_ZeroVisibilityTimeoutSeconds(t *testing.T) {
})
}

// https://github.com/hashicorp/terraform-provider-aws/issues/19786.
func TestAccAWSSQSQueue_DefaultKmsDataKeyReusePeriodSeconds(t *testing.T) {
var queueAttributes map[string]string
resourceName := "aws_sqs_queue.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, sqs.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSSQSQueueDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSSQSConfigDefaultKmsDataKeyReusePeriodSeconds(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSSQSQueueExists(resourceName, &queueAttributes),
resource.TestCheckResourceAttr(resourceName, "kms_data_key_reuse_period_seconds", strconv.Itoa(tfsqs.DefaultQueueKmsDataKeyReusePeriodSeconds)),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckAWSSQSQueuePolicyAttribute(queueAttributes *map[string]string, rName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
expectedPolicyText := fmt.Sprintf(
Expand Down Expand Up @@ -952,3 +980,12 @@ resource "aws_sqs_queue" "test" {
}
`, rName)
}

func testAccAWSSQSConfigDefaultKmsDataKeyReusePeriodSeconds(rName string) string {
return fmt.Sprintf(`
resource "aws_sqs_queue" "test" {
name = %[1]q
kms_data_key_reuse_period_seconds = 300
}
`, rName)
}