Create Azure Resources - WA

Octopus.AzurePowerShell exported 2018-01-08 by IanMoroney belongs to ‘Azure’ category.

The New-AzureRmAppServicePlan cmdlet creates a new app service plan. The New-AzureRmWebApp cmdlet creates a new web app.

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

ResourceGroupName

ResourceGroupName

Enter the name of the resource group you are deploying this Web App into

DeploymentLocation

Location

Enter the location (Region) where the service plan is located

AppServicePlanName

AppServicePlanName

Enter the name of the app service plan

AppServicePlanTier

AppServicePlanTier

Enter the tier of the app service plan

WebAppName

WebAppName

Enter the name of your web app

AppServiceUse32BitWorkerProcess

AppServiceUse32BitWorkerProcess

Sets the app pool for 32-bit processes or 64-bit processes. Use 1 for 32-bit Use 0 for 64-bit

AzureAccount

AzureAccount

Enter the SPN used to connect to Azure

Script body

Steps based on this template will execute the following undefined script.

###############################################
##Step 1: Get Variables
$ResourceGroupName             = $OctopusParameters["ResourceGroupName"] 
$DeploymentLocation            = $OctopusParameters["Location"] 
$AppServicePlanName            = $OctopusParameters["AppServicePlanName"] 
$AppServicePlanTier            = $OctopusParameters["AppServicePlanTier"]
$WebAppName                    = $OctopusParameters["WebAppName"]
$TimeStamp                          = Get-Date -Format ddMMyyyy_hhmmss
$PublishProfilePath                 = Join-Path -Path $ENV:Temp -ChildPath "publishprofile$TimeStamp.xml"
$AppServiceUse32BitWorkerProcess= $OctopusParameters["AppServiceUse32BitWorkerProcess"] 
###############################################

