From 3eaa64e5f18ae506db2fee0c741b01b1585a8c20 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Wed, 16 Oct 2019 17:09:04 -0700 Subject: [PATCH] Update Resource DSL doco to reflect lazy loading. Signed-off-by: Ryan Davis --- docs/dsl_resource.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/dsl_resource.md b/docs/dsl_resource.md index a041a7fbe..9e1df0e31 100644 --- a/docs/dsl_resource.md +++ b/docs/dsl_resource.md @@ -98,3 +98,32 @@ end ``` For a full example, see our [example resource](https://github.com/chef/inspec/blob/master/examples/profile/libraries/example_config.rb). + +## Lazy Loading + +Prior to InSpec v4.16, resources were pre-loaded for every invocation +of `inspec`. This was a heavy and unnecessary burden on the system and +exacerbated startup times (especially on Windows). + +As of InSpec v4.16, resources are lazily loaded into the `inspec` +process upon use. This greatly speeds up the initial startup costs of +the `inspec` process and only loads what you need to use (eg, `inspec +--version` no longer runs for 10 seconds!). + +### Overriding Core Resources + +Lazy loading does change the way the resource registry is handled in +ways that might break some assumptions. Specifically, +`inspec.` isn't pre-populated with the core resources that +InSpec ships with. If you make a local/custom resource of the same +name, referring to the core resource via `inspec.` will not +resolve to the core resource. + +As such, overriding core resources is not recommended best practice. + +If you really do need to do this, it is easiest to make a local +resource with a new name and refer to the core resource directly. +Otherwise, you need to ensure that the core resource you want is +registered (via `require "inspec/resource/"`) _before_ your +profile is run to ensure it is eagerly loaded and in the global +resource registry.