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.42k stars 9.51k forks source link

Using chef provisioner; get unexpected EOF with basic config #15324

Closed shannonrdunn closed 7 years ago

shannonrdunn commented 7 years ago

Terraform Version

0.9.8

Terraform Configuration Files

terraform {
  backend "local" {
    path = "./terraform.tfstate"
  }
}

provider "aws" {

  region     = "us-east-1"
}

resource "aws_instance" "web" {
  ami           = "ami-xxxxxx"
  instance_type = "r4.4xlarge"
  subnet_id = "subnet-xxxxxxxxxx"
  key_name = "keyname"
  vpc_security_group_ids = ["sg-xxxxxx"]
  provisioner "chef" {
    attributes_json = <<-EOF
      {
        "key": "value",
        "app": {
          "cluster1": {
            "nodes": [
              "webserver1",
              "webserver2"
            ]
          }
        }
      }
    EOF
    environment     = "_default"
    node_name       = "webserver1"
    server_url      = "https://172.16.1.0/organizations/xxxxx"
    recreate_client = true
    user_name       = "ryan_dunn"
    user_key        = "${file("/home/dunn/.chef/ryan_dunn.pem")}"
    version         = "12.4.1"
  }
}

Panic Output

CLI output: https://gist.github.com/shannonrdunn/a953e3a99318e91a0ca908faea2b7208

Crash.log: https://gist.github.com/shannonrdunn/dce306eb8f797e21121ae5

Expected Behavior

We expect terraform to spin up the AWS instance, then bootstrap with chef with the built in chef provisioner.

Actual Behavior

