简体   繁体   English

如何使用 Terraform 部署此 ARM 模板? 请指教

[英]How do I deploy this ARM template with Terraform? Please Advise

When I deploy this template via Terraform and Azure Devops, I get an Invalid template error while the template deploys normally on the portal.当我通过 Terraform 和 Azure Devops 部署此模板时,我收到 Invalid template 错误,而模板在门户上正常部署。 This is the error:这是错误:

'The template resource '' of type 'microsoft.insights/workbooks' at line '1' and column '1512' is not valid.第 1 行和第 1512 列的“microsoft.insights/workbooks”类型的“模板资源”无效。 The name property cannot be null or empty. name 属性不能为 null 或为空。 Please see https://aka.ms/arm-template/#resources for usage details.'." AdditionalInfo=[{"info":{"lineNumber":1,"linePosition":1512,"path":"properties.template.resources[0]"},"type":"TemplateViolation"}]使用详情请查看https://aka.ms/arm-template/#resources 。'。" AdditionalInfo=[{"info":{"lineNumber":1,"linePosition":1512,"path":"properties .template.resources[0]"},"type":"TemplateViolation"}]

What modification should I make to deploy via Terraform?通过 Terraform 部署我应该进行哪些修改?

{
    "contentVersion": "1.0.0.0",
    "parameters": {
      "workbookDisplayName": {
        "type": "string",
        "defaultValue": "Azure Firewall Workbook",
        "metadata": {
          "description": "The friendly name for the workbook that is used in the Gallery or Saved List.  This name must be unique within a resource group."
        }
      },
      "workbookType": {
        "type": "string",
        "allowedValues": [
            "workbook",
            "sentinel"
            
          ],
          "defaultValue": "workbook",
        "metadata": {
          "description": "The gallery that the workbook will been shown under. Supported values include workbook, tsg, etc. Usually, this is 'workbook'"
        }
      },
      "DiagnosticsWorkspaceName": {
        "type": "string",
        "defaultValue": "WorkspaceName",
        "metadata": {
          "description": "Provide the workspace name for your Network Diagnostic logs"
        }
      },
      "DiagnosticsWorkspaceSubscription": {
        "type": "string",
        "defaultValue": "WorkspaceSubscriptionID",
        "metadata": {
          "description": "Provide the workspace subscription GUID for your Network Diagnostic logs"
        }
      },
      "DiagnosticsWorkspaceResourceGroup": {
        "type": "string",
        "defaultValue": "ResourceGroupName",
        "metadata": {
          "description": "Provide the workspace resourcegroupname for your Network Diagnostic logs"
        }
      },
      "workbookId": {
        "type": "string",
        "defaultValue": "[newGuid()]",
        "metadata": {
          "description": "The unique guid for this workbook instance"
        }
      }
    },
    "variables": {
            "workbookSourceId": "[concat('/subscriptions/',parameters('DiagnosticsWorkspaceSubscription'),'/resourcegroups/', parameters('DiagnosticsWorkspaceResourceGroup'), '/providers/Microsoft.OperationalInsights/workspaces/',parameters('DiagnosticsWorkspaceName'))]"
  },
    "resources": [
      {
        "name": "[parameters('workbookId')]",
        "type": "microsoft.insights/workbooks",
        "location": "[resourceGroup().location]",
        "apiVersion": "2018-06-17-preview",
        "dependsOn": [],
        "kind": "shared",
        "properties": {
          "displayName": "[parameters('workbookDisplayName')]"}",
          "version": "1.0",
          "sourceId": "[variables('workbookSourceId')]",
          "category": "[parameters('workbookType')]"
        }
      }
    ],
    "outputs": {
      "workbookId": {
        "type": "string",
        "value": "[resourceId( 'microsoft.insights/workbooks', parameters('workbookId'))]"
      }
    },
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"
  }

I don't know ARM templates but I have really good experience on Terraform AWS & Terraform Azure providers.我不知道 ARM 模板,但我在 Terraform AWS 和 Terraform Z3A5813F142208867303677 提供商方面有很好的经验。

First of all, you better take a look from Terraform resource page which is here.首先,您最好从此处的 Terraform 资源页面查看。 That would be helpful in understanding resource needs and outcomes.这将有助于了解资源需求和成果。

I might be wrong, because I cannot see your Terraform script.我可能错了,因为我看不到您的 Terraform 脚本。 Nevertheless, I guess you might have an issue in Terraform side.不过,我猜你可能在 Terraform 方面有问题。 As I understood, you are getting error ARM template site.据我了解,您收到错误 ARM 模板站点。 It is complaining about missing name parameter which is mandatory.它抱怨缺少强制性的名称参数。 You may forget pass parameter names from Terraform to ARM template.您可能会忘记将参数名称从 Terraform 传递到 ARM 模板。 I can be wrong, this is just a suggestion, the correct way would be reviewing Terraform azurerm_template_deployment resource.我可能错了,这只是一个建议,正确的方法是查看 Terraform azurerm_template_deployment资源。

// ARM Template part
{
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "storageAccountType": {
          "type": "string",
          "defaultValue": "Standard_LRS",
          "allowedValues": [
            "Standard_LRS",
            "Standard_GRS",
            "Standard_ZRS"
          ],
          "metadata": {
            "description": "Storage Account type"
          }
        }
      },
// Terraform resource provisioning
      parameters = {
        "storageAccountType" = "Standard_GRS"
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM