hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.71k stars 9.55k forks source link

Terraform crashed when terraform plan #21835

Closed relifeted closed 5 years ago

relifeted commented 5 years ago

Terraform Version

Terraform v0.12.2

Terraform Configuration Files

locals {
  aws_cloudwatch_event_target_codebuild_input_template = <<TEMPLATE
{
  "Service": "CodeBuild",
  "project": "$project-name#",
  "status": "$build-status#",
  "region": "$region#"
}
TEMPLATE

}

resource "aws_cloudwatch_event_rule" "CodeBuild_Build_State" {
  name = "capture-CodeBuild-Build-State-events"
  description = "Capture all CodeBuild Build State events"

  event_pattern = <<PATTERN
{
  "source": [ 
    "aws.codebuild"
  ], 
  "detail-type": [
    "CodeBuild Build State Change"
  ],
  "detail": {
    "build-status": [
      "IN_PROGRESS",
      "SUCCEEDED", 
      "FAILED",
      "STOPPED" 
    ]
  }  
}
PATTERN

}

resource "aws_cloudwatch_event_target" "CodeBuild_Build_State" {
  target_id = "sns"
  rule      = aws_cloudwatch_event_rule.CodeBuild_Build_State.name
  arn       = aws_sns_topic.deployments.arn

  input_transformer {
    input_paths = {
      "region"       = "$.region"
      "project-name" = "$.detail.project-name"
      "build-status" = "$.detail.build-status"
    }

    input_template = replace(
      replace(
        jsonencode(local.aws_cloudwatch_event_target_codebuild_input_template),
        "$",
        "<",
      ),
      "#",
      ">",
    )
  }
}

resource "aws_cloudwatch_event_rule" "CodeBuild_Build_State_virginia" {
  provider    = aws.virginia
  name        = "capture-CodeBuild-Build-State-events"
  description = "Capture all CodeBuild Build State events"

  event_pattern = <<PATTERN
  {
    "source": [ 
      "aws.codebuild"
    ], 
    "detail-type": [
      "CodeBuild Build State Change"
    ],
    "detail": {
      "build-status": [
        "IN_PROGRESS",
        "SUCCEEDED", 
        "FAILED",
        "STOPPED" 
      ]
    }  
  }
  PATTERN

}

resource "aws_cloudwatch_event_target" "CodeBuild_Build_State_virginia" {
  provider = aws.virginia
  target_id = "sns"
  rule = aws_cloudwatch_event_rule.CodeBuild_Build_State_virginia.name
  arn = aws_sns_topic.deployments-virginia.arn

  input_transformer {
    input_paths = {
      "region" = "$.region"
      "project-name" = "$.detail.project-name"
      "build-status" = "$.detail.build-status"
    }

  input_template = replace(
      replace(
          jsonencode(local.aws_cloudwatch_event_target_codebuild_input_template)
          ,"$","<",
      )
      ,"#",">",
    )
  }
}

Debug Output

https://gist.github.com/relifeted/c831f9521d8228c94ecd4deaa4996da4

Crash Output

https://gist.github.com/relifeted/c831f9521d8228c94ecd4deaa4996da4

Expected Behavior

finish plan

Actual Behavior

crashed

Steps to Reproduce

  1. terraform init
  2. terraform plan

    Additional Context

References

jbardin commented 5 years ago

Thanks for the bug report @relifeted,

There seems to be an unexpectedly nil instance in the state. The relevant stack trace is:

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

goroutine 2298 [running]:
github.com/hashicorp/terraform/terraform.(*evaluationStateData).getResourceInstancesAll(0xc0068413b0, 0x4d, 0xc000702820, 0x13, 0xc000948d40, 0xd, 0xc0007f6180, 0x33, 0xa, 0x1a, ...)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/evaluate.go:704 +0x11a3
github.com/hashicorp/terraform/terraform.(*evaluationStateData).GetResourceInstance(0xc0068413b0, 0x4d, 0xc000702820, 0x13, 0xc000948d40, 0xd, 0x0, 0x0, 0xc0007f6180, 0x33, ...)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/evaluate.go:593 +0x1360
github.com/hashicorp/terraform/lang.(*Scope).evalContext(0xc003bec5f0, 0xc001848fa0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0xc00089b520, 0xa)
    /opt/gopath/src/github.com/hashicorp/terraform/lang/eval.go:253 +0xfcc
