Azure / template-specs

MIT License
31 stars 4 forks source link

Allow use of variables in relativepath within the TemplateSpec resource #56

Open kilasuit opened 3 years ago

kilasuit commented 3 years ago

As commented on in this issue https://github.com/microsoft/vscode-azurearmtools/issues/1323 I have a need where I am not hardcoding the path for the sub template being deployed with template specs, especially as requiring the value to be hardcoded breaks typical developer expectation of being able to use variables for data that is referenced many times in a template

As this stands it is a stopper when looking at any autogeneration (or automated manipluation) of templates by other tooling

alex-frankel commented 3 years ago

We can't allow this for parameters since we need to be able to resolve the paths at TS-create time, but we theoretically could allow it for variables. My guess is there are some technical blockers in resolving the variables at TS-create time since we only resolve the variables when the deployment starts.

cc @stuartko as FYI in case he has some more insights.

kilasuit commented 3 years ago

We can't allow this for parameters since we need to be able to resolve the paths at TS-create time - There is a pattern that we've used for years with API versions which is to pass through an APIVersion object from our top level templates into lower level ones. Could we potentially allow a TemplateSpecs parameter that can only allow an object that is defined like the below to be used in a similar manner at all?

example object definition

"TemplateSpecs": {
            "NSG": "./resourcegroups/resources/nsg.azuredeploy.json",
            "vnet": "./resourcegroups/resources/nsg.azuredeploy.json"
        }

I'm ideally looking for 1 place to make updates as opposed to potentially having many places, which reduces risk

stuartko commented 2 years ago

We want template specs to be able to be unpacked/packed to/from the file system in a consistent way that won't result in the artifact files changing depending on dynamic factors.

@kilasuit : One way you can retain consistent packing/unpacking but also support dynamic behavior at runtime is by using the condition property on the deployment for the artifact. For example:

    ...
    "resources": [
        {
        "condition": "[equals(parameters('typeOfArtifact'),'TypeA')]",
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2020-06-01",
            "name": "myArtifactDeployment",
            "location": "[parameters('myArtifactLocation')]",
            "properties": {
                "mode": "Incremental",
                "templateLink": {
                    "relativePath": "artifacts/myArtifact_TypeA.json",
                    "contentVersion": "1.0.0.0"
                },
                "parameters": {
                ...