###############################################
##Step 2: Check and Create Service Plan
try{
  $ServicePlan= Get-AzureRmAppServicePlan -ResourceGroupName $ResourceGroupName -Name $AppServicePlanName  -ErrorAction SilentlyContinue 
  if ($null -eq $ServicePlan)
  {
    Write-Output "Creating Service Plan"
    $ServicePlan=New-AzureRmAppServicePlan -Name $AppServicePlanName -Location $Location -ResourceGroupName $ResourceGroupName -Tier $AppServicePlanTier
  }
  else{
      Write-Output "Service Plan already set up"
  }
  $WebApp = Get-AzureRmWebApp -ResourceGroupName $ResourceGroupName -Name $WebAppName -ErrorAction SilentlyContinue
  if($null -eq $WebApp)
  {
      Write-Output "Creating WebApp"
      $webApp = New-AzureRmWebApp -Name $WebAppName -AppServicePlan $AppServicePlanName -ResourceGroupName $ResourceGroupName -Location $DeploymentLocation
  }
  else {
      Write-Output "WebApp already created"
  }
  
  Write-Output "setting app to use $AppServiceUse32BitWorkerProcess" 
  Set-AzureRmWebApp -ResourceGroupName $ResourceGroupName -Name $WebAppName -Use32BitWorkerProcess ([bool]$AppServiceUse32BitWorkerProcess)
  $null = Get-AzureRmWebAppPublishingProfile -OutputFile $PublishProfilePath -ResourceGroupName $ResourceGroupName -Name $WebAppName -Format WebDeploy -Verbose
  
  Write-output "profile: $(get-content  $PublishProfilePath)"
  if (!(Test-Path -Path $PublishProfilePath)){
    throw [System.IO.FileNotFoundException] "$PublishProfilePath not found."
  }

    get-childitem $psscriptroot
}
catch{
  Write-Output "Cannot add serviceplan/webapp : $AzureAppServicePlanName / $AzureWebAppName"
  Write-Output $_

}

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "c9a3122f-6723-4753-8461-f9fb3e73a513",
  "Name": "Create Azure Resources - WA",
  "Description": "The New-AzureRmAppServicePlan cmdlet creates a new app service plan.\nThe New-AzureRmWebApp cmdlet creates a new web app.",
  "Version": 1,
  "ExportedAt": "2018-01-08T10:36:38.951Z",
  "ActionType": "Octopus.AzurePowerShell",
  "Author": "IanMoroney",
  "Parameters": [
    {
      "Id": "f6595af0-9cb5-4281-8fce-69f046c53e96",
      "Name": "ResourceGroupName",
      "Label": "ResourceGroupName",
      "HelpText": "Enter the name of the resource group you are deploying this Web App into",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "f8d7d8c4-e862-436d-bea3-aa3f9a6caec3",
      "Name": "Location",
      "Label": "DeploymentLocation",
      "HelpText": "Enter the location (Region) where the service plan is located",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "ef49ded7-ec59-482b-83bd-e890d36103b9",
      "Name": "AppServicePlanName",
      "Label": "AppServicePlanName",
      "HelpText": "Enter the name of the app service plan",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "554a3a1c-9235-45e9-b198-d77cd8dae52d",
      "Name": "AppServicePlanTier",
      "Label": "AppServicePlanTier",
      "HelpText": "Enter the tier of the app service plan",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "eee220dc-1af4-44ce-9bfc-950e87e9587d",
      "Name": "WebAppName",
      "Label": "WebAppName",
      "HelpText": "Enter the name of your web app",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "1f60c02e-77d1-4f2f-9874-87da815fc157",
      "Name": "AppServiceUse32BitWorkerProcess",
      "Label": "AppServiceUse32BitWorkerProcess",
      "HelpText": "Sets the app pool for 32-bit processes or 64-bit processes.\nUse 1 for 32-bit\nUse 0 for 64-bit",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "7dda30f1-94e4-4a2a-beb6-c8663924bdee",
      "Name": "AzureAccount",
      "Label": "AzureAccount",
      "HelpText": "Enter the SPN used to connect to Azure",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    }
  ],
  "Properties": {
    "Octopus.Action.Azure.AccountId": "#{AzureAccount}",
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.ScriptBody": "###############################################\n##Step 1: Get Variables\n$ResourceGroupName             = $OctopusParameters[\"ResourceGroupName\"] \n$DeploymentLocation            = $OctopusParameters[\"Location\"] \n$AppServicePlanName            = $OctopusParameters[\"AppServicePlanName\"] \n$AppServicePlanTier            = $OctopusParameters[\"AppServicePlanTier\"]\n$WebAppName                    = $OctopusParameters[\"WebAppName\"]\n$TimeStamp                          = Get-Date -Format ddMMyyyy_hhmmss\n$PublishProfilePath                 = Join-Path -Path $ENV:Temp -ChildPath \"publishprofile$TimeStamp.xml\"\n$AppServiceUse32BitWorkerProcess= $OctopusParameters[\"AppServiceUse32BitWorkerProcess\"] \n###############################################\n\n###############################################\n##Step 2: Check and Create Service Plan\ntry{\n  $ServicePlan= Get-AzureRmAppServicePlan -ResourceGroupName $ResourceGroupName -Name $AppServicePlanName  -ErrorAction SilentlyContinue \n  if ($null -eq $ServicePlan)\n  {\n    Write-Output \"Creating Service Plan\"\n    $ServicePlan=New-AzureRmAppServicePlan -Name $AppServicePlanName -Location $Location -ResourceGroupName $ResourceGroupName -Tier $AppServicePlanTier\n  }\n  else{\n      Write-Output \"Service Plan already set up\"\n  }\n  $WebApp = Get-AzureRmWebApp -ResourceGroupName $ResourceGroupName -Name $WebAppName -ErrorAction SilentlyContinue\n  if($null -eq $WebApp)\n  {\n      Write-Output \"Creating WebApp\"\n      $webApp = New-AzureRmWebApp -Name $WebAppName -AppServicePlan $AppServicePlanName -ResourceGroupName $ResourceGroupName -Location $DeploymentLocation\n  }\n  else {\n      Write-Output \"WebApp already created\"\n  }\n  \n  Write-Output \"setting app to use $AppServiceUse32BitWorkerProcess\" \n  Set-AzureRmWebApp -ResourceGroupName $ResourceGroupName -Name $WebAppName -Use32BitWorkerProcess ([bool]$AppServiceUse32BitWorkerProcess)\n  $null = Get-AzureRmWebAppPublishingProfile -OutputFile $PublishProfilePath -ResourceGroupName $ResourceGroupName -Name $WebAppName -Format WebDeploy -Verbose\n  \n  Write-output \"profile: $(get-content  $PublishProfilePath)\"\n  if (!(Test-Path -Path $PublishProfilePath)){\n    throw [System.IO.FileNotFoundException] \"$PublishProfilePath not found.\"\n  }\n\n    get-childitem $psscriptroot\n}\ncatch{\n  Write-Output \"Cannot add serviceplan/webapp : $AzureAppServicePlanName / $AzureWebAppName\"\n  Write-Output $_\n\n}\n",
    "Octopus.Action.Package.FeedId": null,
    "Octopus.Action.Script.ScriptFileName": null,
    "Octopus.Action.Package.PackageId": null
  },
  "Category": "Azure",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/azure-create-new-webapp.json",
  "Website": "/step-templates/c9a3122f-6723-4753-8461-f9fb3e73a513",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////AHjXf7vrv931QJrh7/f8EIDaIIncMJHfYKvmz+b3n8zw3+76j8Ttr9XycLPpUKLkkKvYFAAABGZJREFUeNrsnNmCqjoQRc1MEiD8/9cer7Yt2KBJZQC8ez07sKlKTQlcLgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzoUSnt8YxXlFuGHSbIaxvj+fip4btkLn1blkWLaF5v03yLhLOYlVuGYfMOMZzNGxCOzhjTJqFkXnjq3Dr1yyvPI3hGl3Ih3zzHHNKudRstRhX5O58vIcShY67Gq6EPIESlzUWvazaGAOGbvU7ArDu/g8M4o8opDZWvbvPzlL/MMBE8jT9T9W7PbAJlHPTBFRf9yVTEcs63msXz2UHLSgf650G/d5t+wjbxxB2UCMqGrk8/LFSD7uJMeNt5bcJCyQZyAe5Fo9KYfWS2flQrr4b4tpuzaeWjYs49rt9LHf9uZD7+VbyVi9EBNrjYjuq2sxQOrl+p+HuBVu45qvqfq691ttYFQ5KyKbyJgaIY/NGxrlWZwlwGvmvu1oY3PuAv0niTq6tZ78jk//9uc1r1r4lQki7y7sp2Tu4V1y2iLoqFTqi1lIGcpFiebrZNZ1dOkF0cCIlO8jQ47nCkam9Lilz9GhDF1I6XGLzfnhwDIIZVfI7+8SSgfHsijqXENOGJF5QorG4EcW0OrScqX/dDrXpr70Ut/BII+1OfECPuYz/NWxYmgrCsUskxPvyhgmrw+WGZ6lGTuOlIyCYWTFyWjpM5KIZRUIOwjRNYRQ6tZF9BXtk8hWAHPtLNJ727Fq0JSkC1FDRRF0Jalj0d5qVh2KEpM2TuSsCYTCT6ZkdmFYI9LrYp5QayWbo6NXlZwcRD/61pth5Fq5EX423QQxNjhqWvvklkljOLkYjrmphXPZOJOk6Pg7HKMsrtQKcowzZoK3rx1ZUelGMdQA/HaKkjAt2RgqpZeYqbNbH7Hp2ct4nqfSPOfe0ftiSTZJydOV6rG5bQbyLK+nRuCC0343PzDgiOXyQA5c14BTZi98uR/5KJ1SnatLdoO50WWBQZPTq0VgsklU3h932actuo17ayrHrb/3ykiegd3KbqF2wbV6RrlsJ07yLcpsWFTul9RyK6ZScr+tk7oNrFj0o7HQUlj4EiEvJ6rPLKSmlMZCrksl1OnLaRkxc+/HB1naMhNtT/6yM2bDs6azCRHrM3aVPN7aW8irD/10B8njpAMcsl8okXcdKrl4sPsLmQVy/Sj90ucPRc/d/Bxxj+dXSpCayen32D+hLi16MsIV8gfCXrYp6ySsiJKRUF0XXiLpVbFU+fNv4r7mOwhFsX4ZdwpSi1DYs2jb6ebZ9788cblTzMrYhu7sf/17IFdtuviJ2ioHA6pMHkoH4CLUeMBU7iGkxuM/YgcdderF9ibRdc7O982F1HpYhjfWUe+x5a6pjop9iNLfoePvlsdZdTSMwfxSmTY20Q0eHnUNzga1edeNmmqbg18aMVR1L9vwSXHF9TfIWBxpKLs2hj3eQeBC0USvp2HHF3eIkRdhFOd6ER8AAAAAAAAAAAAAAAAAAAAAAAAAAAAA/I/4J8AAo/80BciBec4AAAAASUVORK5CYII=",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Monday, January 8, 2018