hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.76k stars 9.11k forks source link

aws_launch_template: Empty block of capacity_reservation_target & elastic_gpu_specifications causing panic:interface conversion: interface {} is nil, not map[string]interface {} #10250

Closed falconh closed 4 years ago

falconh commented 5 years ago

Community Note

Terraform Version

Terraform v0.12.9
+ provider.aws v2.29.0
+ provider.null v2.1.2

Affected Resource(s)

Terraform Configuration Files

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key: https://keybase.io/hashicorp

resource "aws_launch_template" "default" {
  count = var.enabled ? 1 : 0

  name_prefix = format("%s%s", lookup(module.common_labels.common_tags, "Name"), var.delimiter)

  description = lookup(module.common_labels.common_tags, lookup(module.common_labels.common_tag_keys.tag_keys, "usage_description"))

  dynamic "block_device_mappings" {
    for_each = var.block_device_mappings
    content {
        device_name    = lookup(block_device_mappings.value, "device_name", "/dev/xvda")

        dynamic "ebs" {
          for_each = lookup(block_device_mappings.value, "ebs", {})
          content {
              delete_on_termination = lookup(ebs.value, "delete_on_termination", true)
              encrypted = lookup(ebs.value, "encrypted", false)
              iops  = lookup(ebs.value, "iops", null)
              kms_key_id = lookup(ebs.value, "kms_key_id", null)
              snapshot_id = lookup(ebs.value, "snapshot_id", null)
              volume_size = lookup(ebs.value, "volume_size", 20)
              volume_type = lookup(ebs.value, "volume_type", "standard")
          }
        }
    }
  }

  capacity_reservation_specification {
    capacity_reservation_preference = var.capacity_reservation_preference

    capacity_reservation_target {
      capacity_reservation_id = var.capacity_reservation_id
    }
  }

  credit_specification {
    cpu_credits = var.cpu_credits
  }

  disable_api_termination              = var.disable_api_termination
  ebs_optimized                        = var.ebs_optimized

  elastic_gpu_specifications {
    type = var.elastic_gpu_type
  }

  elastic_inference_accelerator {
    type = var.elastic_inference_accelerator_type
  }

  placement {
    affinity = var.affinity
    availability_zone = var.autoscaling_enabled ? null : var.availability_zone
    group_name  = var.group_name
    host_id = var.dedicated_host_id
    tenancy = var.tenancy
  }

  image_id                             = var.image_id
  instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior
  instance_type                        = var.instance_type
  key_name                             = var.key_name
  user_data                            = var.user_data_base64

  iam_instance_profile {
    name = var.iam_instance_profile_name
  }

  monitoring {
    enabled = var.enable_monitoring
  }

  # https://github.com/terraform-providers/terraform-provider-aws/issues/4570
  network_interfaces {
    description                 = lookup(module.common_labels.common_tags, "Name")
    device_index                = 0
    associate_public_ip_address = var.associate_public_ip_address
    delete_on_termination       = true
    security_groups             = var.security_group_ids
  }

  tag_specifications {
    resource_type = "volume"
    tags          = local.full_tags
  }

  tag_specifications {
    resource_type = "instance"
    tags          = local.full_tags
  }

  tags = local.full_tags

  lifecycle {
    create_before_destroy = true
  }
}

Debug Output

panic: interface conversion: interface {} is nil, not map[string]interface {}
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: goroutine 106 [running]:
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: github.com/terraform-providers/terraform-provider-aws/aws.readCapacityReservationSpecificationFromConfig(0xc000b6c1b0, 0x4fcf002)
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_launch_template.go:1352 +0x2f4
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: github.com/terraform-providers/terraform-provider-aws/aws.buildLaunchTemplateData(0xc0002b8f50, 0x29, 0xc000b063c0, 0x43)      
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_launch_template.go:1073 +0x61b
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsLaunchTemplateCreate(0xc0002b8f50, 0x3ff2080, 0xc00074c900, 0x2, 0x99b8440)
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_launch_template.go:525 +0xcf
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform/helper/schema.(*Resource).Apply(0xc0005e6400, 0xc000c6d9f0, 0xc0008ffde0, 0x3ff2080, 0xc00074c900, 0x1, 0xc000b6a238, 0x451ed60)
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform/helper/schema/resource.go:305 +0x3bb
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform/helper/schema.(*Provider).Apply(0xc0006a1480, 0xc0008a3a58, 0xc000c6d9f0, 0xc0008ffde0, 0xc00092a868, 0xc0005712c0, 0x45214c0)
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform/helper/schema/provider.go:289 +0x196
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0xc0001669a8, 0x58a3a00, 0xc0008fac00, 0xc0007406c0, 0xc0001669a8, 0xc0008fac00, 0xc0008c1bd0)
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform/helper/plugin/grpc_provider.go:885 +0x89b
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0x4e41520, 0xc0001669a8, 0x58a3a00, 0xc0008fac00, 0xc000c6d720, 0x0, 0x58a3a00, 0xc0008fac00, 0xc00077ea00, 0x137c)
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform/internal/tfplugin5/tfplugin5.pb.go:3217 +0x245
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc.(*Server).processUnaryRPC(0xc000502c00, 0x58c73e0, 0xc000503500, 0xc0006b5600, 0xc00069ff80, 0x998cce0, 0x0, 0x0, 0x0)
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc/server.go:971 +0x477
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc.(*Server).handleStream(0xc000502c00, 0x58c73e0, 0xc000503500, 0xc0006b5600, 0x0)
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc/server.go:1250 +0xd2c
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc00016c150, 0xc000502c00, 0x58c73e0, 0xc000503500, 0xc0006b5600)
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc/server.go:690 +0xa6
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: created by github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc.(*Server).serveStreams.func1    
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc/server.go:688 +0xa8
2019/09/26 09:11:25 [DEBUG] aws_launch_template.default[0]: apply errored, but we're indicating that via the Error pointer rather than returning it: rpc error: code = Unavailable desc = transport is closing    
2019/09/26 09:11:25 [TRACE] <root>: eval: *terraform.EvalMaybeTainted
2019/09/26 09:11:25 [TRACE] EvalMaybeTainted: aws_launch_template.default[0] encountered an error during creation, so it is now marked as tainted
2019/09/26 09:11:25 [TRACE] <root>: eval: *terraform.EvalWriteState
2019/09/26 09:11:25 [TRACE] EvalWriteState: removing state object for aws_launch_template.default[0]
2019/09/26 09:11:25 [TRACE] <root>: eval: *terraform.EvalApplyProvisioners
2019/09/26 09:11:25 [TRACE] EvalApplyProvisioners: aws_launch_template.default[0] has no state, so skipping provisioners
2019/09/26 09:11:25 [TRACE] <root>: eval: *terraform.EvalMaybeTainted
2019/09/26 09:11:25 [TRACE] EvalMaybeTainted: aws_launch_template.default[0] encountered an error during creation, so it is now marked as tainted
2019/09/26 09:11:25 [TRACE] <root>: eval: *terraform.EvalWriteState
2019/09/26 09:11:25 [TRACE] EvalWriteState: removing state object for aws_launch_template.default[0]
2019/09/26 09:11:25 [TRACE] <root>: eval: *terraform.EvalIf
2019/09/26 09:11:25 [TRACE] <root>: eval: *terraform.EvalIf
2019/09/26 09:11:25 [TRACE] <root>: eval: *terraform.EvalWriteDiff
2019/09/26 09:11:25 [TRACE] <root>: eval: *terraform.EvalApplyPost
2019/09/26 09:11:25 [ERROR] <root>: eval: *terraform.EvalApplyPost, err: rpc error: code = Unavailable desc = transport is closing
2019/09/26 09:11:25 [ERROR] <root>: eval: *terraform.EvalSequence, err: rpc error: code = Unavailable desc = transport is closing
2019/09/26 09:11:25 [TRACE] [walkApply] Exiting eval tree: aws_launch_template.default[0]
2019/09/26 09:11:25 [TRACE] vertex "aws_launch_template.default[0]": visit complete
2019/09/26 09:11:25 [TRACE] dag/walk: upstream of "output.launch_template_id" errored, so skipping
2019/09/26 09:11:25 [TRACE] dag/walk: upstream of "output.launch_template_arn" errored, so skipping
2019/09/26 09:11:25 [TRACE] dag/walk: upstream of "aws_autoscaling_group.default[0]" errored, so skipping
2019/09/26 09:11:25 [TRACE] dag/walk: upstream of "output.autoscaling_group_id" errored, so skipping
2019/09/26 09:11:25 [TRACE] dag/walk: upstream of "output.autoscaling_group_default_cooldown" errored, so skipping
2019/09/26 09:11:25 [TRACE] dag/walk: upstream of "output.autoscaling_group_desired_capacity" errored, so skipping
2019/09/26 09:11:25 [TRACE] dag/walk: upstream of "output.autoscaling_group_health_check_grace_period" errored, so skipping
2019/09/26 09:11:25 [TRACE] dag/walk: upstream of "output.autoscaling_group_min_size" errored, so skipping
2019/09/26 09:11:25 [TRACE] dag/walk: upstream of "output.autoscaling_group_health_check_type" errored, so skipping
2019/09/26 09:11:25 [TRACE] dag/walk: upstream of "provider.aws (close)" errored, so skipping
2019/09/26 09:11:25 [TRACE] dag/walk: upstream of "output.autoscaling_group_name" errored, so skipping
2019/09/26 09:11:25 [TRACE] dag/walk: upstream of "output.autoscaling_group_arn" errored, so skipping
2019/09/26 09:11:25 [TRACE] dag/walk: upstream of "output.autoscaling_group_max_size" errored, so skipping
2019/09/26 09:11:25 [TRACE] dag/walk: upstream of "meta.count-boundary (EachMode fixup)" errored, so skipping
2019/09/26 09:11:25 [TRACE] dag/walk: upstream of "root" errored, so skipping
2019/09/26 09:11:25 [TRACE] statemgr.Filesystem: creating backup snapshot at terraform.tfstate.backup
2019/09/26 09:11:25 [TRACE] statemgr.Filesystem: state has changed since last snapshot, so incrementing serial to 117
2019/09/26 09:11:25 [TRACE] statemgr.Filesystem: writing snapshot at terraform.tfstate
2019/09/26 09:11:25 [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info
2019/09/26 09:11:25 [TRACE] statemgr.Filesystem: unlocked by closing terraform.tfstate
2019-09-26T09:11:25.088+0800 [DEBUG] plugin: plugin process exited: path=C:\Users\wongf\Documents\terraform\modules\ec2-asg-launchtemplate\.terraform\plugins\windows_amd64\terraform-provider-aws_v2.29.0_x4.exe 
pid=30084 error="exit status 2"
2019-09-26T09:11:25.088+0800 [DEBUG] plugin: plugin exited

Panic Output

https://gist.github.com/falconh/c78713024c839d785d242c64279e68b9

Expected Behavior

During the creation of aws_launch_template, the aws provider should ignore the empty block of following attributes

and create the aws_launch_template resource successfully

Actual Behavior

Panic happened and crashed the terraform

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

Steps to Reproduce

  1. terraform apply
  2. Comment out one of the attribute blocks in order to isolate the problem during testing

    Important Factoids

References

nywilken commented 4 years ago

Relevant log information


panic: interface conversion: interface {} is nil, not map[string]interface {}
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: goroutine 106 [running]:
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: github.com/terraform-providers/terraform-provider-aws/aws.readCapacityReservationSpecificationFromConfig(0xc000b6c1b0, 0x4fcf002)
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_launch_template.go:1352 +0x2f4
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: github.com/terraform-providers/terraform-provider-aws/aws.buildLaunchTemplateData(0xc0002b8f50, 0x29, 0xc000b063c0, 0x43)      
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_launch_template.go:1073 +0x61b
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe: github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsLaunchTemplateCreate(0xc0002b8f50, 0x3ff2080, 0xc00074c900, 0x2, 0x99b8440)
2019-09-26T09:11:25.073+0800 [DEBUG] plugin.terraform-provider-aws_v2.29.0_x4.exe:      /opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_launch_template.go:525 +0xcf```
ghost commented 4 years ago

I'm going to close this issue due to inactivity (90 days without response ⏳ ). 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 commented 4 years ago

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!