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

Add 'Seperator' property to AWS IoT Firehose Rule #5734

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
11 changes: 10 additions & 1 deletion aws/resource_aws_iot_topic_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ func resourceAwsIotTopicRule() *schema.Resource {
Required: true,
ValidateFunc: validateArn,
},
"separator": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateIoTTopicRuleFirehoseSeparator,
},
},
},
},
Expand Down Expand Up @@ -413,12 +418,16 @@ func createTopicRulePayload(d *schema.ResourceData) *iot.TopicRulePayload {

for _, a := range firehoseActions {
raw := a.(map[string]interface{})
actions[i] = &iot.Action{
act := &iot.Action{
Firehose: &iot.FirehoseAction{
DeliveryStreamName: aws.String(raw["delivery_stream_name"].(string)),
RoleArn: aws.String(raw["role_arn"].(string)),
},
}
if v, ok := raw["separator"].(string); ok && v != "" {
act.Firehose.Separator = aws.String(raw["separator"].(string))
}
actions[i] = act
i++
}

Expand Down
1 change: 1 addition & 0 deletions aws/resource_aws_iot_topic_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ resource "aws_iot_topic_rule" "rule" {
firehose {
delivery_stream_name = "mystream"
role_arn = "${aws_iam_role.iot_role.arn}"
separator = "\n"
}
}
`, rName)
Expand Down
1 change: 1 addition & 0 deletions aws/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -2754,6 +2754,7 @@ func flattenIoTRuleFirehoseActions(actions []*iot.Action) []map[string]interface
if v != nil {
result["role_arn"] = *v.RoleArn
result["delivery_stream_name"] = *v.DeliveryStreamName
result["separator"] = *v.Separator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API will omit this value in the response if parameter is not provided in the configuration and cause a panic:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x2e9cb09]

goroutine 406 [running]:
github.com/terraform-providers/terraform-provider-aws/aws.flattenIoTRuleFirehoseActions(0xc0000c9058, 0x1, 0x1, 0x379df40, 0xc000669520, 0x0)
	/Users/bflad/go/src/github.com/terraform-providers/terraform-provider-aws/aws/structure.go:2815 +0x1e9

We should prefer to use the AWS SDK provided functions to dereference pointers instead, e.g. result["separator"] = aws.StringValue(v.Separator)


results = append(results, result)
}
Expand Down
13 changes: 13 additions & 0 deletions aws/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,19 @@ func validateIoTTopicRuleElasticSearchEndpoint(v interface{}, k string) (ws []st
return
}

func validateIoTTopicRuleFirehoseSeparator(v interface{}, s string) ([]string, []error) {
switch v.(string) {
case
",",
"\t",
"\n",
"\r\n":
return nil, nil
}

return nil, []error{fmt.Errorf("Separator must be one of ',' (comma), '\t' (tab) '\n' (newline) or '\r\n' (Windows newline)")}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When printing this error, it is returning the whitespace and not the intended characters:

aws_iot_topic_rule.rule: Separator must be one of ',' (comma), '	' (tab) '
        ' (newline) or '
        ' (Windows newline)

They need to be escaped appropriately. 👍

}

func validateCognitoRoleMappingsAmbiguousRoleResolutionAgainstType(v map[string]interface{}) (errors []error) {
t := v["type"].(string)
isRequired := t == cognitoidentity.RoleMappingTypeToken || t == cognitoidentity.RoleMappingTypeRules
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 @@ -115,6 +115,7 @@ The `firehose` object takes the following arguments:

* `delivery_stream_name` - (Required) The delivery stream name.
* `role_arn` - (Required) The IAM role ARN that grants access to the Amazon Kinesis Firehose stream.
* `separator` - (Optional) A character separator that is used to separate records written to the Firehose stream. Valid values are: '\n' (newline), '\t' (tab), '\r\n' (Windows newline), ',' (comma).

The `kinesis` object takes the following arguments:

Expand Down