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

Unexpected results in Parameter-Types-Should-Be-Consistent #665

Open
anagyzambo-kx opened this issue Jul 25, 2022 · 1 comment
Open

Unexpected results in Parameter-Types-Should-Be-Consistent #665

anagyzambo-kx opened this issue Jul 25, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@anagyzambo-kx
Copy link

Hi All,

Thanks for creating the validation tool.
I have found that there are 2 edge cases in Parameter-Types-Should-Be-Consistent where we are not getting the expected behavior:

1. Nested deployment output of type int -> nested deployment input of type string should fail

Template:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {},
    "resources": [
        {
            "name": "nestedDeployment1",
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2021-04-01",
            "properties": {
                "expressionEvaluationOptions": {
                    "scope": "inner"
                },
                "mode": "Incremental",
                "parameters": {},
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {},
                    "variables": {},
                    "resources": [],
                    "outputs": {
                        "output1": {
                            "type": "int",
                            "value": 1
                        }
                    }
                }
            }
        },
        {
            "name": "nestedDeployment2",
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2021-04-01",
            "properties": {
                "expressionEvaluationOptions": {
                    "scope": "inner"
                },
                "mode": "Incremental",
                "parameters": {
                    "parameter1": {
                        "value": "[reference(resourceId('Microsoft.Resources/deployments', 'nestedDeployment1')).outputs.output1.value]"
                    }
                },
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "parameter1": {
                            "type": "string",
                            "metadata": {
                                "description": "description"
                            }
                        }
                    },
                    "variables": {},
                    "resources": [],
                    "outputs": {}
                }
            }
        }
    ],
    "outputs": {}
}

Test results:

$ pwsh --Command 'Import-Module .\arm-ttk\arm-ttk.psd1 -Force; ./unit-tests/Parameter-Types-Should-Be-Consistent/Parameter-Types-Should-Be-Consistent.tests.ps1'

Describing Parameter-Types-Should-Be-Consistent

  Context Fail
    [+] Validates grandchild is flagged 1.09s
    [+] Validates InconsistentParameterTypes is flagged 65ms
    [-] Validates InconsistentParameterTypesOutput is flagged 100ms
      RuntimeException: Errors were expected
      at <ScriptBlock>, /home/nagyako/arm-ttk/arm-ttk/unit-tests/arm-ttk.test.functions.ps1: line 131

The deployment fails with the below error:
image

"Deployment template validation failed: 'Template parameter 'parameter1' was provided an invalid value. Expected a value of type 'String, Uri', but received a value of type 'Integer'. Please see https://aka.ms/resource-manager-parameter-files for usage details.'.

2. Nested deployment output of type array -> nested deployment input of type array should pass

Template:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.8.9.13224",
      "templateHash": "12511175399169845925"
    }
  },
  "parameters": {
    "project": {
      "type": "string",
      "defaultValue": "Foo"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2020-10-01",
      "name": "[format('{0}nestedDeployment1', parameters('project'))]",
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "inner"
        },
        "mode": "Incremental",
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "metadata": {
            "_generator": {
              "name": "bicep",
              "version": "0.8.9.13224",
              "templateHash": "4279842583979532621"
            }
          },
          "resources": [
            {
              "copy": {
                "name": "nestedDeployments",
                "count": "[length(range(0, 2))]"
              },
              "type": "Microsoft.Resources/deployments",
              "apiVersion": "2021-04-01",
              "name": "[format('nestedDeployment{0}', range(0, 2)[copyIndex()])]",
              "properties": {
                "mode": "Incremental",
                "template": {
                  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                  "contentVersion": "1.0.0.0",
                  "resources": []
                }
              }
            }
          ],
          "outputs": {
            "deploymentNames": {
              "type": "array",
              "copy": {
                "count": "[length(range(0, 2))]",
                "input": "[format('nestedDeployment{0}', range(0, 2)[range(0, 2)[copyIndex()]])]"
              }
            }
          }
        }
      }
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2020-10-01",
      "name": "[format('{0}nestedDeployment2', parameters('project'))]",
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "inner"
        },
        "mode": "Incremental",
        "parameters": {
          "deploymentNames": {
            "value": "[reference(resourceId('Microsoft.Resources/deployments', format('{0}nestedDeployment1', parameters('project')))).outputs.deploymentNames.value]"
          }
        },
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "metadata": {
            "_generator": {
              "name": "bicep",
              "version": "0.8.9.13224",
              "templateHash": "11588361600448277843"
            }
          },
          "parameters": {
            "deploymentNames": {
              "type": "array"
            }
          },
          "resources": [
            {
              "type": "Microsoft.Resources/deployments",
              "apiVersion": "2021-04-01",
              "name": "[format('{0}a', parameters('deploymentNames')[0])]",
              "properties": {
                "mode": "Incremental",
                "template": {
                  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
                  "contentVersion": "1.0.0.0",
                  "resources": []
                }
              }
            }
          ]
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Resources/deployments', format('{0}nestedDeployment1', parameters('project')))]"
      ]
    }
  ]
}

Test results:

  Context Pass
    [+] Validates ConsistentParameterTypes is correct 61ms
    [-] Validates ConsistentParameterTypesOutput is correct 578ms
      RuntimeException: Write-Error: /home/nagyako/arm-ttk/arm-ttk/arm-ttk/Test-AzTemplate.ps1:253
      Line |
       253 |                      . $myModule $TheTest @testInput 2>&1 3>&1
           |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           | Type Mismatch: Parameter 'deploymentNames' in nested template '[format('{0}nestedDeployment2', parameters('project'))]' is defined as array, but the parent template defines it as string).

      at <ScriptBlock>, /home/nagyako/arm-ttk/arm-ttk/unit-tests/arm-ttk.test.functions.ps1: line 96
    [+] Validates grandchild is correct 77ms

The second template was generated from bicep and works fine:
image

If the referenced resource name is literal and does not contain a parameter like format('{0}nestedDeployment1', parameters('project')) then the test is passing.

@ghost ghost added the Needs: triage 🔍 label Jul 25, 2022
@bmoore-msft bmoore-msft added bug Something isn't working and removed Needs: triage 🔍 labels Jul 27, 2022
@aavdberg
Copy link

aavdberg commented Jan 3, 2024

Is there anything known about the status of this item?

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

3 participants