Skip to content

Commit

Permalink
Update validation
Browse files Browse the repository at this point in the history
  • Loading branch information
bmaltais committed May 16, 2019
0 parents commit 855e556
Show file tree
Hide file tree
Showing 9 changed files with 344 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/parameters/cleanup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": { },
"variables": { },
"resources": [ ],
"outputs": { }
}
59 changes: 59 additions & 0 deletions test/parameters/dependancy-keyvaults.parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"keyvaultArray": {
"value": [
{
"name": "PwS2-validate-[unique]",
"resourceGroup": "PwS2-validate-active-directory-RG",
"sku": "Standard",
"enabledForDeployment": true,
"enabledForTemplateDeployment": true,
"enabledForDiskEncryption": true,
"accessPoliciesObjectId": "267cced3-2154-43ff-b79b-b12c331ad1d1",
"networkAcls": {
"defaultAction": "Allow",
"bypass": "AzureServices",
"virtualNetworkRules": [],
"ipRules": []
},
"secrets": [
{
"name": "server2016DefaultPassword",
"properties": {
"value": "Validate123!"
}
},
{
"name": "linuxDefaultPassword",
"properties": {
"value": "Validate123!"
}
},
{
"name": "adDefaultPassword",
"properties": {
"value": "Validate123!"
}
},
{
"name": "defaultAdminUsername",
"properties": {
"value": "azureadmin"
}
}
],
"tagValues": {
"Owner": "[email protected]",
"CostCenter": "PSPC-EA",
"Enviroment": "Validate",
"Classification": "Unclassified",
"Organizations": "PSPC-CCC-E&O",
"DeploymentVersion": "2018-12-14-01"
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"rgLocation": {
"value": "canadacentral"
},
"rgNames": {
"value": [
{
"resourceGroup": "PwS2-validate-active-directory-RG"
}
]
},
"tagValues": {
"value": {
"Owner": "[email protected]",
"CostCenter": "PSPC-EA",
"Enviroment": "Validate",
"Classification": "Unclassified",
"Organizations": "PSPC-CCC-E&O",
"DeploymentVersion": "2018-12-12-01"
}
}
}
}
33 changes: 33 additions & 0 deletions test/parameters/dependancy-vnet-subnet.parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vnetArray": {
"value": [
{
"name": "PwS2-validate-active-directory-VNET",
"resourceGroup": "PwS2-validate-active-directory-RG",
"addressPrefixes": [
"10.250.0.0/20"
],
"subnets": [
{
"name": "test1",
"properties": {
"addressPrefix": "10.250.1.0/24"
}
}
],
"tagValues": {
"Owner": "[email protected]",
"CostCenter": "PSPC-EA",
"Enviroment": "Validate",
"Classification": "Unclassified",
"Organizations": "PSPC-CCC-E&O",
"DeploymentVersion": "2018-12-13-01"
}
}
]
}
}
}
34 changes: 34 additions & 0 deletions test/parameters/masterdeploysub.parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"deploymentSubArray": {
"value": [
{
"name": "resourcegroups",
"location": "canadacentral",
"templateLink": "https://raw.githubusercontent.com/canada-ca-azure-templates/resourcegroups/20190514/template/azuredeploysub.json",
"parametersFile": "dependancy-resourcegroups-canadacentral.parameters.json"
},
{
"name": "keyvault-infra",
"location": "canadacentral",
"templateLink": "https://raw.githubusercontent.com/canada-ca-azure-templates/keyvaults/20190514/template/azuredeploysub.json",
"parametersFile": "dependancy-keyvaults.parameters.json",
"dependsOn": [
"resourcegroups"
]
},
{
"name": "vnet-subnet",
"location": "canadacentral",
"templateLink": "https://raw.githubusercontent.com/canada-ca-azure-templates/vnet-subnet/20190516/template/azuredeploysub.json",
"parametersFile": "dependancy-vnet-subnet.parameters.json",
"dependsOn": [
"resourcegroups"
]
}
]
}
}
}
79 changes: 79 additions & 0 deletions test/parameters/validate.parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"keyVaultResourceGroupName": {
"value": "PwS2-validate-active-directory-RG"
},
"keyVaultName": {
"value": "PwS2-validate-[unique]"
},
"DomainName": {
"value": "pspc.gc.ca.local"
},
"createChildDomain": {
"value": false
},
"ChildDomainName": {
"value": "mgmt"
},
"VMSize": {
"value": "Standard_B2ms"
},
"vnetRG": {
"value": "PwS2-validate-active-directory-RG"
},
"vnetName": {
"value": "PwS2-validate-active-directory-VNET"
},
"vnetAddressRange": {
"value": "10.250.0.0/20"
},
"adSubnetName": {
"value": "APP"
},
"adSubnet": {
"value": "10.250.1.0/24"
},
"RootDC1Name": {
"value": "AzPwS-RootDC01"
},
"RootDC1IPAddress": {
"value": "10.250.1.8"
},
"RootDC2Name": {
"value": "AzPwS-RootDC01"
},
"RootDC2IPAddress": {
"value": "10.250.1.9"
},
"ChildDC3Name": {
"value": "AzPwS-MgmtDC01"
},
"ChildDC3IPAddress": {
"value": "10.250.1.10"
},
"ChildDC4Name": {
"value": "AzPwS-MgmtDC02"
},
"ChildDC4IPAddress": {
"value": "10.250.1.11"
},
"tagValues": {
"value": {
"Owner": "[email protected]",
"CostCenter": "PSPC-EA",
"Enviroment": "Validate",
"Classification": "Unclassified",
"Organizations": "PSPC-CCC-E&O",
"DeploymentVersion": "2018-12-12-01"
}
},
"ReverseZoneObject": {
"value": [
"2.250.10",
"1.250.10"
]
}
}
}
7 changes: 7 additions & 0 deletions test/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Manually running validation

