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

go panic while configure existing launch_template #24009

Closed
jkroepke opened this issue Apr 3, 2022 · 8 comments · Fixed by #30539
Closed

go panic while configure existing launch_template #24009

jkroepke opened this issue Apr 3, 2022 · 8 comments · Fixed by #30539
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@jkroepke
Copy link

jkroepke commented Apr 3, 2022

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

Affected Resource(s)

  • aws_launch_template

Terraform Configuration Files

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

data "aws_ami" "flatcar" {
  most_recent = true
  owners      = ["aws-marketplace"]

  filter {
    name   = "architecture"
    values = ["x86_64"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  filter {
    name   = "name"
    values = ["Flatcar-alpha-*"]
  }
}

resource "aws_launch_template" "this" {
  name                   = "jkr-k8s-controller-asg-controller-eu-central-1a"
  update_default_version = true

  block_device_mappings {
    device_name = "/dev/sda1"

    ebs {
      volume_size = 20
      volume_type = "gp3"
    }
  }

  credit_specification {
    cpu_credits = "standard"
  }

  disable_api_termination = false
  ebs_optimized           = true

  image_id                             = data.aws_ami.flatcar.id

  instance_market_options {
    market_type = "spot"
    spot_options {

    }
  }

  instance_type = "t2.micro"
  key_name      = "jkr"

  metadata_options {
    http_endpoint               = "enabled"
    http_tokens                 = "optional"
    http_put_response_hop_limit = 1
  }

  network_interfaces {
    associate_public_ip_address = true
    security_groups             = [var.vpc_security_group_id]
  }

  private_dns_name_options {
    hostname_type                        = "resource-name"
    enable_resource_name_dns_a_record    = true
    enable_resource_name_dns_aaaa_record = true
  }

  user_data              = ""

  depends_on = []
}

Debug Output

Panic Output

Stack trace from the terraform-provider-aws_v4.8.0_x5 plugin:

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

goroutine 45 [running]:
github.com/hashicorp/terraform-provider-aws/internal/service/ec2.expandLaunchTemplateInstanceMarketOptionsRequest(0xc001b1d4d0)
	github.com/hashicorp/terraform-provider-aws/internal/service/ec2/launch_template.go:1292 +0x18a
github.com/hashicorp/terraform-provider-aws/internal/service/ec2.expandRequestLaunchTemplateData(0x9775d4f)
	github.com/hashicorp/terraform-provider-aws/internal/service/ec2/launch_template.go:958 +0xfd7
github.com/hashicorp/terraform-provider-aws/internal/service/ec2.resourceLaunchTemplateUpdate(0xc001071680, {0x84487e0, 0xc000217500})
	github.com/hashicorp/terraform-provider-aws/internal/service/ec2/launch_template.go:815 +0x145
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xa748280, {0xa748280, 0xc0028aff20}, 0xd, {0x84487e0, 0xc000217500})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:364 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000d9f500, {0xa748280, 0xc0028aff20}, 0xc0018acb60, 0xc001071400, {0x84487e0, 0xc000217500})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:482 +0x785
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000132a50, {0xa7481d8, 0xc00185e780}, 0xc001c6e0f0)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1021 +0xdaa
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc00172a6e0, {0xa748280, 0xc0028af590}, 0xc002595c00)
	github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:812 +0x56b
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x9511f20, 0xc00172a6e0}, {0xa748280, 0xc0028af590}, 0xc0015eaae0, 0x0)
	github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00029efc0, {0xa842ba0, 0xc000fdb380}, 0xc001874900, 0xc001919920, 0xfeab3a0, 0x0)
	google.golang.org/[email protected]/server.go:1282 +0xccf
google.golang.org/grpc.(*Server).handleStream(0xc00029efc0, {0xa842ba0, 0xc000fdb380}, 0xc001874900, 0x0)
	google.golang.org/[email protected]/server.go:1619 +0xa2a
google.golang.org/grpc.(*Server).serveStreams.func1.2()
	google.golang.org/[email protected]/server.go:921 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
	google.golang.org/[email protected]/server.go:919 +0x294

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

2022-04-03T20:24:43.736+0200 [DEBUG] provider: plugin exited

Expected Behavior

  • Terraform is able to reconfigure launch template

Actual Behavior

  • go panic from terraform provider

