DSC icon indicating copy to clipboard operation
DSC copied to clipboard

Implement `variables` support

Open SteveL-MSFT opened this issue 2 years ago • 4 comments

Summary of the new feature / enhancement

Enable config to define and pass variables. Need to figure out how this is passed to group resources.

Proposed technical implementation details (optional)

No response

SteveL-MSFT avatar Apr 05 '23 15:04 SteveL-MSFT

Docs for variables in ARM templates: https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/variables

Variables should not pass to a nested config (group). If the nested config needs these, it should define parameters and the variables can be passes as params.

Bpoe avatar May 08 '23 21:05 Bpoe

Totally agree, if the group resource is in a seperate file. Does ARM have a solution for nesting within the same JSON/Bicep template, to consider parity? I can't think of a workable example.

A big issue with this in the past has been whether variables should be expanded at compilation or run time. Most people seemed to be confused when they expanded at compilation time. (it's also why DSC extension compiles on the target, which is not ideal)

For machine config integration, is there an Azure service that could host variables, similar to how ADO centrally stores variables for use in build scripts? Azure Configuration, maybe? I tested it a while back and the data plane operations where pretty much raw REST calls...

mgreenegit avatar Jun 21 '23 18:06 mgreenegit

In ARM template deployments, each template is a separate deployment. A nested template, whether its in its own file or inline, is a separate deployment that does not share any state with any other deployments. Variables are only used in that deployment and are not shared anywhere else. Think of it like a C# method. Any variable that is declared inside a method is scoped to that method only. If that method (M1) makes a call to another method (M2), M2 cannot see the variables in M1. You would need to pass the values in via parameters to M2.

Bpoe avatar Jun 21 '23 18:06 Bpoe

Here is an example to consider https://github.com/Azure/azure-quickstart-templates/blob/3d8a68489ff6d8f0420183501a9c16d38bc45cdd/demos/vmss-win-iis-app-ssl/dsc/serviceDSCVMSS.ps1#L143

mgreenegit avatar Feb 05 '24 14:02 mgreenegit

This was fixed via https://github.com/PowerShell/DSC/pull/511

SteveL-MSFT avatar Oct 08 '24 16:10 SteveL-MSFT