Manual execution of validation does like this:

Commit updates to dev branch then run:

.\validate.ps1
11 changes: 11 additions & 0 deletions test/validate-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
trigger:
- dev

steps:
- task: AzurePowerShell@3
displayName: 'Azure PowerShell script: FilePath'
inputs:
azureSubscription: '$(azureSubscriptionValidation)'
ScriptPath: test/validate.ps1
ScriptArguments: '-devopsCICD'
azurePowerShellVersion: LatestVersion
87 changes: 87 additions & 0 deletions test/validate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
Param(
[Parameter(Mandatory = $false)][string]$templateLibraryName = (Split-Path (Resolve-Path "$PSScriptRoot\..") -Leaf),
[string]$Location = "canadacentral",
[string]$subscription = "",
[switch]$devopsCICD = $false
)

#******************************************************************************
# Script body
# Execution begins here
#******************************************************************************

function getValidationURL {
$remoteURL = git config --get remote.origin.url
$currentBranch = git rev-parse --abbrev-ref HEAD
$remoteURLnogit = $remoteURL -replace '\.git', ''
$remoteURLRAW = $remoteURLnogit -replace 'github.com', 'raw.githubusercontent.com'
$validateURL = $remoteURLRAW + '/' + $currentBranch + '/template/azuredeploy.json'
return $validateURL
}

function getBaseParametersURL {
$remoteURL = git config --get remote.origin.url
$currentBranch = git rev-parse --abbrev-ref HEAD
$remoteURLnogit = $remoteURL -replace '\.git', ''
$remoteURLRAW = $remoteURLnogit -replace 'github.com', 'raw.githubusercontent.com'
$baseParametersURL = $remoteURLRAW + '/' + $currentBranch + '/test/parameters/'
return $baseParametersURL
}

$currentBranch = "dev"
$validationURL = "https://raw.githubusercontent.com/canada-ca-azure-templates/$templateLibraryName/dev/template/azuredeploy.json"
$baseParametersURL = "https://raw.githubusercontent.com/canada-ca-azure-templates/$templateLibraryName/dev/test/"

if (-not $devopsCICD) {
$currentBranch = git rev-parse --abbrev-ref HEAD

if ($currentBranch -eq 'master') {
$confirmation = Read-Host "You are working off the master branch... are you sure you want to validate the template from here? Switch to the dev branch is recommended. Continue? (y/n)"
if ($confirmation -ne 'y') {
exit
}
}

$validationURL = getValidationURL
$baseParametersURL = getBaseParametersURL

# Make sure we update code to git
# git branch dev ; git checkout dev ; git pull origin dev
git add . ; git commit -m "Update validation" ; git push origin $currentBranch
}

if ($subscription -ne "") {
Select-AzureRmSubscription -Subscription $subscription
}

# Cleanup validation resource content in case it did not properly completed and left over components are still lingeringcd
Write-Host "Cleanup old $templateLibraryName validation resources if needed...";

New-AzureRmResourceGroupDeployment -ResourceGroupName PwS2-validate-$templateLibraryName-RG -Mode Complete -TemplateFile (Resolve-Path "$PSScriptRoot\parameters\cleanup.json") -Force -Verbose

# Start the deployment
Write-Host "Starting $templateLibraryName dependancies deployment...";

New-AzureRmDeployment -Location $Location -Name "Deploy-Infrastructure-Dependancies" -TemplateUri "https://raw.githubusercontent.com/canada-ca-azure-templates/masterdeploy/20190514/template/masterdeploysub.json" -TemplateParameterFile (Resolve-Path -Path "$PSScriptRoot\parameters\masterdeploysub.parameters.json") -baseParametersURL $baseParametersURL -Verbose;

$provisionningState = (Get-AzureRmDeployment -Name "Deploy-Infrastructure-Dependancies").ProvisioningState

if ($provisionningState -eq "Failed") {
Write-Host "One of the jobs was not successfully created... exiting..."
exit
}

# Validating server template
Write-Host "Starting $templateLibraryName validation deployment...";

New-AzureRmResourceGroupDeployment -ResourceGroupName PwS2-validate-$templateLibraryName-RG -Name "validate-$templateLibraryName-template" -TemplateUri $validationURL -TemplateParameterFile (Resolve-Path "$PSScriptRoot\parameters\validate.parameters.json") -Verbose

$provisionningState = (Get-AzureRmResourceGroupDeployment -ResourceGroupName PwS2-validate-$templateLibraryName-RG -Name "validate-$templateLibraryName-template").ProvisioningState

if ($provisionningState -eq "Failed") {
Write-Host "Test deployment failed..."
}

# Cleanup validation resource content
Write-Host "Cleanup $templateLibraryName validation resources...";
New-AzureRmResourceGroupDeployment -ResourceGroupName PwS2-validate-$templateLibraryName-RG -Mode Complete -TemplateFile (Resolve-Path "$PSScriptRoot\parameters\cleanup.json") -Force -Verbose

0 comments on commit 855e556

Please sign in to comment.