Last active
April 25, 2021 17:30
-
-
Save JeffBrownTech/f33af074ddec7a1de24bafe96e9ae7d7 to your computer and use it in GitHub Desktop.
PSArm Vnet and Snet Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define variables for the virtual network and subnet properties | |
$location = "westus2" | |
$name = 'prod' | |
$vnetName = "vnet-$name-$location-001" | |
$vnetPrefix = '10.20.0.0/16' | |
# Include as many subnets as you want to create as hashtables in the array | |
$subnets = @( | |
[PsCustomObject]@{Name = 'mgmt'; Prefix = '10.20.2.0/24'}, | |
[PsCustomObject]@{Name = 'web'; Prefix = '10.20.4.0/24'}, | |
[PsCustomObject]@{Name = 'db'; Prefix = '10.20.6.0/24'} | |
) | |
# Define the ARM resources | |
Arm { | |
# Add the virtual network resource | |
# Note the use of variables inline with the resource definition | |
Resource $vnetName -Namespace Microsoft.Network -Type virtualNetworks -ApiVersion 2020-08-01 -Location $location { | |
properties { | |
addressSpace { | |
addressPrefixes $vnetPrefix | |
} | |
# Use PowerShell's foreach to iterate through creating each subnet | |
foreach ($subnet in $subnets) { | |
subnets { | |
name $subnet.Name | |
properties { | |
addressPrefix $subnet.Prefix | |
} | |
} | |
} | |
} | |
} # End of vnet resource | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment