Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encountering undefined method `[]' for nil:NilClass trying to create and attach aws_ebs_volume #242

Open
daystorm opened this issue May 19, 2016 · 3 comments

Comments

@daystorm
Copy link

Cookbook version

aws cookbook is version 3.3.2

Chef-client version

root@hgtv-aws-test2-publish cookbooks]# chef-client -v
Chef: 12.6.0

Platform Details

Linux hgtv-aws-test2-publish 4.4.8-20.46.amzn1.x86_64 #1 SMP Wed Apr 27 19:28:52 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
running on AWS

Scenario:

I am trying to create and attach a volume on to one of my EC2 instances. The recipe works fine with the 2.9.3 version of the cookbook. When I try to use any of the 3.x versions, I get the error listed above.

Steps to Reproduce:

I have tried the following simple recipe and it fails.

vol_path = node[:instance][:vol_path]

aws_ebs_volume 'cq_vol' do
device "/dev/sdf"
size 100
volume_type "gp2"
snapshot_id "my-snapshot" #id obscured for security reasons
action [:create, :attach]
end

aws_resource_tag 'vol_tags' do
resource_id lazy { node[:aws][:ebs_volume][:cq_vol][:volume_id] }
tags ({"auto-cq5-volume" => "",
"subdomain" => node[:instance][:subdomain],
"cqservertype" => node[:instance][:role]
})
action :update
end

mount vol_path do
device '/dev/sdf'
fstype 'xfs'
action [:mount, :enable]
end

Expected Result:

I am expecting to have a volume created, attached, and mounted to my system.

Actual Result:

I get the following error.

================================================================================
Error executing action `create` on resource 'aws_ebs_volume[cq_vol]'
================================================================================

NoMethodError
-------------
undefined method `[]' for nil:NilClass

Cookbook Trace:
---------------
/etc/chef/local-mode-cache/cache/cookbooks/aws/libraries/ec2.rb:34:in `instance_id'
/etc/chef/local-mode-cache/cache/cookbooks/aws/providers/ebs_volume.rb:28:in `block in class_from_file'

Resource Declaration:
---------------------
# In /etc/chef/local-mode-cache/cache/cookbooks/snicq/recipes/_attach_cq_vol_static.rb

  3: aws_ebs_volume 'cq_vol' do
  4:   device "/dev/sdf"
  5:   size 100
  6:   volume_type "gp2"
  7:   snapshot_id "my-snapshot"
  8:   action [:create, :attach]
  9: end
 10: 

Compiled Resource:
------------------
# Declared in /etc/chef/local-mode-cache/cache/cookbooks/snicq/recipes/_attach_cq_vol_static.rb:3:in `from_file'

aws_ebs_volume("cq_vol") do
  action [:create, :attach]
  retries 0
  retry_delay 2
  default_guard_interpreter :default
  declared_type :aws_ebs_volume
  cookbook_name "snicq"
  recipe_name "_attach_cq_vol_static"
  device "/dev/sdf"
  size 100
  volume_type "gp2"
  snapshot_id "my-snapshot"
end
@eldenseropian
Copy link

I am also experiencing this.

@shinterro
Copy link
Contributor

shinterro commented Jul 20, 2016

This happened to me. You might be missing a value for node['ec2']['instance_id'].

Older cookbook versions used a 'query_instance_id' method to lookup the instance_id. This was modified from versions 3.0.0 and up with the intention that Ohai would provide the values.

Try running the aws::ec2_hints recipe. I believe that is what is supposed to supply the required values now.

@eldenseropian
Copy link

Adding aws::ec2_hints worked for me, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants