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_cloudwatch_event_target panics if sqs_target block is empty #19945

Closed
packrat386 opened this issue Jun 24, 2021 · 4 comments · Fixed by #19946
Closed

aws_cloudwatch_event_target panics if sqs_target block is empty #19945

packrat386 opened this issue Jun 24, 2021 · 4 comments · Fixed by #19946
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic.
Milestone

Comments

@packrat386
Copy link
Contributor

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 other comments that do not add relevant new information or questions, 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 CLI and Terraform AWS Provider Version

 [fg-386] tf_sqs_issue_repro > terraform version
Terraform v0.15.5
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v3.46.0

Your version of Terraform is out of date! The latest version
is 1.0.0. You can update by downloading from https://www.terraform.io/downloads.html

Affected Resource(s)

  • aws_cloudwatch_event_target

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

terraform {
  required_version = ">= 0.14"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 3.25"
    }
  }
}

locals {
  message_group_id = null
}

terraform {
  backend "local" {}
}

provider "aws" {
  alias  = "va"
  region = "us-east-1"
}

resource "aws_sqs_queue" "test_queue" {
  provider = aws.va
  name     = "terraform_test_queue"
}

resource "aws_cloudwatch_event_rule" "test_rule" {
  provider            = aws.va
  name                = "test_rule"
  description         = "Send a message at a set interval to kick off a job."
  schedule_expression = "cron(0 12 * * ? *)"
}

resource "aws_cloudwatch_event_target" "test_rule_target" {
  provider = aws.va
  rule     = aws_cloudwatch_event_rule.test_rule.name
  arn      = aws_sqs_queue.test_queue.arn

  input = jsonencode({
    foo = "bar"
  })

  sqs_target {
    message_group_id = local.message_group_id
  }
}

Debug Output

https://gist.github.com/packrat386/b88da9175a551d4ab5968c8c87387887

Panic Output

│ Error: Plugin did not respond
│
│   with aws_cloudwatch_event_target.test_rule_target,
│   on main.tf line 36, in resource "aws_cloudwatch_event_target" "test_rule_target":
│   36: resource "aws_cloudwatch_event_target" "test_rule_target" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-aws_v3.46.0_x5 plugin:

panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 195 [running]:
github.com/terraform-providers/terraform-provider-aws/aws.expandAwsCloudWatchEventTargetSqsParameters(0xc001692900, 0x1, 0x1, 0x593e8c0)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-aws/aws/resource_aws_cloudwatch_event_target.go:673 +0x18b
github.com/terraform-providers/terraform-provider-aws/aws.buildPutTargetInputStruct(0xc0013fd500, 0x7128d4f)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-aws/aws/resource_aws_cloudwatch_event_target.go:518 +0x507
github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsCloudWatchEventTargetCreate(0xc0013fd500, 0x632bc80, 0xc0012ac000, 0x0, 0xffffffffffffffff)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/hashicorp/terraform-provider-aws/aws/resource_aws_cloudwatch_event_target.go:334 +0x18f
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc0007a3420, 0x7c74908, 0xc00150d5c0, 0xc0013fd500, 0x632bc80, 0xc0012ac000, 0x0, 0x0, 0x0)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:318 +0x1ee
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0007a3420, 0x7c74908, 0xc00150d5c0, 0xc000b1fc70, 0xc001027660, 0x632bc80, 0xc0012ac000, 0x0, 0x0, 0x0, ...)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:456 +0x67b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000306780, 0x7c74908, 0xc00150d5c0, 0xc00153e7d0, 0xc00150d5c0, 0x6f07b20, 0xc001563600)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:955 +0x8ef
github.com/hashicorp/terraform-plugin-go/tfprotov5/server.(*server).ApplyResourceChange(0xc0016bcee0, 0x7c749b0, 0xc00150d5c0, 0xc000b1fb20, 0xc0016bcee0, 0xc0015636e0, 0xc00105fba0)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/server/server.go:332 +0xb5
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0x6f07b20, 0xc0016bcee0, 0x7c749b0, 0xc0015636e0, 0xc0015469c0, 0x0, 0x7c749b0, 0xc0015636e0, 0xc001dcdb00, 0x2c6)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x214
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0005b56c0, 0x7c963b8, 0xc001b0a180, 0xc001393a00, 0xc0011c3050, 0xb402a60, 0x0, 0x0, 0x0)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/[email protected]/server.go:1194 +0x52b
google.golang.org/grpc.(*Server).handleStream(0xc0005b56c0, 0x7c963b8, 0xc001b0a180, 0xc001393a00, 0x0)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/[email protected]/server.go:1517 +0xd0c
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc000a68cd0, 0xc0005b56c0, 0x7c963b8, 0xc001b0a180, 0xc001393a00)
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/[email protected]/server.go:859 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
        /opt/teamcity-agent/work/5d79fe75d4460a2f/pkg/mod/google.golang.org/[email protected]/server.go:857 +0x1fd

Error: The terraform-provider-aws_v3.46.0_x5 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.

Expected Behavior

This should not crash and add a cloudwatch event target to an SQS queue with no message_group_id.

Actual Behavior

It crashed

Steps to Reproduce

  1. terraform apply

https://github.com/packrat386/tf_sqs_issue_repro

Important Factoids

N/A


I'm aware that this is a rather silly bug, as one should avoid adding the block if one does not have a message_group_id, but the provider still ought to handle it gracefully.

@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/cloudwatchevents service/sqs Issues and PRs that pertain to the sqs service. labels Jun 24, 2021
@packrat386
Copy link
Contributor Author

I am drafting a PR that I think should resolve this.

@ewbankkit
Copy link
Contributor

Relevant code:

func expandAwsCloudWatchEventTargetSqsParameters(config []interface{}) *events.SqsParameters {
sqsParameters := &events.SqsParameters{}
for _, c := range config {
param := c.(map[string]interface{})
if v, ok := param["message_group_id"].(string); ok && v != "" {
sqsParameters.MessageGroupId = aws.String(v)
}
}
return sqsParameters
}

@ewbankkit ewbankkit removed needs-triage Waiting for first response or review from a maintainer. service/sqs Issues and PRs that pertain to the sqs service. labels Jun 24, 2021
@github-actions github-actions bot added this to the v3.48.0 milestone Jun 28, 2021
@github-actions
Copy link

github-actions bot commented Jul 8, 2021

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

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

github-actions bot commented Aug 8, 2021

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2021
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants