GitHub操作命令:从JSON ARM模板创建Azure资源组

huangapple go评论106阅读模式
英文:

GitHub Action command to create an Azure Resource Group from JSON ARM Template

问题

我正在尝试从ARM JSON模板中创建和删除Azure资源组。我手动尝试创建了一个资源组,并从Azure门户保存了模板。

以下是资源组的ARM模板的Json版本:

{
    "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
    "contentVersion": "1.0.0.1",
    "parameters": {
        "rgName": {
            "type": "string"
        },
        "rgLocation": {
            "type": "string"
        },
        "tags": {
            "type": "object",
            "defaultValue": {}
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Resources/resourceGroups",
            "apiVersion": "2018-05-01",
            "location": "[parameters('rgLocation')]",
            "name": "[parameters('rgName')]",
            "properties": {},
            "tags": "[parameters('tags')]"
        }
    ],
    "outputs": {}
}

我想要的是在部署资源之前创建一个资源组。之后我想销毁整个资源组以及其下的资源。

以下是部署资源到资源组的Workflow示例:

- name: 部署函数应用程序资源
    uses: azure/arm-deploy@v1
    with:
      scope: resourcegroup
      subscriptionId: ${{ env.AZURE_SUBSCRIPTION_ID }}
      resourceGroupName: ${{ env.AZURE_RESOURCE_GROUP }}
      parameters: ./parameters.json
      template: ./azure-deploy-function-api.json
英文:

I'm trying to create and delete an Azure Resource Group from the ARM JSON Template. I manually tried to create a Resource Group and saved the Template from the Azure Portal.

Here is the Json version of the ARM template for the Resource Group:

{
    "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
    "contentVersion": "1.0.0.1",
    "parameters": {
        "rgName": {
            "type": "string"
        },
        "rgLocation": {
            "type": "string"
        },
        "tags": {
            "type": "object",
            "defaultValue": {}
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Resources/resourceGroups",
            "apiVersion": "2018-05-01",
            "location": "[parameters('rgLocation')]",
            "name": "[parameters('rgName')]",
            "properties": {},
            "tags": "[parameters('tags')]"
        }
    ],
    "outputs": {}
}

I want is to create a Resource Group and later destroy the Resource Group from a GitHub Workflow. I have already some Workflow script to deploy resources in a Resource Group. An example is below:

 - name: Deploy Function App Resources
        uses: azure/arm-deploy@v1
        with:
          scope: resourcegroup
          subscriptionId: ${{ env.AZURE_SUBSCRIPTION_ID }}
          resourceGroupName: ${{ env.AZURE_RESOURCE_GROUP }}
          parameters: ./parameters.json
          template: ./azure-deploy-function-api.json          

What I want is to create the Resource Group before deploying the resources to it. Later I want destroy the whole Resource Group and the resources underneath it.

答案1

得分: 1

如果要部署资源组,您需要在此更改范围,然后您也不需要 resourceGroupName 参数(您不能在资源组范围内部署资源组)。

 - name: 部署函数应用资源
        uses: azure/arm-deploy@v1
        with:
          scope: 订阅
          subscriptionId: ${{ env.AZURE_SUBSCRIPTION_ID }}
          parameters: ./parameters.json
          template: ./azure-deploy-function-api.json
          region: 东部美国

在此处查看有关此 操作 的更多详细信息。

英文:

If you want to deploy resource group you need to change here the scope and then you also don't need resourceGroupName parameter. (You simply cannot deploy resource group in resource group scope).

 - name: Deploy Function App Resources
        uses: azure/arm-deploy@v1
        with:
          scope: subscription
          subscriptionId: ${{ env.AZURE_SUBSCRIPTION_ID }}
          parameters: ./parameters.json
          template: ./azure-deploy-function-api.json
          region: eastus

Here you find more details for this action.

huangapple
  • 本文由 发表于 2023年7月18日 08:15:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76708810.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定