nathwill / chef-systemd

resource-driven chef cookbook for managing linux systems via systemd
Apache License 2.0
44 stars 33 forks source link

change resource sub-block evaluation context to avoid conflict with resource top-level properties #128

Closed nathwill closed 6 years ago

nathwill commented 6 years ago

this has been a pain point since the v3 rewrite (see #112, #125), but i wasn't ever sure how to get around it. thanks to some helpful advice from @coderanger tonight (👏), i was able to adapt the approach in the poise option_collector (switching the sub-resource block evaluation into a new context) and avoid this too-common and confusing error.

hip, hip, hooray!

now instead of:

systemd_service 'my-app' do
  user 'bob'
  unit do
    description 'my super-cool app'
  end
  install do
    wanted_by 'multi-user.target'
  end
  service do
    service_user 'my-user'
    exec_start '/usr/bin/my-app'
  end
end

we can do:

systemd_service 'my-app' do
  user 'bob'
  unit do
    description 'my super-cool app'
  end
  install do
    wanted_by 'multi-user.target'
  end
  service do
    user 'my-user'
    exec_start '/usr/bin/my-app'
  end
end