Menu
e-lo
  • Home
    • Tech
    • Inspiration and about
  • Database
    • T-SQL
    • SQL Server quick
    • SQL server docs
    • MySql quick sheet
    • Postgre
    • InfluxDB
  • Programming
    • Automating the boring stuff
    • Python 101
    • Python Docs
    • Python Logging
    • cSharp Overview
    • Powershell Latest
    • Powershell 4 lang ref
    • MS Azure PS ref
    • MS Azure CLI ref
  • Azure
    • AZ-104-MS Azure Administrator 101 quick ref
    • AZ-104 Lab
    • MS Windows virtual machines in Azure
    • MS ARM Docs
    • MS ARM Tutorial
    • MS Deployment scripts (intern/extern)
    • ARM Quickstart
    • MS ARM templates 4h
  • Az Adm
    • AD 101
    • Governance and Compliance 102
    • Administration 103
    • Virtual Networking 104
    • Storage 107 (With table (NoSQL and more))
    • Virtual Machines 108
    • Azure Virtual Machines 101
    • Monitor VM (and market)
  • Linux
    • Top CMD’s
    • Useful CMD Linux
    • ss64 Linux
    • Ubuntu
    • 30 things Ubuntu 18.04
  • Zen
    • Not thinking about anything is Zen
e-lo

ARM Lab 103 MS (param+ template)

Posted on December 18, 2020January 4, 2021 by espenk

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.

RSS Azure

  • Azure Cost Management and Billing updates – January 2021 January 26, 2021

RSS Python

  • PEP 651: Robust Stack Overflow Handling January 18, 2021

Cloud

ARM (8) azure (23) cmd (1) Django (4) Docker (1) e-lo (2) Flask (2) Github (9) Grafana (2) Information (1) Information Retrieval (11) JAVA (1) kivy (2) Kotlin (4) linux (11) mobile (2) Natural Language Prossesing (NLP) (2) Net.Core (1) Networking and Security (2) OPC (2) PEP8 (1) Philosophy (3) Python (41) Python Networking and Security (2) Reason (2) RMQ (2) Solr (11) Sql (10) VSC (1) Warframe (2) WMVARE (4) Zabbix (7)

Recent Posts

  • 1 TODO ARM Lab 105 MS (Deployment create a pipeline)
  • 2 TODO MS ARM Template 4h
  • TODO Cryptography with Python – Caesar Cipher
  • 3 TODO Udemy AZ-104 Microsoft Azure Administrator Exam Certification (Scott Duffy)
  • ARM Lab 104 MS (Deployment and more)

Archives

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2021 e-lo | Powered by WordPress & Superb Themes