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_iot_topic_rule: Add support for 'operation' in DynamoDB action #12714

Merged
merged 1 commit into from
May 12, 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
8 changes: 8 additions & 0 deletions aws/resource_aws_iot_topic_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ func resourceAwsIotTopicRule() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"operation": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateIoTRuleDynamoDBOperation,
},
},
},
},
Expand Down Expand Up @@ -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++
}
Expand Down
5 changes: 3 additions & 2 deletions aws/resource_aws_iot_topic_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
12 changes: 12 additions & 0 deletions aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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 @@ -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.

Expand Down