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

aws_iot_topic_rule fails to parse SQS in response #7334

Closed
rraub opened this issue Jan 25, 2019 · 7 comments · Fixed by #7337
Closed

aws_iot_topic_rule fails to parse SQS in response #7334

rraub opened this issue Jan 25, 2019 · 7 comments · Fixed by #7337
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/iot Issues and PRs that pertain to the iot service.
Milestone

Comments

@rraub
Copy link

rraub commented Jan 25, 2019

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

  • Terraform v0.11.11
  • provider.aws v1.56.0

Affected Resource(s)

  • resource "aws_iot_topic_rule"

Terraform Configuration Files

resource "aws_iot_topic_rule" "hub_messages" {
  name = "hub_messages_${var.environment_name}"
  sql = "SELECT *, topic(1) as serial_number FROM '+/message'"
  sql_version = "2016-03-23"
  sqs {
    queue_url = "${aws_sqs_queue.my_queue.id}"
    role_arn = "${aws_iam_role.my_role.arn}"
    use_base64 = true
  }
}

Debug Output

https://gist.github.com/rraub/fb1d48916ca5606e6048e924461ba641

Panic Output

Error: Error refreshing state: 1 error(s) occurred:

* module.iot.aws_iot_topic_rule.rule_name: 1 error(s) occurred:

* module.iot.aws_iot_topic_rule.rule_name: aws_iot_topic_rule.rule_name: unexpected EOF

Expected Behavior

An IoT Topic Rule with an SQS action can be updated from Terraform.

Actual Behavior

Terraform AWS provider fails to parse the AWS response in iot/GetTopicRule

Steps to Reproduce

  1. Create a terraform aws_iot_topic_rule resource with an SQS action that has a base64 encoding set to false or null.
  2. terraform apply
  3. Change the name of the rule in the terraform configuration
  4. terraform apply

Important Factoids

The SQS is also a terraform managed resource, but I don't think that matters.

References

@bflad bflad added bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/iot Issues and PRs that pertain to the iot service. labels Jan 25, 2019
@bflad
Copy link
Contributor

bflad commented Jan 25, 2019

It looks like the code is unsafely assuming UseBase64 is always returned in the API response.

Relevant portion from logs:

2019-01-25T10:36:41.021-0700 [DEBUG] plugin.terraform-provider-aws_v1.56.0_x4: 2019/01/25 10:36:41 [DEBUG] [aws-sdk-go] {"rule":{"actions":[{"cloudwatchAlarm":null,"cloudwatchLogs":null,"cloudwatchMetric":null,"dynamoDB":null,"dynamoDBv2":null,"elasticsearch":null,"firehose":null,"iotAnalytics":null,"iotEvents":null,"kinesis":null,"lambda":null,"republish":null,"s3":null,"salesforce":null,"sns":null,"sqs":{"queueUrl":"https://sqs.us-east-1.amazonaws.com/000000000000/queue_name","roleArn":"arn:aws:iam::000000000000:role/service-role/iot-to-sqs","useBase64":null},"stepFunctions":null}],"awsIotSqlVersion":"2016-03-23","createdAt":null,"description":"test","errorAction":null,"ruleDisabled":false,"ruleName":"rule_name","sql":"SELECT *, topic(1) as serial_number FROM '+/message'"},"ruleArn":"arn:aws:iot:us-east-1:000000000000:rule/rule_name"}
2019-01-25T10:36:41.024-0700 [DEBUG] plugin.terraform-provider-aws_v1.56.0_x4: panic: runtime error: invalid memory address or nil pointer dereference
2019-01-25T10:36:41.024-0700 [DEBUG] plugin.terraform-provider-aws_v1.56.0_x4: [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x3379dba]
2019-01-25T10:36:41.024-0700 [DEBUG] plugin.terraform-provider-aws_v1.56.0_x4: 
2019-01-25T10:36:41.024-0700 [DEBUG] plugin.terraform-provider-aws_v1.56.0_x4: goroutine 183 [running]:
2019-01-25T10:36:41.024-0700 [DEBUG] plugin.terraform-provider-aws_v1.56.0_x4: github.com/terraform-providers/terraform-provider-aws/aws.flattenIoTRuleSqsActions(0xc00037a000, 0x1, 0x1, 0x37124c0, 0xc0008b0a60, 0x0)
2019-01-25T10:36:41.024-0700 [DEBUG] plugin.terraform-provider-aws_v1.56.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/aws/structure.go:2996 +0x16a
2019-01-25T10:36:41.024-0700 [DEBUG] plugin.terraform-provider-aws_v1.56.0_x4: github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsIotTopicRuleRead(0xc0003a7730, 0x3c9e660, 0xc0001d4380, 0xc0003a7730, 0x0)
2019-01-25T10:36:41.024-0700 [DEBUG] plugin.terraform-provider-aws_v1.56.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_iot_topic_rule.go:580 +0x9b7

@rraub
Copy link
Author

rraub commented Jan 25, 2019

@bflad Agreed! The aws docs aren't explicit with whats nullable. I'll update the ticket description to include a false or null value for the base64 encoding.

@bflad bflad added this to the v1.57.0 milestone Jan 25, 2019
bflad added a commit that referenced this issue Jan 25, 2019
… attribute in API response

Reference: #7334

Output from acceptance testing:

```
--- PASS: TestAccAWSIoTTopicRule_lambda (8.86s)
--- PASS: TestAccAWSIoTTopicRule_basic (9.29s)
--- PASS: TestAccAWSIoTTopicRule_cloudwatchalarm (9.29s)
--- PASS: TestAccAWSIoTTopicRule_s3 (9.31s)
--- PASS: TestAccAWSIoTTopicRule_cloudwatchmetric (9.35s)
--- PASS: TestAccAWSIoTTopicRule_sns (9.35s)
--- PASS: TestAccAWSIoTTopicRule_firehose (9.39s)
--- PASS: TestAccAWSIoTTopicRule_republish (9.41s)
--- PASS: TestAccAWSIoTTopicRule_sqs (9.43s)
--- PASS: TestAccAWSIoTTopicRule_kinesis (9.43s)
--- PASS: TestAccAWSIoTTopicRule_importbasic (9.96s)
--- PASS: TestAccAWSIoTTopicRule_elasticsearch (13.07s)
--- PASS: TestAccAWSIoTTopicRule_firehose_separator (13.55s)
```
@bflad
Copy link
Contributor

bflad commented Jan 25, 2019

Fix submitted. 😄 #7337

@bflad
Copy link
Contributor

bflad commented Jan 25, 2019

The fix for this has been merged and will release with version 1.57.0 of the Terraform AWS provider, likely later today. 👍

@rraub
Copy link
Author

rraub commented Jan 25, 2019

Thanks @bflad !! 🎉

@bflad
Copy link
Contributor

bflad commented Jan 26, 2019

This has been released in version 1.57.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 1, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/iot Issues and PRs that pertain to the iot service.
Projects
None yet
2 participants