Azure / bicep

Bicep is a declarative language for describing and deploying Azure resources
MIT License
3.21k stars 745 forks source link

Bicep decompile Doesn't like 'metadata' resource property #5258

Closed bzabber closed 1 year ago

bzabber commented 2 years ago

Bicep version run bicep --version via the Bicep CLI, az bicep version via the AZ CLI or via VS code by navigating to the extensions tab and searching for Bicep Bicep CLI version 0.4.1008 (223b8d227a) VSCode Extension version: v0.4.1008

Describe the bug When attempting to decompile the ARM template found here, I get the following error from Bicep CLI: " Decompilation failed with fatal error "[253:23]: Unrecognized top-level resource property 'metadata'""

To Reproduce Steps to reproduce the behavior: Copy the ARM template from the above link and save it as an ARM template (deploy.json). within VSCode terminal go to where you saved the deploy.json and run: bicep decompile deploy.json --outfile deploy.bicep

StephenWeatherford commented 1 year ago

Same for templates, nested templates, resources...

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.9.1.41621",
      "templateHash": "14981122793425715178"
    }
  },
  "parameters": {
    "skuName": {
      "type": "string",
      "metadata": {
        "description": "Name of Azure CDN SKU"
      },
      "allowedValues": [
        "Premium_AzureFrontDoor",
        "Standard_AzureFrontDoor"
      ]
    },
    "cdnProfileName": {
      "type": "string",
      "metadata": {
        "description": "Name of CDN Profile"
      }
    },
    "afdEndpointName": {
      "type": "string",
      "metadata": {
        "description": "AFD Endpoint Name"
      }
    },
    "enableAfdEndpoint": {
      "type": "bool",
      "metadata": {
        "description": "AFD Endpoint State"
      }
    },
    "cdnProfileTags": {
      "type": "object",
      "metadata": {
        "description": "Tags to identify resource owner"
      }
    },
    "customDomains": {
      "type": "array",
      "metadata": {
        "description": "Custom Domain List"
      }
    },
    "origins": {
      "type": "array",
      "metadata": {
        "description": "Origin List"
      }
    },
    "eventHubName": {
      "type": "string",
      "metadata": {
        "description": "Event Hub Name"
      }
    },
    "eventHubNamespace": {
      "type": "string",
      "metadata": {
        "description": "Event Hub Namespace Name"
      }
    },
    "eventHubLocation": {
      "type": "string",
      "metadata": {
        "description": "Event Hub Namespace location"
      }
    },
    "wafPolicyName": {
      "type": "string",
      "metadata": {
        "description": "Name of the WAF policy to create."
      }
    },
    "wafPolicyId": {
      "type": "string",
      "metadata": {
        "description": "Id of the WAF policy to attach"
      }
    }
  },
  "variables": {
    "copy": [
      {
        "name": "customDomainIds",
        "count": "[length(parameters('customDomains'))]",
        "input": {
          "id": "[resourceId('Microsoft.Cdn/profiles/customDomains', parameters('cdnProfileName'), replace(parameters('customDomains')[copyIndex('customDomainIds')].hostname, '.', '-'))]"
        }
      }
    ],
    "afdEndpointIds": [
      {
        "id": "[resourceId('Microsoft.Cdn/profiles/afdEndpoints', parameters('cdnProfileName'), parameters('afdEndpointName'))]"
      }
    ],
    "endPointIdsForWaf": "[union(variables('customDomainIds'), variables('afdEndpointIds'))]"
  },
  "resources": [
    {
      "type": "Microsoft.Cdn/profiles",
      "apiVersion": "2021-06-01",
      "name": "[parameters('cdnProfileName')]",
      "location": "Global",
      "tags": "[parameters('cdnProfileTags')]",
      "sku": {
        "name": "[parameters('skuName')]"
      },
      "properties": {
        "originResponseTimeoutSeconds": 60
      },
      "metadata": {
        "description": "Create CDN Profile"
      }
    },
    {
      "type": "Microsoft.Cdn/profiles/afdEndpoints",
      "apiVersion": "2021-06-01",
      "name": "[format('{0}/{1}', parameters('cdnProfileName'), parameters('afdEndpointName'))]",
      "location": "Global",
      "properties": {
        "enabledState": "[if(parameters('enableAfdEndpoint'), 'Enabled', 'Disabled')]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Cdn/profiles', parameters('cdnProfileName'))]"
      ],
      "metadata": {
        "description": "Create AFD Endpoint"
      }
    },
    {
      "copy": {
        "name": "custom_domains",
        "count": "[length(parameters('customDomains'))]"
      },
      "type": "Microsoft.Cdn/profiles/customDomains",
      "apiVersion": "2021-06-01",
      "name": "[format('{0}/{1}', parameters('cdnProfileName'), replace(parameters('customDomains')[copyIndex()].hostname, '.', '-'))]",
      "properties": {
        "hostName": "[parameters('customDomains')[copyIndex()].hostname]",
        "tlsSettings": {
          "certificateType": "ManagedCertificate",
          "minimumTlsVersion": "TLS12"
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Cdn/profiles', parameters('cdnProfileName'))]"
      ],
      "metadata": {
        "description": "Create Custom Domains to be used for CDN profile"
      }
    },
    {
      "copy": {
        "name": "origin_groups",
        "count": "[length(parameters('origins'))]"
      },
      "type": "Microsoft.Cdn/profiles/originGroups",
      "apiVersion": "2021-06-01",
      "name": "[format('{0}/{1}', parameters('cdnProfileName'), parameters('origins')[copyIndex()].originGroupName)]",
      "properties": {
        "loadBalancingSettings": {
          "sampleSize": 4,
          "successfulSamplesRequired": 3,
          "additionalLatencyInMilliseconds": 50
        },
        "healthProbeSettings": {
          "probePath": "/",
          "probeRequestType": "GET",
          "probeProtocol": "Https",
          "probeIntervalInSeconds": 100
        },
        "sessionAffinityState": "Disabled"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Cdn/profiles', parameters('cdnProfileName'))]"
      ],
      "metadata": {
        "description": "List of Origin Groups"
      }
    },
    {
      "copy": {
        "name": "cdn_origins",
        "count": "[length(parameters('origins'))]"
      },
      "type": "Microsoft.Cdn/profiles/originGroups/origins",
      "apiVersion": "2021-06-01",
      "name": "[format('{0}/{1}/{2}', parameters('cdnProfileName'), parameters('origins')[copyIndex()].originGroupName, replace(parameters('origins')[copyIndex()].hostname, '.', '-'))]",
      "properties": {
        "hostName": "[parameters('origins')[copyIndex()].hostname]",
        "httpPort": 80,
        "httpsPort": 443,
        "originHostHeader": "[parameters('origins')[copyIndex()].hostname]",
        "priority": 1,
        "weight": 1000,
        "enabledState": "[if(parameters('origins')[copyIndex()].enabledState, 'Enabled', 'Disabled')]",
        "enforceCertificateNameCheck": true
      },
      "dependsOn": [
        "[resourceId('Microsoft.Cdn/profiles/originGroups', parameters('cdnProfileName'), parameters('origins')[copyIndex()].originGroupName)]"
      ],
      "metadata": {
        "description": "List of origin and mapping to Origin Groups"
      }
    },
    {
      "type": "Microsoft.Cdn/profiles/securityPolicies",
      "apiVersion": "2021-06-01",
      "name": "[format('{0}/{1}', parameters('cdnProfileName'), parameters('wafPolicyName'))]",
      "properties": {
        "parameters": {
          "wafPolicy": {
            "id": "[parameters('wafPolicyId')]"
          },
          "associations": [
            {
              "domains": "[variables('endPointIdsForWaf')]",
              "patternsToMatch": [
                "/*"
              ]
            }
          ],
          "type": "WebApplicationFirewall"
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Cdn/profiles/afdEndpoints', parameters('cdnProfileName'), parameters('afdEndpointName'))]",
        "[resourceId('Microsoft.Cdn/profiles', parameters('cdnProfileName'))]",
        "custom_domains"
      ],
      "metadata": {
        "description": "Attach WAF for Security policy"
      }
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2020-10-01",
      "name": "[format('{0}-eventhub-module', parameters('cdnProfileName'))]",
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "inner"
        },
        "mode": "Incremental",
        "parameters": {
          "eventHubNameSpace": {
            "value": "[parameters('eventHubNamespace')]"
          },
          "eventHubName": {
            "value": "[parameters('eventHubName')]"
          },
          "eventHubLocation": {
            "value": "[parameters('eventHubLocation')]"
          }
        },
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "metadata": {
            "_generator": {
              "name": "bicep",
              "version": "0.9.1.41621",
              "templateHash": "10011087564064102984"
            }
          },
          "parameters": {
            "eventHubNameSpace": {
              "type": "string",
              "metadata": {
                "description": "Event Hub Namespace Name"
              }
            },
            "eventHubName": {
              "type": "string",
              "metadata": {
                "description": "Event Hub Name"
              }
            },
            "eventHubLocation": {
              "type": "string",
              "metadata": {
                "description": "Event Hub Namespace location"
              }
            }
          },
          "resources": [
            {
              "type": "Microsoft.EventHub/namespaces",
              "apiVersion": "2022-01-01-preview",
              "name": "[parameters('eventHubNameSpace')]",
              "location": "[parameters('eventHubLocation')]",
              "sku": {
                "name": "Standard",
                "tier": "Standard",
                "capacity": 20
              },
              "properties": {
                "minimumTlsVersion": "1.0",
                "publicNetworkAccess": "Enabled",
                "disableLocalAuth": false,
                "zoneRedundant": false,
                "isAutoInflateEnabled": true,
                "maximumThroughputUnits": 20,
                "kafkaEnabled": true
              }
            },
            {
              "type": "Microsoft.EventHub/namespaces/authorizationRules",
              "apiVersion": "2022-01-01-preview",
              "name": "[format('{0}/{1}', parameters('eventHubNameSpace'), 'RootManageSharedAccessKey')]",
              "properties": {
                "rights": [
                  "Listen",
                  "Manage",
                  "Send"
                ]
              },
              "dependsOn": [
                "[resourceId('Microsoft.EventHub/namespaces', parameters('eventHubNameSpace'))]"
              ]
            },
            {
              "type": "Microsoft.EventHub/namespaces/eventhubs",
              "apiVersion": "2022-01-01-preview",
              "name": "[format('{0}/{1}', parameters('eventHubNameSpace'), parameters('eventHubName'))]",
              "properties": {
                "messageRetentionInDays": 1,
                "partitionCount": 20,
                "status": "Active"
              },
              "dependsOn": [
                "[resourceId('Microsoft.EventHub/namespaces', parameters('eventHubNameSpace'))]"
              ]
            },
            {
              "type": "Microsoft.EventHub/namespaces/networkRuleSets",
              "apiVersion": "2022-01-01-preview",
              "name": "[format('{0}/{1}', parameters('eventHubNameSpace'), 'default')]",
              "properties": {
                "publicNetworkAccess": "Enabled",
                "defaultAction": "Allow"
              },
              "dependsOn": [
                "[resourceId('Microsoft.EventHub/namespaces', parameters('eventHubNameSpace'))]"
              ]
            },
            {
              "type": "Microsoft.EventHub/namespaces/eventhubs/consumergroups",
              "apiVersion": "2022-01-01-preview",
              "name": "[format('{0}/{1}/{2}', parameters('eventHubNameSpace'), parameters('eventHubName'), '$Default')]",
              "dependsOn": [
                "[resourceId('Microsoft.EventHub/namespaces/eventhubs', parameters('eventHubNameSpace'), parameters('eventHubName'))]"
              ]
            }
          ],
          "outputs": {
            "eventHubName": {
              "type": "string",
              "value": "[parameters('eventHubName')]"
            },
            "eventHubAuthId": {
              "type": "string",
              "value": "[resourceId('Microsoft.EventHub/namespaces/authorizationRules', parameters('eventHubNameSpace'), 'RootManageSharedAccessKey')]"
            }
          }
        }
      },
      "metadata": {
        "description": "Create EventHub."
      }
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2020-10-01",
      "name": "[format('{0}-rulesets-module', parameters('cdnProfileName'))]",
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "inner"
        },
        "mode": "Incremental",
        "parameters": {
          "cdnProfileName": {
            "value": "[parameters('cdnProfileName')]"
          }
        },
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "metadata": {
            "_generator": {
              "name": "bicep",
              "version": "0.9.1.41621",
              "templateHash": "13124418295169759821"
            }
          },
          "parameters": {
            "cdnProfileName": {
              "type": "string",
              "metadata": {
                "description": "Name of CDN Profile. For chaining, use output from parent module"
              }
            }
          },
          "resources": [
            {
              "type": "Microsoft.Cdn/profiles/ruleSets",
              "apiVersion": "2021-06-01",
              "name": "[format('{0}/{1}', parameters('cdnProfileName'), 'Global')]",
              "metadata": {
                "description": "Default ruleset"
              }
            },
            {
              "type": "Microsoft.Cdn/profiles/ruleSets/rules",
              "apiVersion": "2021-06-01",
              "name": "[format('{0}/{1}/{2}', parameters('cdnProfileName'), 'Global', 'OverwriteResponseHeaders')]",
              "properties": {
                "order": 1,
                "actions": [
                  {
                    "name": "ModifyResponseHeader",
                    "parameters": {
                      "typeName": "DeliveryRuleHeaderActionParameters",
                      "headerAction": "Overwrite",
                      "headerName": "X-CDN",
                      "value": "AZUR"
                    }
                  },
                  {
                    "name": "RouteConfigurationOverride",
                    "parameters": {
                      "typeName": "DeliveryRuleRouteConfigurationOverrideActionParameters",
                      "cacheConfiguration": {
                        "isCompressionEnabled": "Enabled",
                        "queryStringCachingBehavior": "UseQueryString",
                        "cacheBehavior": "OverrideIfOriginMissing",
                        "cacheDuration": "365.00:00:00"
                      }
                    }
                  }
                ],
                "matchProcessingBehavior": "Continue"
              },
              "dependsOn": [
                "[resourceId('Microsoft.Cdn/profiles/ruleSets', parameters('cdnProfileName'), 'Global')]"
              ],
              "metadata": {
                "description": "Modify other request-response headers and add to global rulesets"
              }
            }
          ],
          "outputs": {
            "defaultRuleSetId": {
              "type": "string",
              "value": "[resourceId('Microsoft.Cdn/profiles/ruleSets', parameters('cdnProfileName'), 'Global')]"
            }
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Cdn/profiles', parameters('cdnProfileName'))]"
      ],
      "metadata": {
        "description": "Default Rule Sets."
      }
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2020-10-01",
      "name": "[format('{0}-monitoring-module', parameters('cdnProfileName'))]",
      "properties": {
        "expressionEvaluationOptions": {
          "scope": "inner"
        },
        "mode": "Incremental",
        "parameters": {
          "cdnProfileName": {
            "value": "[parameters('cdnProfileName')]"
          },
          "eventHubName": {
            "value": "[reference(resourceId('Microsoft.Resources/deployments', format('{0}-eventhub-module', parameters('cdnProfileName')))).outputs.eventHubName.value]"
          },
          "eventHubAuthId": {
            "value": "[reference(resourceId('Microsoft.Resources/deployments', format('{0}-eventhub-module', parameters('cdnProfileName')))).outputs.eventHubAuthId.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.9.1.41621",
              "templateHash": "291091334959894439"
            }
          },
          "parameters": {
            "cdnProfileName": {
              "type": "string",
              "metadata": {
                "description": "Name of CDN Profile. For chaining, use output from parent module"
              }
            },
            "eventHubName": {
              "type": "string",
              "metadata": {
                "description": "Event Hub Name"
              }
            },
            "eventHubAuthId": {
              "type": "string",
              "metadata": {
                "description": "Event Hub AuthId"
              }
            }
          },
          "variables": {
            "diagnosticSettings": [
              {
                "name": "azure-afd-cdn-logs-diagnostic-settings",
                "eventHub": "[parameters('eventHubName')]",
                "eventHubAuthorizationRuleId": "[parameters('eventHubAuthId')]",
                "logSettings": [
                  {
                    "name": "FrontDoorAccessLog",
                    "enabled": true
                  },
                  {
                    "name": "FrontDoorWebApplicationFirewallLog",
                    "enabled": false
                  },
                  {
                    "name": "FrontDoorHealthProbeLog",
                    "enabled": false
                  }
                ]
              }
            ]
          },
          "resources": [
            {
              "copy": {
                "name": "diagnostic_setting",
                "count": "[length(variables('diagnosticSettings'))]"
              },
              "type": "Microsoft.Insights/diagnosticSettings",
              "apiVersion": "2021-05-01-preview",
              "scope": "[format('Microsoft.Cdn/profiles/{0}', parameters('cdnProfileName'))]",
              "name": "[variables('diagnosticSettings')[copyIndex()].name]",
              "properties": {
                "copy": [
                  {
                    "name": "logs",
                    "count": "[length(variables('diagnosticSettings')[copyIndex()].logSettings)]",
                    "input": {
                      "category": "[variables('diagnosticSettings')[copyIndex()].logSettings[copyIndex('logs')].name]",
                      "enabled": "[variables('diagnosticSettings')[copyIndex()].logSettings[copyIndex('logs')].enabled]",
                      "retentionPolicy": {
                        "enabled": false,
                        "days": 0
                      }
                    }
                  }
                ],
                "eventHubName": "[variables('diagnosticSettings')[copyIndex()].eventHub]",
                "eventHubAuthorizationRuleId": "[variables('diagnosticSettings')[copyIndex()].eventHubAuthorizationRuleId]",
                "metrics": [
                  {
                    "category": "AllMetrics",
                    "enabled": false,
                    "retentionPolicy": {
                      "enabled": false,
                      "days": 0
                    }
                  }
                ]
              }
            }
          ]
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Cdn/profiles', parameters('cdnProfileName'))]",
        "[resourceId('Microsoft.Resources/deployments', format('{0}-eventhub-module', parameters('cdnProfileName')))]"
      ],
      "metadata": {
        "description": "Create Diagnostic Settings for Logs"
      }
    }
  ],
  "outputs": {
    "cdnName": {
      "type": "string",
      "value": "[parameters('cdnProfileName')]"
    },
    "afdEndpointName": {
      "type": "string",
      "value": "[parameters('afdEndpointName')]"
    },
    "afdEndpointHostName": {
      "type": "string",
      "value": "[reference(resourceId('Microsoft.Cdn/profiles/afdEndpoints', parameters('cdnProfileName'), parameters('afdEndpointName'))).hostName]"
    },
    "defaultRuleSets": {
      "type": "string",
      "value": "[reference(resourceId('Microsoft.Resources/deployments', format('{0}-rulesets-module', parameters('cdnProfileName')))).outputs.defaultRuleSetId.value]"
    }
  }
}