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

[Bug]: Error: The terraform-provider-aws_v4.67.0_x5 plugin crashed! #31443

Closed
DKlug1337 opened this issue May 17, 2023 · 6 comments · Fixed by #31683
Closed

[Bug]: Error: The terraform-provider-aws_v4.67.0_x5 plugin crashed! #31443

DKlug1337 opened this issue May 17, 2023 · 6 comments · Fixed by #31683
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/ecs Issues and PRs that pertain to the ecs service.

Comments

@DKlug1337
Copy link

Terraform Core Version

Terraform v1.4.2

AWS Provider Version

aws_v4.67.0_x5

Affected Resource(s)

aws_ecs_service

Expected Behavior

it should be add this block:

alarms {
    enable   = true
    rollback = true
    alarm_names = [
      aws_cloudwatch_metric_alarm.example.alarm_name
    ]
  }

Actual Behavior

Error: The terraform-provider-aws_v4.67.0_x5 plugin crashed!

Relevant Error/Panic Output Snippet

╷
│ Error: Plugin did not respond
│ 
│   with module.ecs.aws_ecs_service.default,
│   on .terraform/modules/ecs/ecs/resources.tf line 169, in resource "aws_ecs_service" "default":
│  169: resource "aws_ecs_service" "default" {
│ 
│ 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_v4.67.0_x5 plugin:

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

goroutine 435 [running]:
github.com/hashicorp/terraform-provider-aws/internal/service/ecs.resourceServiceUpdate({0xf0a19c0?, 0xc00541dbf0}, 0xc006410280, {0xdb8cd20?, 0xc0003a8c00})
        github.com/hashicorp/terraform-provider-aws/internal/service/ecs/service.go:857 +0xaa9
github.com/hashicorp/terraform-provider-aws/internal/provider.interceptedHandler[...].func1(0x0?, {0xdb8cd20?, 0xc0003a8c00?})
        github.com/hashicorp/terraform-provider-aws/internal/provider/intercept.go:95 +0x175
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xf0a19c0?, {0xf0a19c0?, 0xc005304fc0?}, 0xd?, {0xdb8cd20?, 0xc0003a8c00?})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:736 +0x87
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000ff88c0, {0xf0a19c0, 0xc005304fc0}, 0xc0031c3a00, 0xc006b17f80, {0xdb8cd20, 0xc0003a8c00})
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:847 +0x83a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00266f620, {0xf0a19c0?, 0xc005304ea0?}, 0xc0059532c0)
        github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1021 +0xe8d
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.muxServer.ApplyResourceChange({0xc004011350, 0xc0040113b0, {0xc0048686a0, 0x2, 0x2}, {0x0, 0x0, 0x0}, {0x0, 0x0, ...}, ...}, ...)
        github.com/hashicorp/[email protected]/tf5muxserver/mux_server_ApplyResourceChange.go:27 +0x102
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc00258e8c0, {0xf0a19c0?, 0xc005253b60?}, 0xc0032d4850)
        github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:818 +0x574
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0xd877e80?, 0xc00258e8c0}, {0xf0a19c0, 0xc005253b60}, 0xc0032d47e0, 0x0)
        github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:419 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0041c23c0, {0xf0b21e0, 0xc00595c680}, 0xc0041e46c0, 0xc004c21830, 0x15cfa500, 0x0)
        google.golang.org/[email protected]/server.go:1345 +0xdf0
google.golang.org/grpc.(*Server).handleStream(0xc0041c23c0, {0xf0b21e0, 0xc00595c680}, 0xc0041e46c0, 0x0)
        google.golang.org/[email protected]/server.go:1722 +0xa2f
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/[email protected]/server.go:966 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/[email protected]/server.go:964 +0x28a

Error: The terraform-provider-aws_v4.67.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.

Terraform Configuration Files

resource "aws_ecs_service" "default" {
  name                               = var.name
  cluster                            = data.aws_ecs_cluster.default.id
  launch_type                        = "FARGATE"
  task_definition                    = aws_ecs_task_definition.default.arn
  desired_count                      =  1
  deployment_minimum_healthy_percent = 50
  deployment_maximum_percent         = 200
  scheduling_strategy                = "REPLICA"
  propagate_tags                     = "SERVICE"
  lifecycle {
    ignore_changes = [
    desired_count]
  }
  network_configuration {
    subnets          = data.aws_subnets.private.ids
    security_groups  = [aws_security_group.ecs_tasks.id, data.aws_security_group.default.id]
    assign_public_ip = false
  }
  dynamic "alarms" {
    for_each = var.alarm_names == null ? [] : [true]
    content {
      enable      = true
      rollback    = true
      alarm_names = var.alarm_names
    }
  }
}

Steps to Reproduce

do a terraform apply

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

No

@DKlug1337 DKlug1337 added bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. labels May 17, 2023
@github-actions github-actions bot added crash Results from or addresses a Terraform crash or kernel panic. service/ecs Issues and PRs that pertain to the ecs service. labels May 17, 2023
@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@fennnec
Copy link

