Skip to content

Commit

Permalink
Resolves #12: option to override pre-tag name instead of using Resour…
Browse files Browse the repository at this point in the history
…ce Group name
  • Loading branch information
Badgerati committed May 16, 2017
1 parent b4d5ddd commit b022b62
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
14 changes: 14 additions & 0 deletions examples/basic-vm-pretag/Foggfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"SubscriptionName": "<SUB_NAME_HERE>",
"Groups": [
{
"ResourceGroupName": "basic-pretag-rg",
"Location": "westeurope",
"TemplatePath": ".\\template.json",
"VNetAddress": "10.6.0.0/16",
"SubnetAddresses": {
"vm": "10.6.0.0/24"
}
}
]
}
35 changes: 35 additions & 0 deletions examples/basic-vm-pretag/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"pretag": "pretag",
"template": [
{
"tag": "vm",
"type": "vm",
"count": 1,
"provisioners": [
"remoting"
],
"usePublicIP": true,
"os": {
"size": "Standard_DS1_v2",
"type": "Windows",
"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"skus": "2016-Datacenter"
}
}
],
"provisioners": {
"remoting": "dsc: @{remoting}"
},
"firewall": {
"inbound": [
{
"name": "RDP",
"priority": 4095,
"source": "*:*",
"destination": "@{subnet}:3389",
"access": "Allow"
}
]
}
}
8 changes: 7 additions & 1 deletion src/Fogg.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ try
# Check the template section
$vmCount = Test-Template -Template $template.template -FoggObject $FoggObject -OS $template.os

# If we have a pretag on the template, set against this FoggObject
if (![string]::IsNullOrWhiteSpace($template.pretag))
{
$FoggObject.PreTag = $template.pretag.ToLowerInvariant()
}


# If we're using an existng virtual network, ensure it actually exists
if ($FoggObject.UseExistingVNet)
Expand Down Expand Up @@ -223,7 +229,7 @@ try
foreach ($vm in $vms)
{
$tag = $vm.tag.ToLowerInvariant()
$tagname = "$($FoggObject.ShortRGName)-$($tag)"
$tagname = "$($FoggObject.PreTag)-$($tag)"
$snetname = "$($tagname)-snet"
$subnet = $FoggObject.SubnetAddressMap[$tag]

Expand Down
4 changes: 2 additions & 2 deletions src/Modules/FoggAzure.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function New-FoggStorageAccount
$StorageTag = 'prm'
}

$Name = ("$($FoggObject.ShortRGName)-$($StorageTag)-sa") -ireplace '-', ''
$Name = ("$($FoggObject.PreTag)-$($StorageTag)-sa") -ireplace '-', ''

Write-Information "Creating storage account $($Name) in resource group $($FoggObject.ResourceGroupName)"

Expand Down Expand Up @@ -874,7 +874,7 @@ function New-FoggVirtualNetwork
$FoggObject
)

$Name = "$($FoggObject.ShortRGName)-vnet"
$Name = "$($FoggObject.PreTag)-vnet"

Write-Information "Creating virtual network $($Name) in $($FoggObject.ResourceGroupName)"

Expand Down
8 changes: 4 additions & 4 deletions src/Modules/FoggTools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ function New-FoggGroupObject
# create fogg object with params
$group = @{}
$group.ResourceGroupName = $ResourceGroupName
$group.ShortRGName = (Remove-RGTag $ResourceGroupName)
$group.PreTag = (Remove-RGTag $ResourceGroupName)
$group.Location = $Location
$group.VNetAddress = $VNetAddress
$group.VNetResourceGroupName = $VNetResourceGroupName
Expand All @@ -962,7 +962,7 @@ function New-FoggGroupObject

# post param alterations
$groupObj.ResourceGroupName = $groupObj.ResourceGroupName.ToLowerInvariant()
$groupObj.ShortRGName = $groupObj.ShortRGName.ToLowerInvariant()
$groupObj.PreTag = $groupObj.PreTag.ToLowerInvariant()

# return object
return $groupObj
Expand Down Expand Up @@ -1038,7 +1038,7 @@ function New-DeployTemplateVM
)

$tag = $VMTemplate.tag.ToLowerInvariant()
$tagname = "$($FoggObject.ShortRGName)-$($tag)"
$tagname = "$($FoggObject.PreTag)-$($tag)"
$usePublicIP = [bool]$VMTemplate.usePublicIP
$subnetId = ($VNet.Subnets | Where-Object { $_.Name -ieq "$($tagname)-snet" }).Id

Expand Down Expand Up @@ -1123,7 +1123,7 @@ function New-DeployTemplateVPN
)

$tag = $VPNTemplate.tag.ToLowerInvariant()
$tagname = "$($FoggObject.ShortRGName)-$($tag)"
$tagname = "$($FoggObject.PreTag)-$($tag)"

$gatewaySubnetId = ($VNet.Subnets | Where-Object { $_.Name -ieq 'GatewaySubnet' }).Id
$gatewayIP = $FoggObject.SubnetAddressMap["$($tag)-gip"]
Expand Down

0 comments on commit b022b62

Please sign in to comment.