When using version 0.9.8 we get "unexpected EOF" error when it gets to using chef provisioner

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Get example config from terraform site:
  resource "aws_instance" "web" {
  # ...

  provisioner "chef" {
    attributes_json = <<-EOF
      {
        "key": "value",
        "app": {
          "cluster1": {
            "nodes": [
              "webserver1",
              "webserver2"
            ]
          }
        }
      }
    EOF

    environment     = "_default"
    run_list        = ["cookbook::recipe"]
    node_name       = "webserver1"
    secret_key      = "${file("../encrypted_data_bag_secret")}"
    server_url      = "https://chef.company.com/organizations/org1"
    recreate_client = true
    user_name       = "bork"
    user_key        = "${file("../bork.pem")}"
    version         = "12.4.1"
  }
  1. Fill in relevant AWS information
  2. terraform apply

Important Factoids

We are using a pretty basic configuration of AWS. But this appears to be happening when running the chef provisioner with even the provided chef provisioner example.

References

This works in 0.9.6 and looks like there was maybe a refactor of the chef provisioner code here:

https://github.com/hashicorp/terraform/pull/14681

trthomps commented 7 years ago

I am also seeing this issue.

px4n commented 7 years ago

I'm getting exactly the same error when using Terraform 0.9.8, as @shannonrdunn stated, looks like issue started occurring with 0.9.7, 0.9.6 works fine. I'm getting around this by using user data instead but it's not ideal.

keyan commented 7 years ago

Hate to +1, but we are also seeing this and it is blocking us from using TF. After attempting a few things I ended up having to manually modify the state file and downgrade to 0.9.6 following the advice mentioned here: https://github.com/hashicorp/terraform/issues/15177#issuecomment-307800618

echohack commented 7 years ago

+1

I believe something was broken in https://github.com/hashicorp/terraform/commit/0e422737baa8f23919d5a7fc2c1e2772d3a32d14

I'm curious what @svanharmelen thinks.

Here is our crash log:


aws_instance.es_backend.0: Provisioning with 'chef'...
Error applying plan:

1 error(s) occurred:

* aws_instance.es_backend[0]: 1 error(s) occurred:

* unexpected EOF

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
panic: runtime error: invalid memory address or nil pointer dereference
2017/06/26 11:50:18 [DEBUG] plugin: terraform: [signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x4e24262]
2017/06/26 11:50:18 [DEBUG] plugin: terraform:
2017/06/26 11:50:18 [DEBUG] plugin: terraform: goroutine 73 [running]:
2017/06/26 11:50:18 [DEBUG] plugin: terraform: github.com/hashicorp/terraform/builtin/provisioners/chef.applyFn(0x8db91c0, 0xc420344600, 0x0, 0x0)
2017/06/26 11:50:18 [DEBUG] plugin: terraform:  /private/tmp/terraform-20170608-62088-1i5m5j4/terraform-0.9.8/src/github.com/hashicorp/terraform/builtin/provisioners/chef/resource_provisioner.go:268 +0x14d2
2017/06/26 11:50:18 [DEBUG] plugin: terraform: github.com/hashicorp/terraform/helper/schema.(*Provisioner).Apply(0xc4201daa50, 0x8d8e840, 0xc4201d6008, 0xc42037c0a0, 0xc42021a0f0, 0x0, 0x0)
2017/06/26 11:50:18 [DEBUG] plugin: terraform:  /private/tmp/terraform-20170608-62088-1i5m5j4/terraform-0.9.8/src/github.com/hashicorp/terraform/helper/schema/provisioner.go:205 +0x563
2017/06/26 11:50:18 [DEBUG] plugin: terraform: github.com/hashicorp/terraform/plugin.(*ResourceProvisionerServer).Apply(0xc420261040, 0xc4203ce0c0, 0xc4204e02a0, 0x0, 0x0)
2017/06/26 11:50:18 [DEBUG] plugin: terraform:  /private/tmp/terraform-20170608-62088-1i5m5j4/terraform-0.9.8/src/github.com/hashicorp/terraform/plugin/resource_provisioner.go:142 +0x191
2017/06/26 11:50:18 [DEBUG] plugin: terraform: reflect.Value.call(0xc420070c60, 0xc4204e0a90, 0x13, 0x614892d, 0x4, 0xc420046f20, 0x3, 0x3, 0x0, 0x0, ...)
2017/06/26 11:50:18 [DEBUG] plugin: terraform:  /usr/local/Cellar/go/1.8.3/libexec/src/reflect/value.go:434 +0x91f
2017/06/26 11:50:18 [DEBUG] plugin: terraform: reflect.Value.Call(0xc420070c60, 0xc4204e0a90, 0x13, 0xc42076af20, 0x3, 0x3, 0x0, 0x0, 0xc42001aa80)
2017/06/26 11:50:18 [DEBUG] plugin: terraform:  /usr/local/Cellar/go/1.8.3/libexec/src/reflect/value.go:302 +0xa4
2017/06/26 11:50:18 [DEBUG] plugin: terraform: net/rpc.(*service).call(0xc420798580, 0xc420798540, 0xc4204112c0, 0xc420099b80, 0xc4202adca0, 0x523b940, 0xc4203ce0c0, 0x16, 0x523b980, 0xc4204e02a0, ...)
2017/06/26 11:50:18 [DEBUG] plugin: terraform:  /usr/local/Cellar/go/1.8.3/libexec/src/net/rpc/server.go:387 +0x144
2017/06/26 11:50:18 [DEBUG] plugin: terraform: created by net/rpc.(*Server).ServeCodec
2017/06/26 11:50:18 [DEBUG] plugin: terraform:  /usr/local/Cellar/go/1.8.3/libexec/src/net/rpc/server.go:481 +0x404
2017/06/26 11:50:18 [DEBUG] root: eval: *terraform.EvalIf
2017/06/26 11:50:18 [DEBUG] root: eval: *terraform.EvalWriteState
2017/06/26 11:50:18 [DEBUG] root: eval: *terraform.EvalWriteDiff
2017/06/26 11:50:18 [DEBUG] root: eval: *terraform.EvalApplyPost
2017/06/26 11:50:18 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:

* unexpected EOF
2017/06/26 11:50:18 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

* unexpected EOF
2017/06/26 11:50:18 [TRACE] [walkApply] Exiting eval tree: aws_instance.es_backend[0]
2017/06/26 11:50:18 [DEBUG] dag/walk: upstream errored, not walking "aws_instance.es_backend[1]"
2017/06/26 11:50:18 [DEBUG] dag/walk: upstream errored, not walking "aws_instance.es_backend[2]"
2017/06/26 11:50:18 [DEBUG] dag/walk: upstream errored, not walking "aws_instance.chef_automate"
2017/06/26 11:50:18 [DEBUG] dag/walk: upstream errored, not walking "aws_instance.chef_load"
2017/06/26 11:50:18 [DEBUG] dag/walk: upstream errored, not walking "provisioner.remote-exec (close)"
2017/06/26 11:50:18 [DEBUG] dag/walk: upstream errored, not walking "provisioner.chef (close)"
2017/06/26 11:50:18 [DEBUG] dag/walk: upstream errored, not walking "provisioner.file (close)"
2017/06/26 11:50:18 [DEBUG] dag/walk: upstream errored, not walking "provider.aws (close)"
2017/06/26 11:50:18 [DEBUG] dag/walk: upstream errored, not walking "meta.count-boundary (count boundary fixup)"
2017/06/26 11:50:18 [DEBUG] dag/walk: upstream errored, not walking "root"
2017/06/26 11:50:18 [DEBUG] plugin: /usr/local/Cellar/terraform/0.9.8/bin/terraform: plugin process exited
2017/06/26 11:50:18 [TRACE] Preserving existing state lineage "49caf0f6-4b7c-44d5-ac96-a18756d50b7b"
2017/06/26 11:50:18 [DEBUG] plugin: waiting for all plugin processes to complete...
2017/06/26 11:50:18 [WARN] plugin: error closing client during Kill: connection is shut down
2017/06/26 11:50:18 [DEBUG] plugin: terraform: remote-exec-provisioner (internal) 2017/06/26 11:50:18 [DEBUG] plugin: waiting for all plugin processes to complete...
2017/06/26 11:50:18 [DEBUG] plugin: terraform: file-provisioner (internal) 2017/06/26 11:50:18 [DEBUG] plugin: waiting for all plugin processes to complete...
2017/06/26 11:50:18 [DEBUG] plugin: terraform: aws-provider (internal) 2017/06/26 11:50:18 [DEBUG] plugin: waiting for all plugin processes to complete...
2017/06/26 11:50:18 [DEBUG] plugin: terraform: template-provider (internal) 2017/06/26 11:50:18 [DEBUG] plugin: waiting for all plugin processes to complete...
2017/06/26 11:50:18 [DEBUG] plugin: terraform: local-exec-provisioner (internal) 2017/06/26 11:50:18 [DEBUG] plugin: waiting for all plugin processes to complete...
2017/06/26 11:50:18 [DEBUG] plugin: terraform: random-provider (internal) 2017/06/26 11:50:18 [DEBUG] plugin: waiting for all plugin processes to complete...
2017/06/26 11:50:18 [DEBUG] plugin: /usr/local/Cellar/terraform/0.9.8/bin/terraform: plugin process exited
2017/06/26 11:50:18 [DEBUG] plugin: /usr/local/Cellar/terraform/0.9.8/bin/terraform: plugin process exited
2017/06/26 11:50:18 [DEBUG] plugin: /usr/local/Cellar/terraform/0.9.8/bin/terraform: plugin process exited
2017/06/26 11:50:18 [DEBUG] plugin: /usr/local/Cellar/terraform/0.9.8/bin/terraform: plugin process exited
2017/06/26 11:50:18 [DEBUG] plugin: /usr/local/Cellar/terraform/0.9.8/bin/terraform: plugin process exited
2017/06/26 11:50:18 [DEBUG] plugin: /usr/local/Cellar/terraform/0.9.8/bin/terraform: plugin process exited

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Terraform crashed! This is always indicative of a bug within Terraform.
A crash log has been placed at "crash.log" relative to your current
working directory. It would be immensely helpful if you could please
report the crash with Terraform[1] so that we can fix this.

When reporting bugs, please include your terraform version. That
information is available on the first line of crash.log. You can also
get it by running 'terraform --version' on the command line.

[1]: https://github.com/hashicorp/terraform/issues

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!```
svanharmelen commented 7 years ago

Any chance you could test this with 0.10.0-beta1? There are a few fixes in there related to the Chef provisioner so would be good to know if the problem still exists before diving in...

svanharmelen commented 7 years ago

Version 0.9.9 is just released. Could you please verify if this release also solves this issue? Thx!

echohack commented 7 years ago

@svanharmelen

We've tested out https://github.com/echohack/deltron using terraform 0.9.9 with the Chef Provisioner and confirmed that this fixes the issue.

heythisisnate commented 7 years ago

0.9.9 fixed the problem for me as well. Thank you for quickly fixing.

svanharmelen commented 7 years ago

Glad to hear the problem is solved 👍

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 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.