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

what-if missing resources created in a nested deployment with a copy expression #155

Closed
alex-frankel opened this issue Feb 12, 2021 · 1 comment
Labels
preflight improvement issue requires a change to preflight API

Comments

@alex-frankel
Copy link
Contributor

alex-frankel commented Feb 12, 2021

Discovered running what-if using bicep integrated with az cli. What-if does not see that I am deploying two websites in the nested deployment.

Here is the JSON that is being deployed:

{
  "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "functions": [],
  "variables": {
    "websites": [
      {
        "name": "fancy",
        "tag": "latest"
      },
      {
        "name": "plain",
        "tag": "plain-text"
      }
    ]
  },
  "resources": [
    {
      "type": "Microsoft.Resources/resourceGroups",
      "apiVersion": "2020-06-01",
      "name": "adotfrank-ignite21",
      "location": "[deployment().location]"
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2019-10-01",
      "name": "appPlanDeploy",
      "resourceGroup": "adotfrank-ignite21",
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "inner"
        },
        "mode": "Incremental",
        "parameters": {
          "namePrefix": {
            "value": "adotfrank"
          }
        },
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {
            "namePrefix": {
              "type": "string"
            },
            "sku": {
              "type": "string",
              "defaultValue": "B1"
            }
          },
          "functions": [],
          "resources": [
            {
              "type": "Microsoft.Web/serverfarms",
              "apiVersion": "2020-06-01",
              "name": "[format('{0}-plan', parameters('namePrefix'))]",
              "location": "[resourceGroup().location]",
              "kind": "linux",
              "sku": {
                "name": "[parameters('sku')]"
              },
              "properties": {
                "reserved": true
              }
            }
          ],
          "outputs": {
            "planId": {
              "type": "string",
              "value": "[resourceId('Microsoft.Web/serverfarms', format('{0}-plan', parameters('namePrefix')))]"
            }
          }
        }
      },
      "dependsOn": [
        "[subscriptionResourceId('Microsoft.Resources/resourceGroups', 'adotfrank-ignite21')]"
      ]
    },
    {
      "copy": {
        "name": "siteDeploy",
        "count": "[length(variables('websites'))]"
      },
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2019-10-01",
      "name": "[format('{0}siteDeploy', variables('websites')[copyIndex()].name)]",
      "resourceGroup": "adotfrank-ignite21",
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "inner"
        },
        "mode": "Incremental",
        "parameters": {
          "appPlanId": {
            "value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, 'adotfrank-ignite21'), 'Microsoft.Resources/deployments', 'appPlanDeploy'), '2019-10-01').outputs.planId.value]"
          },
          "namePrefix": {
            "value": "[variables('websites')[copyIndex()].name]"
          },
          "dockerImage": {
            "value": "nginxdemos/hello"
          },
          "dockerImageTag": {
            "value": "[variables('websites')[copyIndex()].tag]"
          }
        },
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {
            "namePrefix": {
              "type": "string"
            },
            "location": {
              "type": "string",
              "defaultValue": "[resourceGroup().location]"
            },
            "dockerImage": {
              "type": "string"
            },
            "dockerImageTag": {
              "type": "string"
            },
            "appPlanId": {
              "type": "string"
            }
          },
          "functions": [],
          "resources": [
            {
              "type": "Microsoft.Web/sites",
              "apiVersion": "2020-06-01",
              "name": "[format('{0}-site', parameters('namePrefix'))]",
              "location": "[parameters('location')]",
              "properties": {
                "siteConfig": {
                  "appSettings": [
                    {
                      "name": "DOCKER_REGISTRY_SERVER_URL",
                      "value": "https://index.docker.io"
                    },
                    {
                      "name": "DOCKER_REGISTRY_SERVER_USERNAME",
                      "value": ""
                    },
                    {
                      "name": "DOCKER_REGISTRY_SERVER_PASSWORD",
                      "value": ""
                    },
                    {
                      "name": "WEBSITES_ENABLE_APP_SERVICE_STORAGE",
                      "value": "false"
                    }
                  ],
                  "linuxFxVersion": "[format('DOCKER|{0}:{1}', parameters('dockerImage'), parameters('dockerImageTag'))]"
                },
                "serverFarmId": "[parameters('appPlanId')]"
              }
            }
          ]
        }
      },
      "dependsOn": [
        "[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, 'adotfrank-ignite21'), 'Microsoft.Resources/deployments', 'appPlanDeploy')]",
        "[subscriptionResourceId('Microsoft.Resources/resourceGroups', 'adotfrank-ignite21')]"
      ]
    }
  ]
}
@ghost ghost added the Needs Triage 🔍 label Feb 12, 2021
@alex-frankel alex-frankel added preflight improvement issue requires a change to preflight API and removed Needs Triage 🔍 labels Feb 18, 2021
@alex-frankel
Copy link
Contributor Author

closing, correct diagnosis is in #157

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preflight improvement issue requires a change to preflight API
Projects
None yet
Development

No branches or pull requests

1 participant