What is the correct way to create a resource in a provider?

asked 2018-10-19 10:24:08 -0600

avidspartan1 gravatar image

updated 2018-10-19 11:14:14 -0600

I'm currently writing a provider that acts as a "resource wrapper". Essentially, it takes a name, type, some parameters, and then creates a resource based on that.

I've been using Puppet::Resource.new(<type>, <name>, parameters: <parameters>), but it doesn't seem to take into account Sensitive parameters.

For example, I try to create a File resource, like so:

Puppet::Resource.new('file', '/root/.ssh/id_rsa', parameters: params)

If the params contain a Sensitive value, it gives me the following error:

Could not evaluate: Parameter content failed on File[/root/.ssh/id_ra]: Munging failed for value #<Sensitive [value redacted]> in class content: no implicit conversion of Puppet::Pops::Types::PSensitiveType::Sensitive into String

What resource creation call do I need to make for all parameters (sensitive or not) to be handled correctly?

EDIT: I need a custom type and provider because of what I'm trying to accomplish. I want to manage resources that need to reliably know a user's home directory. For example, I want to manage /home/<user>/.vimrc without knowing what that directory is beforehand. The new resource type is meant to "wrap" resources with the user's home directory. Writing a custom type and provider is the only way I know to do this.

edit retag flag offensive close merge delete