Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top scope variable are rewritten into fact references #195

Open
brunoleon opened this issue Mar 7, 2024 · 5 comments
Open

Top scope variable are rewritten into fact references #195

brunoleon opened this issue Mar 7, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@brunoleon
Copy link

Describe the Bug

The PR #190 introduces a bug that prevent reference to top scope variables by rewriting into a reference to a fact

$::example_var => save => $facts['example_var']

Expected Behavior

$::example_var => save => $::example_var
(nothing to change)

Steps to Reproduce

Open VScode and enable Puppet Vscode Extension
Write a manifests referencing a top scope variable.
It is rewritten into a reference to a fact.

Environment

Since Puppet VSCode extension 1.5.0

@brunoleon brunoleon added the bug Something isn't working label Mar 7, 2024
@kenyon
Copy link

kenyon commented Mar 11, 2024

Seems correct to me. What top scope variables are you using?

@brunoleon
Copy link
Author

The vscode extension assumes that all top scope variables are facts, which is not true.

You can have a variable defined in you "entrypoint" manifest that defines a variable to be used globally.

I'm not meaning this is the right thing to do (and I would even advise against...), however the current behavior prevents you from doing something that is possible in the language.

For example on one setup involving arm devices, I have the following piece of code because of repository naming;

//nodes.pp
$arch = $facts['os']['architecture'] ? {
  'aarch64' => 'arm64',
  'aarch'   => 'arm',
  default   => $facts['os']['architecture']
}

Current VSCode behavior prevents me from referring to this variable, it keeps turning it into a facts, which it is not.

Hope this makes sense

@kenyon
Copy link

kenyon commented Mar 12, 2024

In that case, shouldn't you be referring to it as $nodes::arch when used in other classes?

@brunoleon
Copy link
Author

node.pp is an example entrypoint, may be be calling it site.pp would have been clearer but it is not a class

The documentation is here: https://www.puppet.com/docs/puppet/8/lang_scope.html#top-scope

Notably: Because the top scope’s name is the empty string, $::my_variable refers to the top-scope value of $my_variable, even if $my_variable has a different value in local scope.

Which clearly states that we must be able to access top scope variables.

@kenyon
Copy link

kenyon commented Mar 12, 2024

OK I see. I don't use top scope variables from a site.pp like that, so thanks for elaborating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants