ARM,  azure

ARM Lab 103 MS (param+ template)

Lets continue from ARM Lab 102

https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-tutorial-create-first-template?tabs=azure-powershell

With

8 Use quick start template

Quick start templates is a repository of templates, here we will use a website resource definition and add
it to the last template we used:
Folder Quick Start-templates contains:
azure deploy_exported.json
deploy_exported.ps1
The above template works for str.acc and app service plan, but we also want to add a website to it.
(App service plan is for build, deploy, and scale web apps and APIs)
Lets find a prebuilt JSON webapp.

Open the link to the repository

https://azure.microsoft.com/en-us/resources/templates/

Go to browse on git
Look at the azuredeploy.json
Scroll to the second last section with web/sites and edit the pre template with new JSON data

[...] param and vars was also edited
{
      "type": "Microsoft.Web/sites",
      "apiVersion": "2018-11-01",
      "name":"[variables('webAppPortalName')]",
      "location":"[parameters('location')]",
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', parameters('appServicePlan'))]"
      ],
      "kind":"app",
      "properties": {
        "serverFarmId":"[resourceId('Microsoft.Web/serverfarms',parameters('appServicePlan'))]",
        "siteConfig": {
          "linuxFxVersion":"[parameters('linuxFxVersion')]"
        }
      }
    }

  ],

Unique names, “webAppPortalName” has been changed to:
“[concat(parameters(‘webAppName’),uniqueString(resourceGroup().id))]”
and add a comma at the end of Microsoft.Web/serverfarms to separate the defintion from the
Microsoft.Web/sites defintion

dependsOn is set to app service plan, is required due to that the app service plan must exists before the web app is to be created.
dependsOn is the order for the RM to deploy

Lets deploy it or test it first with -whatif

Hm, suddenly the Connect-AzAccount did not connect, several errors and yet still the context is there and I am logged in to the portal.

******************************** NA this start

Fix was to remove (in to del folder), restart, login to portal, run Connect-AzAccount and voila!

Ok, now lets deploy it…what a new error for Connect-AzAccount, djjeszes.. and then 30 min of my life is gone.

When running

Connect-AzAccount -TenantId "gvsyvgs" -SubscriptionId "mhubdeomhub"

It prompts for validation with mail yes, and then it comes a new validation with “VERIFY YOUR IDENTITY” and no #ff234 code is received… (50 times)

Switching to the Powershell in the portal…

Using the rg and the str.acc but nned to make a fileshare, lets name it booseshare2

New Tiering models

Transaction-optimized including costs for metadata at-rest.
Hot: Hot file shares are for general purpose and perfect fit for services like Azure File Sync.
This tier are also fully based on Standard HDD level at GPv2.
Cold : Same as hot but also Cool are for small workloads and archives

If you have more issues well then

Run “clouddrive unmount” and then 2. Restart Cloud Shell via restart icon or exit and relaunch

Wow we are finally here…

More info in could storage

https://docs.microsoft.com/en-us/azure/cloud-shell/persisting-shell-storage

So we upload a file and test it

And changed tier to Hot

Continue tomorrow…

****************************** NA this end

Well what do you know….

Again:

Connect-AzAccount -TenantId "gvsyvgs" -SubscriptionId "mhubdeomhub"

Press the mail suggestion and type it, then the code is sent, it was too late yesterday…

And we are in again

Lets now deploy it….., with the -whatif first.


$gr = New-AzResourceGroup -Name "bxoose-rg" -Location "west europe" -Force
Write-Host "rg: " + $gr.ResourceGroupName


$templateFile = "C:\giti\powershell-cmd-bash\arm\quickstart-template\azuredeploy_merged.json"

New-AzResourceGroupDeployment -Name testWithMergeRepository -ResourceGroupName $gr.ResourceGroupName -TemplateFile $templateFile -storagePrefix "bxo" -webAppName "jeklApp" -WhatIf 

# $group = Get-AzResource -ResourceGroupName $gr.ResourceGroupName
# foreach ($item in $group) {
#    Write-Host "resource name: " $item.Name
#}

Then we get the following output, 3 resources will be deployed to the rg.

  • Storage account
  • Serverfarm
  • Web site

Ok, deploy it, just comment out -WhatIf and remove the 4 other comments, then run it.

And there you have it.

And a similar output as before, but now also with the URL and also the -Name of deployment

Name

9 Add tags

By using the same template, tags help you organize the resources. It could be useful for a dev, test or tracking cost.

Add a parameter to the file

[...]
"resourceTags" : {
      "type" : "object",
      "defaultValue" : {
        "Environment": "Dev",
        "Prject":"Tutorial"
      }

    }
# and then use the tag on the resources
"location": "[parameters('location')]",
"tags": "[parameters('resourceTags')]",

Now lets deploy it as before, we have already tested the command, we are now just adding tag. You can verify it in the portal. Here is for the app service: ( and we wrote project wrong !?#, so that means it can be almost anything)


10 Use parameter file

Store values to pass on during deployment, all the previous ones has been inline with powershell.
This approach is good for testing, but when automating, can be more useful to pass a set of val. Parameter files lets you package values for specific environment.

Given the template in num 9, we will now use a easy way to pass in parameters.
The param. file is similar to the temp. file
The name of
param. must match in both files,it is case-insensitive, but please match it.
If
no param. is give, then default is used, if it is configured with default val, else there is an error.

Make a param file, azure_deploy.parameters.dev.json

 {
     "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
     "contentVersion": "1.0.0.0",
     "parameters": {

        "storagePrefix": {
            "value": "devstore"
        },
        "storageSku": {
            "value": "Standard_LRS"
        },
        "appServicePlan" : {
            "value": "devplan"
        },
        "webAppName" : {
            "value": "devapp"
        },
        "resourceTags" : {
            "value":  {
                "Environment": "dev",
                "Project": "tutorial"
            }
        }  
     }
 }

This is the param. file for dev, now do the same but call this prod and change the atr. to you liking

 {
     "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
     "contentVersion": "1.0.0.0",
     "parameters": {

        "storagePrefix": {
            "value": "prodstore"
        },
        "storageSku": {
            "value": "Standard_LRS"
        },
        "appServicePlan" : {
            "value": "prodplan"
        },
        "webAppName" : {
            "value": "companyapp"
        },
        "resourceTags" : {
            "value":  {
                "Environment": "prod",
                "Project": "tutorial"
            }
        }   
     }
 }

Now lets deploy it (all files are in folder…\10-param-file on github)

Create a new file deploy_dev.ps1, run it with what if and provide the parameters you need and test it with -whatif:

  • A new rg
  • Template file
  • Parameter file
  • And the deploy command
  • (Optional get after)

$gr = New-AzResourceGroup -Name "bxoose-dev-rg" -Location "west europe" -Force
Write-Host "rg: " + $gr.ResourceGroupName

$templateFile = "C:\giti\powershell-cmd-bash\arm\Parameter-file\10-param-file\azure_template.json"
$paramterFile = "C:\giti\powershell-cmd-bash\arm\Parameter-file\10-param-file\azure_deploy.parameters.dev.json"

New-AzResourceGroupDeployment -Name testParameterDev -ResourceGroupName $gr.ResourceGroupName -TemplateFile $templateFile -TemplateParameterFile $paramterFile -WhatIf 

$group = Get-AzResource -ResourceGroupName $gr.ResourceGroupName
foreach ($item in $group) {
    Write-Host "resource name: " $item.Name
}

Output:

Now we can deploy the dev and prod and check it in the portal.

Comments Off on ARM Lab 103 MS (param+ template)