Steps to Reproduce

  1. terraform apply

Important Factoids

References

Panic maybe introduced in

since, go panic does not happens on provider version 4.5.0, which not include the PR.

@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/ec2 Issues and PRs that pertain to the ec2 service. labels Apr 3, 2022
@ewbankkit ewbankkit removed the needs-triage Waiting for first response or review from a maintainer. label Apr 3, 2022
@ewbankkit
Copy link
Contributor

ewbankkit commented Apr 3, 2022

v4.8.0

if v, ok := tfMap["spot_options"].([]interface{}); ok && len(v) > 0 {
apiObject.SpotOptions = expandLaunchTemplateSpotMarketOptionsRequest(v[0].(map[string]interface{}))
}

v4.5.0

if v, ok := imo["spot_options"]; ok {
vL := v.([]interface{})
for _, v := range vL {
so, ok := v.(map[string]interface{})
if !ok {
continue
}

There was an explicit check for map[string]interface{}.

@ewbankkit
Copy link
Contributor

@jkroepke Thanks for reporting this issue.
As a workaround, removing

    spot_options {

    }

should prevent the crash.

@ewbankkit
Copy link
Contributor

Related: #23766 (comment).

@sdlarsen
Copy link

sdlarsen commented Apr 8, 2022

@ewbankkit That workaround is not useful if you have conditional spot options (as we have). It's still present in v4.9.0_x5:

Stack trace from the terraform-provider-aws_v4.9.0_x5 plugin:

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

goroutine 148 [running]:
github.com/hashicorp/terraform-provider-aws/internal/service/ec2.expandLaunchTemplateInstanceMarketOptionsRequest(0xc000c239e0)
	github.com/hashicorp/terraform-provider-aws/internal/service/ec2/launch_template.go:1292 +0x18a
github.com/hashicorp/terraform-provider-aws/internal/service/ec2.expandRequestLaunchTemplateData(0x8c6f989)
	github.com/hashicorp/terraform-provider-aws/internal/service/ec2/launch_template.go:958 +0xfd7
github.com/hashicorp/terraform-provider-aws/internal/service/ec2.resourceLaunchTemplateUpdate(0xc00276ed00, {0x7921500, 0xc000744000})
	github.com/hashicorp/terraform-provider-aws/internal/service/ec2/launch_template.go:815 +0x145
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0x9c63900, {0x9c63900, 0xc002758ae0}, 0xd, {0x7921500, 0xc000744000})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:730 +0x178
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc001051880, {0x9c63900, 0xc002758ae0}, 0xc00277d860, 0xc00276eb80, {0x7921500, 0xc000744000})
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:848 +0x785
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0006a00f0, {0x9c63858, 0xc0024bd940}, 0xc002064dc0)
	github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:1021 +0xe3c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc000ed3360, {0x9c63900, 0xc002758420}, 0xc002485810)
	github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:812 +0x56b
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x8a08420, 0xc000ed3360}, {0x9c63900, 0xc002758420}, 0xc0018b01e0, 0x0)
	github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0001c2fc0, {0x9d60020, 0xc000751380}, 0xc0027547e0, 0xc0017a3f20, 0xf45b400, 0x0)
	google.golang.org/[email protected]/server.go:1282 +0xccf
google.golang.org/grpc.(*Server).handleStream(0xc0001c2fc0, {0x9d60020, 0xc000751380}, 0xc0027547e0, 0x0)
	google.golang.org/[email protected]/server.go:1619 +0xa2a
google.golang.org/grpc.(*Server).serveStreams.func1.2()
	google.golang.org/[email protected]/server.go:921 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
	google.golang.org/[email protected]/server.go:919 +0x294

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

Which makes it impossible to apply anything to a running cluster (which is pretty bad...)

@sdlarsen
Copy link

sdlarsen commented May 5, 2022

Any progress on this?

@sdlarsen
Copy link

sdlarsen commented May 6, 2022

I worked around it using dynamic, should anyone end up here...

  # Spot price if used
  dynamic "instance_market_options" {
    for_each = var.spot_price != "" ? [1] : []
    content {
      market_type = "spot"
      spot_options {
        max_price          = var.spot_price
        spot_instance_type = "one-time"
      }
    }
  }

@github-actions
Copy link

This functionality has been released in v4.63.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

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 May 15, 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/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
3 participants