From 6944aa589a22abd065ef352ef60369d749444804 Mon Sep 17 00:00:00 2001 From: Kristopher Linquist Date: Tue, 7 Apr 2020 12:17:58 -0700 Subject: [PATCH] IoT Rule DyanmoDB operation action --- aws/resource_aws_iot_topic_rule.go | 8 ++++++++ aws/resource_aws_iot_topic_rule_test.go | 5 +++-- aws/structure.go | 4 ++++ aws/validators.go | 12 ++++++++++++ website/docs/r/iot_topic_rule.html.markdown | 1 + 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/aws/resource_aws_iot_topic_rule.go b/aws/resource_aws_iot_topic_rule.go index fdfc27bf4b6..e3ffc968ef5 100644 --- a/aws/resource_aws_iot_topic_rule.go +++ b/aws/resource_aws_iot_topic_rule.go @@ -144,6 +144,11 @@ func resourceAwsIotTopicRule() *schema.Resource { Type: schema.TypeString, Required: true, }, + "operation": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validateIoTRuleDynamoDBOperation, + }, }, }, }, @@ -402,6 +407,9 @@ func createTopicRulePayload(d *schema.ResourceData) *iot.TopicRulePayload { if v, ok := raw["payload_field"].(string); ok && v != "" { act.DynamoDB.PayloadField = aws.String(v) } + if v, ok := raw["operation"].(string); ok && v != "" { + act.DynamoDB.Operation = aws.String(v) + } actions[i] = act i++ } diff --git a/aws/resource_aws_iot_topic_rule_test.go b/aws/resource_aws_iot_topic_rule_test.go index 4ebbed7c95b..75025f75277 100644 --- a/aws/resource_aws_iot_topic_rule_test.go +++ b/aws/resource_aws_iot_topic_rule_test.go @@ -481,7 +481,7 @@ resource "aws_iot_topic_rule" "rule" { hash_key_value = "hash_key_value" payload_field = "payload_field" role_arn = "${aws_iam_role.iot_role.arn}" - table_name = "table_name" + table_name = "table_name" } } `, rName) @@ -504,7 +504,8 @@ resource "aws_iot_topic_rule" "rule" { range_key_value = "range_key_value" range_key_type = "STRING" role_arn = "${aws_iam_role.iot_role.arn}" - table_name = "table_name" + table_name = "table_name" + operation = "INSERT" } } `, rName) diff --git a/aws/structure.go b/aws/structure.go index 7f0dc4fb2f1..f48c4cbae0f 100644 --- a/aws/structure.go +++ b/aws/structure.go @@ -2809,6 +2809,10 @@ func flattenIoTRuleDynamoDbActions(actions []*iot.Action) []map[string]interface m["range_key_value"] = aws.StringValue(v.RangeKeyValue) } + if v.Operation != nil { + m["operation"] = aws.StringValue(v.Operation) + } + items = append(items, m) } } diff --git a/aws/validators.go b/aws/validators.go index 5b1b685d960..b7a439fd67c 100644 --- a/aws/validators.go +++ b/aws/validators.go @@ -754,6 +754,18 @@ func validateHTTPMethod() schema.SchemaValidateFunc { }, false) } +func validateIoTRuleDynamoDBOperation(v interface{}, k string) (ws []string, errors []error) { + value := v.(string) + pattern := `^INSERT|UPDATE|DELETE$` + if !regexp.MustCompile(pattern).MatchString(value) { + errors = append(errors, fmt.Errorf( + "%q isn't a valid operation. Use INSERT, UPDATE, or DELETE", + k)) + } + + return +} + func validateLogMetricFilterName(v interface{}, k string) (ws []string, errors []error) { value := v.(string) diff --git a/website/docs/r/iot_topic_rule.html.markdown b/website/docs/r/iot_topic_rule.html.markdown index 0fd4f6ae5e7..d9d13bac5ae 100644 --- a/website/docs/r/iot_topic_rule.html.markdown +++ b/website/docs/r/iot_topic_rule.html.markdown @@ -102,6 +102,7 @@ The `dynamodb` object takes the following arguments: * `range_key_field` - (Optional) The range key name. * `range_key_type` - (Optional) The range key type. Valid values are "STRING" or "NUMBER". * `range_key_value` - (Optional) The range key value. +* `operation` - (Optional) The operation. Valid values are "INSERT", "UPDATE", or "DELETE". * `role_arn` - (Required) The ARN of the IAM role that grants access to the DynamoDB table. * `table_name` - (Required) The name of the DynamoDB table.