I am using Terraform to spin up a Redhat Linux instance in aws using a chef provisioner. My configuration uses the MySQL LWRP to create an SQL client. The machine is spun up correctly and chef-client is installed on the machine, the cookbooks are also synchronised properly. The issues is that I am getting a compilation error.
This cookbook works properly when it's run using test-kitchen on a Centos 6 platform
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.
`
Cookbook version
depends 'mysql', '~> 8.2.0'
Chef-client version
~]$ chef-client --version Chef: 12.18.31
Platform Details
[Operating system distribution and release version. Cloud provider if running in the cloud]
AWS RHEL-6.8_HVM_GA-20160503-x86_64-1-Hourly2-GP2 (ami-6fb7450f)
Scenario:
I am using Terraform to spin up a Redhat Linux instance in aws using a chef provisioner. My configuration uses the MySQL LWRP to create an SQL client. The machine is spun up correctly and chef-client is installed on the machine, the cookbooks are also synchronised properly. The issues is that I am getting a compilation error.
This cookbook works properly when it's run using test-kitchen on a Centos 6 platform
The steps are below:
Steps to Reproduce:
Terraform File Content (main.tf)
` resource "aws_instance" "instance" { connection { user = "user" }
ami = "${var.aws_ami}" instance_type = "${var.instance_type}" vpc_security_group_ids = ["${aws_security_group.default.id}"] key_name = "${aws_key_pair.iris_auth.id}"
provisioner "chef" { run_list = ["Cookbook::default"] node_name = "node" secret_key = "${var.secret_key}" server_url = "${var.chef_server_url}" recreate_client = true user_name = "${var.chef_user_name}" user_key = "${file(var.chef_user_key)}" fetch_chef_certificates = true ssl_verify_mode = ":verify_none" } } `
metadata.rb
depends 'mysql', '~> 8.2.0'
Chef script (default.rb)
` mysql_client 'default' do action :create end
mysql2_chef_gem node['mysql2_chef_gem']['resource_name'] do action :install end `
And the I run the following command
terraform apply
Expected Result:
MySQL client should be installed and running on the instance.
Actual Result:
This file's /etc/chef/first-boot.json content is the run list.
` aws_instance.node (chef): Synchronizing Cookbooks: aws_instance.node (chef): - ACME (1.0.0) aws_instance.node (chef): - java (1.46.0) aws_instance.node (chef): - apt (5.0.1) aws_instance.node (chef): - compat_resource (12.16.3) aws_instance.node (chef): - windows (2.1.1) aws_instance.node (chef): - ohai (4.2.3) aws_instance.node (chef): - homebrew (3.0.0) aws_instance.node (chef): - mysql (8.2.0) aws_instance.node (chef): - mysql2_chef_gem (1.1.0) aws_instance.node (chef): - build-essential (7.0.3) aws_instance.node (chef): - seven_zip (2.0.2) aws_instance.node (chef): - mingw (1.2.5) aws_instance.node (chef): - mariadb (1.0.1) aws_instance.node (chef): - yum (4.1.0) aws_instance.node (chef): - yum-epel (2.1.1) aws_instance.node (chef): - database (6.1.1) aws_instance.node (chef): - postgresql (6.0.1) aws_instance.node (chef): - openssl (6.1.1) aws_instance.node (chef): Installing Cookbook Gems: aws_instance.node (chef): Compiling Cookbooks... aws_instance.node (chef): aws_instance.node (chef): ================================================================================ aws_instance.node (chef): Recipe Compile Error in /var/chef/cache/cookbooks/mysql/libraries/provider_mysql_client.rb aws_instance.node (chef): ================================================================================
aws_instance.node (chef): NameError aws_instance.node (chef): --------- aws_instance.node (chef): uninitialized constant MysqlCookbook::Helpers
aws_instance.node (chef): Cookbook Trace: aws_instance.node (chef): --------------- aws_instance.node (chef): /var/chef/cache/cookbooks/mysql/libraries/provider_mysql_client.rb:7:in'
aws_instance.node (chef): /var/chef/cache/cookbooks/mysql/libraries/provider_mysql_client.rb:5:in
<class:MysqlClient>' aws_instance.node (chef): aws_instance.node (chef): /var/chef/cache/cookbooks/mysql/libraries/provider_mysql_client.rb:6:in
<class:Chef>' aws_instance.node (chef): /var/chef/cache/cookbooks/mysql/libraries/provider_mysql_client.rb:4:in
<top (required)>'aws_instance.node (chef): Relevant File Content: aws_instance.node (chef): ---------------------- aws_instance.node (chef): /var/chef/cache/cookbooks/mysql/libraries/provider_mysql_client.rb: aws_instance.node (chef): aws_instance.node (chef): 1: require 'chef/provider/lwrp_base' aws_instance.node (chef): 2: require_relative 'helpers' aws_instance.node (chef): 3: aws_instance.node (chef): 4: class Chef aws_instance.node (chef): 5: class Provider aws_instance.node (chef): 6: class MysqlClient < Chef::Provider::LWRPBase aws_instance.node (chef): 7>> include MysqlCookbook::Helpers aws_instance.node (chef): 8: provides :mysql_client if defined?(provides) aws_instance.node (chef): 9: aws_instance.node (chef): 10: use_inline_resources if defined?(use_inline_resources) aws_instance.node (chef): 11: aws_instance.node (chef): 12: def whyrun_supported? aws_instance.node (chef): 13: true aws_instance.node (chef): 14: end aws_instance.node (chef): 15: aws_instance.node (chef): 16: action :create do aws_instance.node (chef): aws_instance.node (chef): Platform: aws_instance.node (chef): --------- aws_instance.node (chef): x86_64-linux
aws_instance.node (chef): aws_instance.node (chef): Running handlers: aws_instance.node (chef): [2017-02-03T04:57:22-05:00] ERROR: Running exception handlers aws_instance.node (chef): Running handlers complete aws_instance.node (chef): [2017-02-03T04:57:22-05:00] ERROR: Exception handlers complete aws_instance.node (chef): Chef Client failed. 0 resources updated in 33 seconds aws_instance.node (chef): [2017-02-03T04:57:22-05:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out aws_instance.node (chef): [2017-02-03T04:57:22-05:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report aws_instance.node (chef): [2017-02-03T04:57:22-05:00] ERROR: uninitialized constant MysqlCookbook::Helpers aws_instance.node (chef): [2017-02-03T04:57:22-05:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1) Error applying plan:
1 error(s) occurred:
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. `