0

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.

carlspring
  • 31,231
  • 29
  • 115
  • 197
wonderful world
  • 10,969
  • 20
  • 97
  • 194
  • 1
    What issue do you have? – Krzysztof Madej Jul 18 '23 at 08:51
  • I don't know the ARM Template commands to create **Resource Group** with JSON template. – wonderful world Jul 18 '23 at 12:53
  • Did you see this https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/deploy-github-actions?tabs=userlevel ? – Krzysztof Madej Jul 18 '23 at 13:18
  • I followed those instructions to deploy resources in a **Resource Group**, but not how the **Resource Group** itself. The **Resource Group** is created using **Azure CLI** in the instructions. I don't want to use **Azure CLI** but use the JSON file like the resources can be deployed. – wonderful world Jul 18 '23 at 13:24

1 Answers1

1

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.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • Eventhough I have region name in the parameters file, I get the error: ```Run azure/arm-deploy@v1 with: scope: subscription subscriptionId: __ parameters: ./parameters-rg.json template: ./azure-ftp-rg.json failOnStdErr: true Changing subscription context... Error: Region must be set.``` – wonderful world Jul 19 '23 at 15:12
  • 1
    Could you share you parameters.json file? – Krzysztof Madej Jul 19 '23 at 16:00
  • Here is the parameters file: {"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#","contentVersion": "1.0.0.0","parameters": {"rgName": {"value": "xx.xx.ResourceGroup"}, "rgLocation": {"value": "eastus"},"tags": {"value": {}}}} – wonderful world Jul 19 '23 at 17:31
  • 1
    Please provide also region `region: Conditional Provide the target region, only required for Management Group or Subscription deployments.` – Krzysztof Madej Jul 19 '23 at 17:45
  • This is what I have for the resources. The region is set correctly. ```"resources": [{"type": "Microsoft.Resources/resourceGroups","apiVersion": "2018-05-01","region": "[parameters('rgLocation')]","name": "[parameters('rgName')]","properties": },"tags": "[parameters('tags')]"}]``` – wonderful world Jul 19 '23 at 19:33
  • 1
    azure/arm-deploy@v1 requires region parameter when scope is subscription. Check out my edit code. – Krzysztof Madej Jul 19 '23 at 22:04
  • After I added region to the scope and again the location in the ```resources.json``` file, the GitHub action succeeds and creates the resources. – wonderful world Jul 20 '23 at 11:36