Skip to content

Instantly share code, notes, and snippets.

@davidobrien1985
Created June 21, 2016 12:46
Show Gist options
  • Save davidobrien1985/56a8d83ff742e70aafa242e54e75c7f3 to your computer and use it in GitHub Desktop.
Save davidobrien1985/56a8d83ff742e70aafa242e54e75c7f3 to your computer and use it in GitHub Desktop.
This gist prepares Azure for use with Packer.
param (
[string]$azurelocation = 'Australia Southeast',
[string]$app_password = 'P@ssw0rd',
[string]$subscription_ID
)
Add-AzureRmAccount
$azuresub = Get-AzureRmSubscription -SubscriptionId $subscription_ID
New-AzureRmResourceGroup -Name vagrant -Location $azurelocation -Tag @{Name='vagrant'} -Verbose
$azurestorage = New-AzureRmStorageAccount -ResourceGroupName vagrant -Name vagrant$(Get-Random) -SkuName Standard_GRS -Location $azurelocation -Tags @{Name='vagrant'} -Verbose
New-AzureRmADApplication -DisplayName vagrant -HomePage http://vagrantauth.com -IdentifierUris http://vagrantauth.com -Password $app_password -Verbose
$app = Get-AzureRmADApplication -IdentifierUri http://vagrantauth.com -Verbose
New-AzureRmADServicePrincipal -ApplicationId $app.ApplicationId -Verbose
Start-Sleep -Seconds 10
$roleassignment = New-AzureRmRoleAssignment -ServicePrincipalName http://vagrantauth.com -RoleDefinitionName Owner -Scope /subscriptions/31d39423-6438-4cd9-a203-052634635dd2 -Verbose
$result = @{SubscriptionID="$($azuresub.SubscriptionId)"; TenantID = "$($azuresub.TenantId)"; ClientID = "$($app.ApplicationId)"; client_secret = $app_password; resource_group_name = 'vagrant'; storage_account = "$($azurestorage.StorageAccountName)"; object_id = "$($roleassignment.ObjectId)"}
$result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment