Skip to content

Commit

Permalink
Merge branch 'iot-republish-qos' of ssh://github.com/drexler/terrafor…
Browse files Browse the repository at this point in the history
…m-provider-aws into drexler-iot-republish-qos
  • Loading branch information
bflad committed May 12, 2020
2 parents f6fb08b + 586f2e8 commit 9b95b2e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
14 changes: 14 additions & 0 deletions aws/resource_aws_iot_topic_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ func resourceAwsIotTopicRule() *schema.Resource {
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"qos": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
ValidateFunc: validation.IntBetween(0, 1),
},
"role_arn": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -819,6 +825,10 @@ func expandIotRepublishAction(tfList []interface{}) *iot.RepublishAction {
apiObject := &iot.RepublishAction{}
tfMap := tfList[0].(map[string]interface{})

if v, ok := tfMap["qos"].(int); ok {
apiObject.Qos = aws.Int64(int64(v))
}

if v, ok := tfMap["role_arn"].(string); ok && v != "" {
apiObject.RoleArn = aws.String(v)
}
Expand Down Expand Up @@ -1534,6 +1544,10 @@ func flattenIotRepublishAction(apiObject *iot.RepublishAction) []interface{} {

tfMap := make(map[string]interface{})

if v := apiObject.Qos; v != nil {
tfMap["qos"] = aws.Int64Value(v)
}

if v := apiObject.RoleArn; v != nil {
tfMap["role_arn"] = aws.StringValue(v)
}
Expand Down
42 changes: 42 additions & 0 deletions aws/resource_aws_iot_topic_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,30 @@ func TestAccAWSIoTTopicRule_republish(t *testing.T) {
})
}

func TestAccAWSIoTTopicRule_republish_with_qos(t *testing.T) {
rName := acctest.RandString(5)
resourceName := "aws_iot_topic_rule.rule"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSIoTTopicRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSIoTTopicRule_republish_with_qos(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSIoTTopicRuleExists("aws_iot_topic_rule.rule"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAWSIoTTopicRule_s3(t *testing.T) {
rName := acctest.RandString(5)
resourceName := "aws_iot_topic_rule.rule"
Expand Down Expand Up @@ -766,6 +790,24 @@ resource "aws_iot_topic_rule" "rule" {
`, rName)
}

func testAccAWSIoTTopicRule_republish_with_qos(rName string) string {
return fmt.Sprintf(testAccAWSIoTTopicRuleRole+`
resource "aws_iot_topic_rule" "rule" {
name = "test_rule_%[1]s"
description = "Example rule"
enabled = true
sql = "SELECT * FROM 'topic/test'"
sql_version = "2015-10-08"
republish {
role_arn = "${aws_iam_role.iot_role.arn}"
topic = "mytopic"
qos = 1
}
}
`, rName)
}

func testAccAWSIoTTopicRule_s3(rName string) string {
return fmt.Sprintf(testAccAWSIoTTopicRuleRole+`
resource "aws_iot_topic_rule" "rule" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/iot_topic_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ The `republish` object takes the following arguments:

* `role_arn` - (Required) The ARN of the IAM role that grants access.
* `topic` - (Required) The name of the MQTT topic the message should be republished to.
* `qos` - (Optional) The Quality of Service (QoS) level to use when republishing messages. Valid values are 0 or 1. The default value is 0.

The `s3` object takes the following arguments:

Expand Down

0 comments on commit 9b95b2e

Please sign in to comment.