I'm having an issue with a custom resource I created in a new cookbook i'm working on. When I do a kitchen converge on the following setup I get the following error:
error: NoMethodError: undefined method `repository_url' for PoiseApplicationGit::Resource
Info about my development machine:
- Chef Development Kit Version: 2.1.11
- chef-client version: 13.2.20
- delivery version: master (73ebb72a6c42b3d2ff5370c476be800fee7e5427)
- berks version: 6.3.0
- kitchen version: 1.17.0
- inspec version: 1.33.1
Here's my custom resource under resources/deploy.rb:
resource_name :opsworks_deploy
property :app_path, String, name_property: true
property :app_name, String, required: true
property :repository_url, String, required: true
property :repository_key, String, required: true
property :short_name, String, required: true
property :app_type, String, required: true
property :app, Object, required: true
property :permission, String, required: true
action :deploy do
apt_update 'update'
# Install NGinx
package 'nginx' do
not_if { ::File.exist?("/etc/init.d/nginx") }
end
# Setup the app directory
directory my_app_path do
owner 'www-data'
group 'www-data'
mode '0755'
recursive true
end
slack_notify "notify_deployment_end" do
message "App #{app_name} deployed successfully"
action :nothing
end
slack_notify "notify_nginx_reload" do
message "Nginx has reloaded"
action :nothing
end
slack_notify "notify_nginx_config" do
message "Nginx site config has been updated for #{app_name}"
action :nothing
end
slack_notify "notify_git_deploy" do
message "App #{app_name} has been checkout out from git"
action :nothing
end
slack_notify "notify_file_permissions" do
message "App #{app_name} has been given proper file permissions"
action :nothing
end
# Deploy git repo from opsworks app
application app_path do
owner 'www-data'
group 'www-data'
git do
user 'root'
group 'root'
repository my_repo_url
deploy_key my_repo_key
notifies :notify, "slack_notify[notify_git_deploy]", :immediately
end
execute "chown-data-www" do
command "chown -R www-data:www-data #{my_app_path}"
user "root"
action :run
notifies :notify, "slack_notify[notify_file_permissions]", :immediately
end
# Setup the nginx config file for the site
template "/etc/nginx/sites-enabled/#{my_short_name}" do
source "#{my_app_type}.erb"
owner "root"
group "root"
mode 0644
variables( :app => my_app )
notifies :notify, "slack_notify[notify_nginx_config]", :immediately
end
# Reload nginx
service "nginx" do
supports :status => true, :restart => true, :reload => true, :stop => true, :start => true
action :reload
notifies :notify, "slack_notify[notify_nginx_reload]", :immediately
end
end
end
Here's my recipe under recipes/default.rb (all variables are set properly and to the proper types, i'm using test data bags and they are correctly passing):
command = search(:aws_opsworks_command).first
deploy_app = command[:args][:app_ids].first
app = search(:aws_opsworks_app, "app_id:#{deploy_app}").first
app_path = "/var/www/" + app[:shortname]
opsworks_deploy app_path do
app_name app[:name]
app_type app[:environment][:APP_TYPE]
repository_url app[:app_source][:url]
repository_key app[:app_source][:ssh_key]
short_name app[:shortname]
app app
permission '0755'
end
The only way I can get it working is if I add this at the top of the action declaration and update the properties within to match:
action :deploy do
my_repo_url = repository_url.dup
my_repo_key = repository_key.dup
my_app_path = app_path.dup
my_app_type = app_type.dup
my_short_name = short_name.dup
my_app = app.dup
...
Any reason why this is the case? Should I have to redeclare them like that in the action?