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

Validation of template function "deployment" #1060

Closed
reijoh opened this issue Oct 20, 2020 · 7 comments · Fixed by #1098
Closed

Validation of template function "deployment" #1060

reijoh opened this issue Oct 20, 2020 · 7 comments · Fixed by #1098

Comments

@reijoh
Copy link

reijoh commented Oct 20, 2020

The ARM template documentation for deployment() ARM template function states that when you deploy to an Azure subscription, management group, or tenant, the return object includes a location property.

When using this property in an ARM template in VSCode, validation fail with the message:

Template validation failed: The template resource 'location' at line '17' and column '17' is not valid: The language expression property 'location' doesn't exist, available properties are 'name, properties'.. Please see https://aka.ms/arm-template-expressions for usage details.

Validation should take into account the schema used by the template and only fail validation for deployment().location if deploying to a resource group.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "policyDefinitionId": {
      "type": "string"
    },
    "parameters": {
      "type": "object"
    }
  },
  "variables": {},
  "resources": [
    {
      "type": "Microsoft.Authorization/policyAssignments",
      "apiVersion": "2019-09-01",
      "name": "mgname-test",
      "location": "[deployment().location]",
      "properties": {
        "displayName": "test",
        "description": "test",
        "scope": "/providers/Microsoft.Management/managementGroups/mgname",
        "policyDefinitionId": "[parameters('policyDefinitionId')]",
        "parameters": "[parameters('parameters')]",
        "metadata": {
          "assignedBy": "test"
        },
        "enforcementMode": "Default"
      }
    }
  ]
}
@StephenWeatherford
Copy link
Contributor

@reijoh Thanks for taking the time to enter. I would like to be able to distinguish these scenarios, sounds like it's time to make it happen.

@StephenWeatherford StephenWeatherford added this to the 0.14.0 milestone Oct 21, 2020
@StephenWeatherford
Copy link
Contributor

@jorgecotillo Turns out this is a validation message, not a message from the extension. Is this something that has already been fixed?

@StephenWeatherford
Copy link
Contributor

@jorgecotillo Still repros in the last private build you sent me

@jorgecotillo
Copy link
Collaborator

jorgecotillo commented Oct 30, 2020

was able to repro and is getting fixed along with #831

@jorgecotillo
Copy link
Collaborator

Btw @StephenWeatherford in case you are not already doing so, I'll need a deployment object to be passed in the metadata, it can contain any property but the object must exist like resourceGroup or subscription

@StephenWeatherford
Copy link
Contributor

Already doing that, thanks! But it looks like it needs to be updated for other scopes (e.g. "location" not currently included). I can do that once you provide a build.

        private readonly static string DeploymentObject =
        // See https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-deployment#deployment
        ObjectToString(new (string, string)[] {
                        ("name", Quote("deploymentName")),
                        ("properties", ObjectToString(new (string,string)[]
                        {
                            ("templateLink", ObjectToString(new (string,string)[] {
                                ("uri", Quote("https://fake/uri.json"))
                            })),
                            ("template", ObjectToString(new (string, string)[]
                            {
                                ("$schema", Quote("fakeSchema")),
                                ("contentVersion", Quote("fakeContentVersion")),
                                ("parameters", EmptyObject),
                                ("variables", EmptyObject),
                                ("resources", EmptyArray),
                                ("outputs", EmptyObject)
                            })),
                            ("parameters", EmptyObject),
                            ("mode", Quote("fakeMode")),
                            ("provisioningState", Quote("fakeProvisioningState")),
                            ("templateHash", Quote("fakeHash")),
                        }))
        });

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants