0
votes

We're using the Terraform Chef provisioner on AWS using AWS-managed Chef server. Terraform is able to:

  1. create the instance
  2. connect to the instance via SSH and install the chef-client

The chef-client is up to the point where it generates the private key and then it is followed by this error:

aws_instance.machine (chef): ERROR: Not Allowed
aws_instance.machine (chef): Response: <html>
aws_instance.machine (chef): <head><title>405 Not Allowed</title></head>
aws_instance.machine (chef): <body bgcolor="white">
aws_instance.machine (chef): <center><h1>405 Not Allowed</h1></center>
aws_instance.machine (chef): <hr><center>nginx</center>
aws_instance.machine (chef): </body>
aws_instance.machine (chef): </html>

Here's the configuration:

provider "aws" { }

resource "aws_instance" "test" {
  ami = "ami-xxxxxxxx"
  instance_type = "t2.micro"
  vpc_security_group_ids = ["sg-xxxxxxx"]
  subnet_id = "subnet-xxxxxx"
  key_name = "Test"
  tags {
    Name = "test"
  }

  provisioner "chef" {
    server_url      = "https://<chef server url>"
    user_name       = "user"
    user_key        = "${file("~/.chef/user.pem")}"
    node_name       = "test"
    run_list        = ["role[app]"]
    on_failure      = "continue"
    recreate_client = true
    version         = "12.16.42"
    fetch_chef_certificates = false
    ssl_verify_mode = ":verify_none"
    environment = "test"
    client_options = [
      "verbose_logging = true"
    ]
  }

  connection {
    type         = "ssh"
    user         = "ssh-user"
    private_key  = "${file("../keys/ssh-user.pem")}"
    bastion_host = "1.1.1.1"
  }
}

What is causing this error and how do I fix this?

Thanks in advance!

EDIT: I enabled Terraform logging TF_LOG=1 and found that the chef client is trying to reference PEM files that are not on the node:

sudo knife client show test -c /etc/chef/client.rb -u user --key /etc/chef/user.pem > /dev/null 2>&1

and

sudo knife client create test -d -f /etc/chef/client.pem -c /etc/chef/client.rb -u user --key /etc/chef/user.pem
1
Do you install chef-client? Please share the code. - Sudharsan Sivasankaran
I updated the post. Hope someone can point me in the right direction. - FrancisV
IRC, when using bastion host connection block should be part of the provisioner block. The 405 error, looks like one from proxy in your network(?). - Szymon Szypulski

1 Answers

0
votes

I made a mistake with the server_url parameter. The correct URL should be in this format: http://chef_server/organizations/default