github.com/hashicorp/terraform/lang.(*Scope).EvalContext(...)
    /opt/gopath/src/github.com/hashicorp/terraform/lang/eval.go:160
github.com/hashicorp/terraform/lang.(*Scope).EvalExpr(0xc003bec5f0, 0x2de8f60, 0xc000417e00, 0x2dea2a0, 0x3ee48d8, 0xc0014caa80, 0x0, 0xc0020c8768, 0x3, 0xc00004e570, ...)
    /opt/gopath/src/github.com/hashicorp/terraform/lang/eval.go:87 +0xb3
github.com/hashicorp/terraform/terraform.(*BuiltinEvalContext).EvaluateExpr(0xc0014c95f0, 0x2de8f60, 0xc000417e00, 0x2dea2a0, 0x3ee48d8, 0x0, 0x0, 0x3ec4c60, 0x56, 0x2a30f70, ...)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_context_builtin.go:284 +0x1e4
github.com/hashicorp/terraform/terraform.(*EvalWriteOutput).Eval(0xc0019e23c0, 0x2e1c120, 0xc0014c95f0, 0x2, 0x2, 0xc001a20000, 0x53)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_output.go:48 +0x153
github.com/hashicorp/terraform/terraform.EvalRaw(0x2da8d20, 0xc0019e23c0, 0x2e1c120, 0xc0014c95f0, 0x3e, 0x0, 0x0, 0x3e)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:57 +0x131
github.com/hashicorp/terraform/terraform.(*EvalOpFilter).Eval(0xc0019e2420, 0x2e1c120, 0xc0014c95f0, 0x2, 0x2, 0xc0020c8b38, 0x102b231)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_filter_operation.go:37 +0x4c
github.com/hashicorp/terraform/terraform.EvalRaw(0x2da8ae0, 0xc0019e2420, 0x2e1c120, 0xc0014c95f0, 0x14, 0xbf3b4a942b5c4bc8, 0x626428c9b, 0x3e)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:57 +0x131
github.com/hashicorp/terraform/terraform.(*EvalSequence).Eval(0xc000c9ff40, 0x2e1c120, 0xc0014c95f0, 0x2, 0x2, 0x1abe1c5, 0x2da8ae0)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval_sequence.go:20 +0xfd
github.com/hashicorp/terraform/terraform.EvalRaw(0x2da8c20, 0xc000c9ff40, 0x2e1c120, 0xc0014c95f0, 0x2663a20, 0x3d9a404, 0x25d0da0, 0xc00148edb0)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:57 +0x131
github.com/hashicorp/terraform/terraform.Eval(0x2da8c20, 0xc000c9ff40, 0x2e1c120, 0xc0014c95f0, 0xc000c9ff40, 0x2da8c20, 0xc000c9ff40, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/eval.go:35 +0x4d
github.com/hashicorp/terraform/terraform.(*Graph).walk.func1(0x282c680, 0xc000a6a030, 0x0, 0x0, 0x0)
    /opt/gopath/src/github.com/hashicorp/terraform/terraform/graph.go:90 +0xf40
github.com/hashicorp/terraform/dag.(*Walker).walkVertex(0xc0007be980, 0x282c680, 0xc000a6a030, 0xc0015b47c0)
    /opt/gopath/src/github.com/hashicorp/terraform/dag/walk.go:392 +0x353
created by github.com/hashicorp/terraform/dag.(*Walker).Update
    /opt/gopath/src/github.com/hashicorp/terraform/dag/walk.go:314 +0xa9b
xocasdashdash commented 5 years ago

@jbardin I think it's a dupe of another issue I have opened #21740 . Do you think this will be fixed in the 0.11.x series?

jbardin commented 5 years ago

closed by #21979

ghost commented 5 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 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.