Create Azure Resources - RG

Octopus.AzurePowerShell exported 2018-10-03 by Jens-H-Eriksen belongs to ‘Azure’ category.

The New-AzureRmResourceGroup cmdlet creates an Azure resource group

Parameters

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

ResourceGroupName

CreateResourceGroup.ResourceGroupName

Required: Specifies a name for the resource group. This parameter is required. The resource name must be unique in the subscription.You can use -Name or its alias, -ResourceGroupName.If a resource group with that name already exists, the command prompts you for confirmation before replacing the existing resource group. To suppress the confirmation prompt, use the Force parameter.

Location

CreateResourceGroup.Location

Required: Specifies the location of the resource group. This parameter is required. Enter an Azure data center location, such as “West US” or “Southeast Asia”.You can place a resource group in any location. The resource group does not have to be in the same location your Azure subscription or the same location as its resources. Resource groups can contain resources from different locations. To determine which location support each resource type, use the Get-AzureRmResourceProvider with the ProviderNamespace parameter cmdlet.

AzureAccount

CreateResourceGroup.AzureAccount

Enter the SPN used to connect to Azure

Script body

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

$ResourceGroupName =$OctopusParameters["CreateResourceGroup.ResourceGroupName"]
$Location =$OctopusParameters["CreateResourceGroup.Location"]
 
 Write-Output "Variables:"
 Write-Output "ResourceGroupName: $ResourceGroupName"
 Write-Output "Location: $Location"

Write-Output '###############################################'
Write-Output '##Step1: Create Resource Group '
$AzureResourceGroup = Get-AzureRmResourceGroup -Name $ResourceGroupName -ErrorAction SilentlyContinue
if ( $null -eq $AzureResourceGroup)
{
Write-Output "Resource Group $ResourceGroupName does not exist, creating one ..."
$AzureResourceGroup =New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location
} 
else{
Write-Output "Resource Group $ResourceGroupName already exists ..."
}

Write-Output '###############################################'
Write-Output '##Step2: Validate Resource Group '

if ($null -eq $AzureResourceGroup ){
Throw "Failed to create resource group $AzureResourceGroupName"
}

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": "7ae25451-366d-49cc-a49d-eba03d147db0",
  "Name": "Create Azure Resources - RG",
  "Description": "The New-AzureRmResourceGroup cmdlet creates an Azure resource group",
  "Version": 28,
  "ExportedAt": "2018-10-03T11:37:04.316Z",
  "ActionType": "Octopus.AzurePowerShell",
  "Author": "Jens-H-Eriksen",
  "Parameters": [
    {
      "Id": "a5398248-3866-4e86-bfcd-6f6091199839",
      "Name": "CreateResourceGroup.ResourceGroupName",
      "Label": "ResourceGroupName",
      "HelpText": "Required: Specifies a name for the resource group. This parameter is required. The resource name must be unique in the subscription.You can use -Name or its alias, -ResourceGroupName.If a resource group with that name already exists, the command prompts you for confirmation before replacing the existing resource group. To suppress the confirmation prompt, use the Force parameter.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "ddbea94f-8053-4da7-aaea-c71e31be38a5",
      "Name": "CreateResourceGroup.Location",
      "Label": "Location",
      "HelpText": "Required: Specifies the location of the resource group. This parameter is required. Enter an Azure data center location, such as \"West US\" or \"Southeast Asia\".You can place a resource group in any location. The resource group does not have to be in the same location your Azure subscription or the same location as its resources. Resource groups can contain resources from different locations. To determine which location support each resource type, use the Get-AzureRmResourceProvider with the ProviderNamespace parameter cmdlet.",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    },
    {
      "Id": "18d18732-972c-446a-a6da-912866332c02",
      "Name": "CreateResourceGroup.AzureAccount",
      "Label": "AzureAccount",
      "HelpText": "Enter the SPN used to connect to Azure",
      "DefaultValue": null,
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      },
      "Links": {}
    }
  ],
  "Properties": {
    "Octopus.Action.Azure.AccountId": "#{CreateResourceGroup.AzureAccount}",
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.ScriptBody": "$ResourceGroupName =$OctopusParameters[\"CreateResourceGroup.ResourceGroupName\"]\n$Location =$OctopusParameters[\"CreateResourceGroup.Location\"]\n \n Write-Output \"Variables:\"\n Write-Output \"ResourceGroupName: $ResourceGroupName\"\n Write-Output \"Location: $Location\"\n\nWrite-Output '###############################################'\nWrite-Output '##Step1: Create Resource Group '\n$AzureResourceGroup = Get-AzureRmResourceGroup -Name $ResourceGroupName -ErrorAction SilentlyContinue\nif ( $null -eq $AzureResourceGroup)\n{\nWrite-Output \"Resource Group $ResourceGroupName does not exist, creating one ...\"\n$AzureResourceGroup =New-AzureRmResourceGroup -Name $ResourceGroupName -Location $Location\n} \nelse{\nWrite-Output \"Resource Group $ResourceGroupName already exists ...\"\n}\n\nWrite-Output '###############################################'\nWrite-Output '##Step2: Validate Resource Group '\n\nif ($null -eq $AzureResourceGroup ){\nThrow \"Failed to create resource group $AzureResourceGroupName\"\n}\n",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "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-resourcegroup.json",
  "Website": "/step-templates/7ae25451-366d-49cc-a49d-eba03d147db0",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////AHjXf7vrv931QJrh7/f8EIDaIIncMJHfYKvmz+b3n8zw3+76j8Ttr9XycLPpUKLkkKvYFAAABGZJREFUeNrsnNmCqjoQRc1MEiD8/9cer7Yt2KBJZQC8ez07sKlKTQlcLgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzoUSnt8YxXlFuGHSbIaxvj+fip4btkLn1blkWLaF5v03yLhLOYlVuGYfMOMZzNGxCOzhjTJqFkXnjq3Dr1yyvPI3hGl3Ih3zzHHNKudRstRhX5O58vIcShY67Gq6EPIESlzUWvazaGAOGbvU7ArDu/g8M4o8opDZWvbvPzl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YgcdderF9ibRdc7O982F1HpYhjfWUe+x5a6pjop9iNLfoePvlsdZdTSMwfxSmTY20Q0eHnUNzga1edeNmmqbg18aMVR1L9vwSXHF9TfIWBxpKLs2hj3eQeBC0USvp2HHF3eIkRdhFOd6ER8AAAAAAAAAAAAAAAAAAAAAAAAAAAAA/I/4J8AAo/80BciBec4AAAAASUVORK5CYII=",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Wednesday, October 3, 2018