fennnec commented May 17, 2023

can reproduce on
Terraform v1.4.6
on darwin_arm64

  • provider registry.terraform.io/hashicorp/aws v4.67.0

@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label May 17, 2023
@mattburgess
Copy link
Collaborator

I wasn't able to reproduce the crash, but I did observe some issues running an apply. Probably best described using the plan output. First, the minimal reproducer I tried:

terraform {
  required_version = ">= 1.4.6"
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "4.67.0"
    }
  }
}

resource "aws_ecs_cluster" "test" {
  name = "test"
}

resource "aws_ecs_task_definition" "test" {
  family = "test"

  container_definitions = <<DEFINITION
[
  {
    "cpu": 128,
    "essential": true,
    "image": "mongo:latest",
    "memory": 128,
    "name": "mongodb"
  }
]
DEFINITION
}

variable "alarm_names" {
  type    = list(string)
  default = []
}

resource "aws_ecs_service" "test" {
  name            = "test"
  cluster         = aws_ecs_cluster.test.id
  task_definition = aws_ecs_task_definition.test.arn
  desired_count   = 1

  dynamic "alarms" {
    for_each = var.alarm_names == null ? [] : [true]
    content {
      enable      = true
      rollback    = true
      alarm_names = var.alarm_names
    }
  }
}

This produces the following plan:

$ terraform plan
...
 # aws_ecs_service.test will be created
  + resource "aws_ecs_service" "test" {
      + cluster                            = (known after apply)
      + deployment_maximum_percent         = 200
      + deployment_minimum_healthy_percent = 100
      + desired_count                      = 1
      + enable_ecs_managed_tags            = false
      + enable_execute_command             = false
      + iam_role                           = (known after apply)
      + id                                 = (known after apply)
      + launch_type                        = (known after apply)
      + name                               = "test"
      + platform_version                   = (known after apply)
      + scheduling_strategy                = "REPLICA"
      + tags_all                           = (known after apply)
      + task_definition                    = (known after apply)
      + triggers                           = (known after apply)
      + wait_for_steady_state              = false

      + alarms {
          + enable   = true
          + rollback = true
        }
    }

Note the weird looking alarms block that has no alarm_names attribute? Sure enough, trying to apply this results in:

$ terraform apply
...
aws_ecs_service.test: Creating...
╷
│ Error: creating ECS Service (test): InvalidParameter: 1 validation error(s) found.
│ - missing required field, CreateServiceInput.DeploymentConfiguration.Alarms.AlarmNames.
│ 
│ 
│   with aws_ecs_service.test,
│   on main.tf line 36, in resource "aws_ecs_service" "test":
│   36: resource "aws_ecs_service" "test" {

If we change the for_each expression to correctly guard for an empty set, we get what I'd expect to see in the plan:

resource "aws_ecs_service" "test" {
  name            = "test"
  cluster         = aws_ecs_cluster.test.id
  task_definition = aws_ecs_task_definition.test.arn
  desired_count   = 1

  dynamic "alarms" {
    for_each = var.alarm_names == null || length(var.alarm_names) == 0 ? [] : [true]
    content {
      enable      = true
      rollback    = true
      alarm_names = var.alarm_names
    }
  }
}
$ terraform plan
...
  # aws_ecs_service.test will be created
  + resource "aws_ecs_service" "test" {
      + cluster                            = (known after apply)
      + deployment_maximum_percent         = 200
      + deployment_minimum_healthy_percent = 100
      + desired_count                      = 1
      + enable_ecs_managed_tags            = false
      + enable_execute_command             = false
      + iam_role                           = (known after apply)
      + id                                 = (known after apply)
      + launch_type                        = (known after apply)
      + name                               = "test"
      + platform_version                   = (known after apply)
      + scheduling_strategy                = "REPLICA"
      + tags_all                           = (known after apply)
      + task_definition                    = (known after apply)
      + triggers                           = (known after apply)
      + wait_for_steady_state              = false
    }

And the resulting apply works just fine.

If you're able to adjust the minimal reproducer above so that it crashes for you, that'd be useful please. Alternatively, applying that fix for the for_each expression might act as a workaround.

@eternaltyro
Copy link
Contributor

This happens to me as well. Even in versions 5.0.0 and 5.0.1. Weirdly, the plugin crashes only when I apply a diff. If I destroy first before apply, then it works fine.

@ewbankkit
Copy link
Contributor

ewbankkit commented May 31, 2023

if d.HasChange("alarms") {
if v, ok := d.GetOk("alarms"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.DeploymentConfiguration.Alarms = expandAlarms(v.([]interface{})[0].(map[string]interface{}))
}
}

My guess is that we'll need to add:

if input.DeploymentConfiguration == nil {
	input.DeploymentConfiguration = &ecs.DeploymentConfiguration{}
}

@github-actions
Copy link

github-actions bot commented Jul 1, 2023

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 Jul 1, 2023
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/ecs Issues and PRs that pertain to the ecs service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants