puppetlabs / puppet

Server automation framework and application
https://puppet.com/open-source/#osp
Apache License 2.0
7.45k stars 2.19k forks source link

Allow to create virtual resources dynamically #9363

Open vicinus opened 6 months ago

vicinus commented 6 months ago

Describe the Bug

Trying to create virtual resources dynamically results in an error, that the resource name does not conform to the naming rule:

puppet apply -e 'Resource["@File"] { "/tmp/test.txt": }'
Error: Evaluation Error: Illegal type reference. The given name '@file' does not conform to the naming rule (line: 1, column: 10) on node xyz

Expected Behavior

Should allow creating virtual resources like create_resources does.

Steps to Reproduce

puppet apply -e 'Resource["@file"] { "/tmp/test.txt": }'
Error: Evaluation Error: Illegal type reference. The given name '@file' does not conform to the naming rule (line: 1, column: 10) on node xyz

Environment

Tested with puppet agent 8.6.0

tvpartytonight commented 5 months ago

@vicinus I am not clear what you mean by the create_resources in the Expected Behavior section; do you think you could write some more detail in about that?

vicinus commented 5 months ago

I just meant, that with create_resources it is possible to create virtual resources dynamically, without an error:

puppet apply -e 'create_resources("@file", { "/tmp/test.txt" => {}})'
Notice: Compiled catalog for xyz in environment production in 0.02 seconds
Notice: Applied catalog in 0.02 seconds

If I understand the documentation of create_resources correctly, then the usage of create_resources is discouraged and the Resource version is preferred.