зеркало из https://github.com/Azure/vdc.git
Toolkit Config Change and Validation RG Enhancement (#134)
* Completed the initial implementation. * Finalized the changes and tested * Changes based on feedback from today's review * Changes post running tested. * Changes to optimize the code.
This commit is contained in:
Родитель
829f0f9330
Коммит
d66ef4a76e
|
@ -11,6 +11,13 @@
|
|||
"Cache": {
|
||||
"Comments": "Caching service",
|
||||
"StorageType": "AzureDevOps"
|
||||
},
|
||||
"ValidationResourceGroup": {
|
||||
"Name": "vdc-custom-rg",
|
||||
"Location": "West US",
|
||||
"Tags": {
|
||||
"Policy": "Exempt"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,8 @@
|
|||
"Subscription": "AKS",
|
||||
"Location": "West US",
|
||||
"ModuleConfigurationParameters": {
|
||||
"KeyVaultManagementUserId": "env(KEYVAULT_MANAGEMENT_USER_ID)",
|
||||
"DevOpsServicePrincipalId": "env(DEVOPS_SERVICE_PRINCIPAL_USER_ID)",
|
||||
"ResourceGroupPrefix": "${Parameters.Organization}-${Parameters.DeploymentName}",
|
||||
"Region": "westus2",
|
||||
"DnsPrefix": "aks",
|
||||
|
@ -103,6 +105,222 @@
|
|||
"ResourceGroup": "${Parameters.InstanceName}-acr-rg",
|
||||
"AdminUserEnabled": true,
|
||||
"Sku": "Standard"
|
||||
},
|
||||
"VirtualNetwork": {
|
||||
"NetworkSecurityGroups": [
|
||||
{
|
||||
"Name": "default",
|
||||
"Rules": [
|
||||
{
|
||||
"Name": "allow-azure-loadbalancer",
|
||||
"Properties": {
|
||||
"Access": "Allow",
|
||||
"DestinationAddressPrefixes": [],
|
||||
"DestinationAddressPrefix": "VirtualNetwork",
|
||||
"DestinationPortRange": "*",
|
||||
"DestinationPortRanges":[],
|
||||
"DestinationApplicationSecurityGroups": [],
|
||||
"Direction": "Inbound",
|
||||
"Priority": 100,
|
||||
"Protocol": "*",
|
||||
"SourcePortRange": "*",
|
||||
"SourcePortRanges": [],
|
||||
"SourceAddressPrefix": "AzureLoadBalancer",
|
||||
"SourceApplicationSecurityGroups":[]
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "allow-ssh",
|
||||
"Properties": {
|
||||
"Access": "Allow",
|
||||
"DestinationAddressPrefixes": [],
|
||||
"DestinationAddressPrefix": "VirtualNetwork",
|
||||
"DestinationPortRange": "22",
|
||||
"DestinationPortRanges": [],
|
||||
"DestinationApplicationSecurityGroups": [],
|
||||
"Direction": "Inbound",
|
||||
"Priority": 110,
|
||||
"Protocol": "Tcp",
|
||||
"SourcePortRange": "*",
|
||||
"SourcePortRanges": [],
|
||||
"SourceAddressPrefix": "172.0.0.0/16",
|
||||
"SourceApplicationSecurityGroups": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "allow-http",
|
||||
"Properties": {
|
||||
"Access": "Allow",
|
||||
"DestinationAddressPrefixes": [],
|
||||
"DestinationAddressPrefix": "VirtualNetwork",
|
||||
"DestinationPortRange": "80",
|
||||
"DestinationPortRanges": [],
|
||||
"DestinationApplicationSecurityGroups": [],
|
||||
"Direction": "Inbound",
|
||||
"Priority": 120,
|
||||
"Protocol": "*",
|
||||
"SourcePortRange": "*",
|
||||
"SourcePortRanges": [],
|
||||
"SourceAddressPrefix": "VirtualNetwork",
|
||||
"SourceApplicationSecurityGroups": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "allow-https",
|
||||
"Properties": {
|
||||
"Access": "Allow",
|
||||
"DestinationAddressPrefixes": [],
|
||||
"DestinationAddressPrefix": "VirtualNetwork",
|
||||
"DestinationPortRange": "443",
|
||||
"DestinationPortRanges": [],
|
||||
"DestinationApplicationSecurityGroups": [],
|
||||
"Direction": "Inbound",
|
||||
"Priority": 130,
|
||||
"Protocol": "*",
|
||||
"SourcePortRange": "*",
|
||||
"SourcePortRanges": [],
|
||||
"SourceAddressPrefix": "VirtualNetwork",
|
||||
"SourceApplicationSecurityGroups": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "deny-internet",
|
||||
"Properties": {
|
||||
"Access": "Deny",
|
||||
"DestinationAddressPrefix": "*",
|
||||
"DestinationAddressPrefixes": [],
|
||||
"DestinationPortRange": "*",
|
||||
"DestinationPortRanges": [],
|
||||
"DestinationApplicationSecurityGroups": [],
|
||||
"Direction": "Inbound",
|
||||
"Priority": 4095,
|
||||
"Protocol": "Tcp",
|
||||
"SourcePortRange": "*",
|
||||
"SourcePortRanges": [],
|
||||
"SourceAddressPrefix": "Internet",
|
||||
"SourceApplicationSecurityGroups": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "deny-vnet",
|
||||
"Properties": {
|
||||
"Access": "Deny",
|
||||
"DestinationAddressPrefix": "VirtualNetwork",
|
||||
"DestinationAddressPrefixes": [],
|
||||
"DestinationPortRange": "*",
|
||||
"DestinationPortRanges": [],
|
||||
"DestinationApplicationSecurityGroups": [],
|
||||
"Direction": "Inbound",
|
||||
"Priority": 4096,
|
||||
"Protocol": "Tcp",
|
||||
"SourcePortRange": "*",
|
||||
"SourcePortRanges": [],
|
||||
"SourceAddressPrefix": "VirtualNetwork",
|
||||
"SourceApplicationSecurityGroups": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"UserDefinedRoutes": [
|
||||
{
|
||||
"Name": "default",
|
||||
"Routes": [
|
||||
{
|
||||
"Name": "default",
|
||||
"Properties": {
|
||||
"AddressPrefix": "0.0.0.0/0",
|
||||
"NextHopIpAddress": "172.0.3.4",
|
||||
"NextHopType": "VirtualAppliance"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "to-on-premises",
|
||||
"Properties": {
|
||||
"AddressPrefix": "192.168.1.0/28",
|
||||
"NextHopType": "VirtualNetworkGateway"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"Subnets": [
|
||||
{
|
||||
"name": "default",
|
||||
"addressPrefix": "172.2.0.0/17",
|
||||
"networkSecurityGroupName": "${Parameters.ModuleConfigurationParameters.VirtualNetwork.NetworkSecurityGroups[0].Name}",
|
||||
"userDefinedRoute": "",
|
||||
"routeTableName": "${Parameters.ModuleConfigurationParameters.VirtualNetwork.UserDefinedRoutes[0].Name}",
|
||||
"serviceEndpoints": [
|
||||
{
|
||||
"Service": "Microsoft.EventHub"
|
||||
},
|
||||
{
|
||||
"Service": "Microsoft.Sql"
|
||||
},
|
||||
{
|
||||
"Service": "Microsoft.KeyVault"
|
||||
},
|
||||
{
|
||||
"Service": "Microsoft.Storage"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"KeyVault": {
|
||||
"Name": "${Parameters.Organization}-${Parameters.DeploymentName}-kv",
|
||||
"ResourceGroup": "${Parameters.InstanceName}-keyvault-rg",
|
||||
"Sku": "Premium",
|
||||
"EnableVaultForDeployment": true,
|
||||
"EnableVaultForDiskEncryption": true,
|
||||
"EnableVaultForTemplateDeployment": true,
|
||||
"AccessPolicies": [
|
||||
{
|
||||
"tenantId": "${Subscriptions.AKS.TenantId}",
|
||||
"objectId": "${Parameters.ModuleConfigurationParameters.KeyVaultManagementUserId}",
|
||||
"permissions": {
|
||||
"certificates": [
|
||||
"All"
|
||||
],
|
||||
"keys": [
|
||||
"All"
|
||||
],
|
||||
"secrets": [
|
||||
"All"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tenantId": "${Subscriptions.AKS.TenantId}",
|
||||
"objectId": "${Parameters.ModuleConfigurationParameters.DevOpsServicePrincipalId}",
|
||||
"permissions": {
|
||||
"certificates": [
|
||||
"All"
|
||||
],
|
||||
"keys": [
|
||||
"All"
|
||||
],
|
||||
"secrets": [
|
||||
"All"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"SecretsObject": {
|
||||
"Comments": "Creating an object so we can use a secretsobject parameter type in our ARM template",
|
||||
"Secrets": [ ]
|
||||
},
|
||||
"NetworkAcls": {
|
||||
"bypass": "AzureServices",
|
||||
"defaultAction": "Deny",
|
||||
"virtualNetworkRules": [
|
||||
{
|
||||
"subnet": "${Parameters.ModuleConfigurationParameters.VirtualNetwork.Subnets[0].Name}"
|
||||
}
|
||||
],
|
||||
"ipRules": []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,60 +37,6 @@
|
|||
"UseRemoteGateways": false
|
||||
}
|
||||
},
|
||||
"KeyVault": {
|
||||
"Name": "${Parameters.Organization}-${Parameters.DeploymentName}-kv",
|
||||
"ResourceGroup": "${Parameters.InstanceName}-keyvault-rg",
|
||||
"Sku": "Premium",
|
||||
"EnableVaultForDeployment": true,
|
||||
"EnableVaultForDiskEncryption": true,
|
||||
"EnableVaultForTemplateDeployment": true,
|
||||
"AccessPolicies": [
|
||||
{
|
||||
"tenantId": "${Subscriptions.AKS.TenantId}",
|
||||
"objectId": "${Parameters.ModuleConfigurationParameters.KeyVaultManagementUserId}",
|
||||
"permissions": {
|
||||
"certificates": [
|
||||
"All"
|
||||
],
|
||||
"keys": [
|
||||
"All"
|
||||
],
|
||||
"secrets": [
|
||||
"All"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tenantId": "${Subscriptions.AKS.TenantId}",
|
||||
"objectId": "${Parameters.ModuleConfigurationParameters.DevOpsServicePrincipalId}",
|
||||
"permissions": {
|
||||
"certificates": [
|
||||
"All"
|
||||
],
|
||||
"keys": [
|
||||
"All"
|
||||
],
|
||||
"secrets": [
|
||||
"All"
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"SecretsObject": {
|
||||
"Comments": "Creating an object so we can use a secretsobject parameter type in our ARM template",
|
||||
"Secrets": [ ]
|
||||
},
|
||||
"NetworkAcls": {
|
||||
"bypass": "AzureServices",
|
||||
"defaultAction": "Deny",
|
||||
"virtualNetworkRules": [
|
||||
{
|
||||
"subnet": "${Parameters.ModuleConfigurationParameters.VirtualNetwork.Subnets[0].Name}"
|
||||
}
|
||||
],
|
||||
"ipRules": []
|
||||
}
|
||||
},
|
||||
"DiagnosticStorageAccount": {
|
||||
"Name": "${Parameters.Organization}${Parameters.DeploymentName}diag01",
|
||||
"ResourceGroup": "${Parameters.InstanceName}-diagnostics-rg",
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
"dnsPrefix": {
|
||||
"value": "aks"
|
||||
},
|
||||
"osDiskSizeGb": {
|
||||
"agentOSDiskSizeGb": {
|
||||
"value": 30
|
||||
},
|
||||
"agentCount": {
|
||||
|
@ -26,7 +26,7 @@
|
|||
"servicePrincipalClientSecret": {
|
||||
"value": "secret"
|
||||
},
|
||||
"osType": {
|
||||
"agentOSType": {
|
||||
"value": "Linux"
|
||||
},
|
||||
"kubernetesVersion": {
|
||||
|
|
|
@ -2,9 +2,6 @@
|
|||
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
|
||||
"contentVersion": "1.0.0.0",
|
||||
"parameters": {
|
||||
"location": {
|
||||
"value": "West US 2"
|
||||
},
|
||||
"eventHubName": {
|
||||
"value": "org-event-hub-name"
|
||||
},
|
||||
|
@ -23,11 +20,20 @@
|
|||
"authorizationRulesRootManageSharedAccessKeyName": {
|
||||
"value": "RootManageSharedAccessKey"
|
||||
},
|
||||
"storageAccountId": {
|
||||
"diagnosticStorageAccountId": {
|
||||
"value": "/subscriptions/0000000000000000/resourceGroups/org-diagnostics-rg/providers/Microsoft.Storage/storageAccounts/storage-account-name"
|
||||
},
|
||||
"workspaceId": {
|
||||
"value": "/subscriptions/0000000000000000/resourcegroups/org-diagnostics-rg/providers/microsoft.operationalinsights/workspaces/workspace-name"
|
||||
},
|
||||
"logsRetentionInDays": {
|
||||
"value": 30
|
||||
},
|
||||
"networkAcls": {
|
||||
"value": {}
|
||||
},
|
||||
"vNetId": {
|
||||
"value": ""
|
||||
}
|
||||
}
|
||||
}
|
|
@ -428,3 +428,54 @@ Function Start-ExponentialBackoff () {
|
|||
|
||||
throw "Maximum number of retries reached. Number of retries: $MaxRetries. InnerException: $innerException";
|
||||
}
|
||||
|
||||
Function Format-FilePathSpecificToOS () {
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$Path
|
||||
)
|
||||
|
||||
# List of arguments that will be passed to Join-Path using splatting
|
||||
$arguments = @{};
|
||||
# Position to start the processing of the segments in a Path to build
|
||||
# the arugments to be passed to the Join-Path function. If the
|
||||
# Path starts with a slash, then we need to adjust the Start Position
|
||||
# accordingly because passing an empty string as "Path" argument to
|
||||
# Join-Path function results in an error being thrown.
|
||||
$startPosition = 0;
|
||||
|
||||
# Split the Path using forward / backward slash as delimiter
|
||||
$pathSegments = $Path -Split {$_ -eq "/" -or $_ -eq "\"};
|
||||
|
||||
# If the path starts with a slash, then the start position is one.
|
||||
# Also, remove the begining slash
|
||||
if($Path -like "/*" -or `
|
||||
$Path -like "\*" ) {
|
||||
$startPosition = 1;
|
||||
$Path = $Path.Substring(1, $Path.Length-1);
|
||||
}
|
||||
|
||||
# Case 1: Only one segment is found.
|
||||
# Example: Path = "toolkit.config.json"
|
||||
if($pathSegments.Length -eq $startPosition + 1) {
|
||||
return $Path;
|
||||
}
|
||||
# Case 2: Two or more segments found.
|
||||
# Example: Path = "Config/toolkit.config.json"
|
||||
elseif($pathSegments.Length -eq $startPosition + 2) {
|
||||
$arguments.Add("Path", $pathSegments[$startPosition + 0]);
|
||||
$arguments.Add("ChildPath", $pathSegments[$startPosition + 1]);
|
||||
return `
|
||||
Join-Path @arguments;
|
||||
}
|
||||
# Case 3: More than two segments found.
|
||||
# Example: Path = "Config/Temp/toolkit.config.json"
|
||||
elseif($pathSegments.Length -gt $startPosition + 2) {
|
||||
$arguments.Add("Path", $pathSegments[$startPosition + 0]);
|
||||
$arguments.Add("ChildPath", $pathSegments[$startPosition + 1]);
|
||||
$arguments.Add("AdditionalChildPath", $pathSegments[$($startPosition + 2)..$($startPosition + $pathSegments.Length - 1)]);
|
||||
return `
|
||||
Join-Path @arguments;
|
||||
}
|
||||
}
|
|
@ -665,17 +665,24 @@ Class AzureResourceManagerDeploymentService: IDeploymentService {
|
|||
}
|
||||
|
||||
[void] CreateResourceGroup([string] $resourceGroupName,
|
||||
[string] $location) {
|
||||
[string] $location,
|
||||
[object] $tags) {
|
||||
try {
|
||||
$resourceGroupFound = `
|
||||
Get-AzResourceGroup $resourceGroupName `
|
||||
-ErrorAction SilentlyContinue;
|
||||
|
||||
# Convert the object to hashtable
|
||||
$tags = `
|
||||
ConvertTo-HashTable -InputObject $tags;
|
||||
|
||||
if($null -eq $resourceGroupFound) {
|
||||
Start-ExponentialBackoff `
|
||||
-Expression { New-AzResourceGroup `
|
||||
-Name $resourceGroupName `
|
||||
-Location $location -Force; }
|
||||
-Location $location `
|
||||
-Tag $tags `
|
||||
-Force; }
|
||||
}
|
||||
}
|
||||
catch {
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
[string]
|
||||
$WorkingDirectory,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]
|
||||
$ToolkitConfigurationFilePath = '/Config/toolkit.config.json',
|
||||
[Parameter(Mandatory=$false)]
|
||||
[switch]
|
||||
$Validate,
|
||||
[Parameter(Mandatory=$false)]
|
||||
|
@ -57,6 +60,9 @@ Function Start-Deployment {
|
|||
$DefinitionPath,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]
|
||||
$ToolkitConfigurationFilePath,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]
|
||||
$ModuleConfigurationName,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]
|
||||
|
@ -78,7 +84,9 @@ Function Start-Deployment {
|
|||
Start-Init `
|
||||
-WorkingDirectory $WorkingDirectory `
|
||||
-DefinitionPath $DefinitionPath `
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName
|
||||
-ToolkitConfigurationFilePath $ToolkitConfigurationFilePath `
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName `
|
||||
-Validate:$($Validate.IsPresent);
|
||||
|
||||
$defaultWorkingDirectory = $initializedValues.WorkingDirectory
|
||||
$archetypeInstanceJson = $initializedValues.ArchetypeInstanceJson
|
||||
|
@ -342,18 +350,25 @@ Function Start-Deployment {
|
|||
Get-ResourceGroupName `
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName `
|
||||
-ModuleConfiguration $moduleConfiguration;
|
||||
Write-Debug "Resource Group is: $moduleConfigurationResourceGroupName";
|
||||
}
|
||||
elseif($Validate.IsPresent -eq $true) {
|
||||
# Retrieve the validation resource group name
|
||||
|
||||
$moduleConfigurationResourceGroupName = `
|
||||
Get-ValidationResourceGroupName `
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName;
|
||||
$initializedValues.ValidationResourceGroupInformation.Name;
|
||||
|
||||
# if location is provided in the validation resource group property of the configuration object in
|
||||
# the toolkit config json, then use it.
|
||||
if(![string]::IsNullOrEmpty($initializedValues.ValidationResourceGroupInformation.Location)) {
|
||||
$location = `
|
||||
$initializedValues.ValidationResourceGroupInformation.Location;
|
||||
}
|
||||
}
|
||||
Write-Debug "Resource Group is: $moduleConfigurationResourceGroupName";
|
||||
|
||||
New-ResourceGroup `
|
||||
-ResourceGroupName $moduleConfigurationResourceGroupName `
|
||||
-ResourceGroupLocation $location `
|
||||
-Tags $moduleConfigurationResourceGroupInformation.Tags `
|
||||
-Validate:$($Validate.IsPresent);
|
||||
|
||||
Write-Debug "Resource Group successfully created";
|
||||
|
@ -459,7 +474,8 @@ Function Start-Deployment {
|
|||
|
||||
# Destroy the validation Resource Group
|
||||
Remove-ValidationResourceGroup `
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName;
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName `
|
||||
-ValidationResourceGroupInformation $initializedValues.ValidationResourceGroupInformation;
|
||||
|
||||
Write-Host "Validation Resource Group is destroyed."
|
||||
}
|
||||
|
@ -485,6 +501,9 @@ Function Start-TearDownEnvironment {
|
|||
$DefinitionPath,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]
|
||||
$ToolkitConfigurationFilePath,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]
|
||||
$ModuleConfigurationName,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]
|
||||
|
@ -502,7 +521,9 @@ Function Start-TearDownEnvironment {
|
|||
Start-Init `
|
||||
-WorkingDirectory $WorkingDirectory `
|
||||
-DefinitionPath $DefinitionPath `
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName
|
||||
-ToolkitConfigurationFilePath $ToolkitConfigurationFilePath `
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName `
|
||||
-Validate;
|
||||
|
||||
$archetypeInstanceJson = $initializedValues.ArchetypeInstanceJson
|
||||
$archetypeInstanceName = $initializedValues.ArchetypeInstanceName
|
||||
|
@ -681,7 +702,13 @@ Function Start-Init {
|
|||
$DefinitionPath,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]
|
||||
$WorkingDirectory
|
||||
$ToolkitConfigurationFilePath,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[string]
|
||||
$WorkingDirectory,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[switch]
|
||||
$Validate
|
||||
)
|
||||
try {
|
||||
$defaultWorkingDirectory = `
|
||||
|
@ -690,9 +717,13 @@ Function Start-Init {
|
|||
|
||||
Write-Debug "Working directory is: $defaultWorkingDirectory";
|
||||
|
||||
$global:factory = `
|
||||
$bootstrappedValues = `
|
||||
Invoke-Bootstrap `
|
||||
-WorkingDirectory $defaultWorkingDirectory;
|
||||
-WorkingDirectory $defaultWorkingDirectory `
|
||||
-ToolkitConfigurationFilePath $ToolkitConfigurationFilePath `
|
||||
-Mode @{ "False" = "deploy"; "True" = "validate"; }[$Validate.ToString()];
|
||||
|
||||
$global:factory = $bootstrappedValues.Factory
|
||||
|
||||
$global:deploymentService = `
|
||||
$factory.GetInstance('IDeploymentService');
|
||||
|
@ -738,6 +769,7 @@ Function Start-Init {
|
|||
WorkingDirectory = $defaultWorkingDirectory
|
||||
ArchetypeInstanceJson = $archetypeInstanceJson
|
||||
ArchetypeInstanceName = $archetypeInstanceName
|
||||
ValidationResourceGroupInformation = $bootstrappedValues.ValidationResourceGroupInformation
|
||||
Location = $location
|
||||
}
|
||||
}
|
||||
|
@ -1232,17 +1264,23 @@ Function Invoke-Bootstrap {
|
|||
param (
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$WorkingDirectory
|
||||
$WorkingDirectory,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$ToolkitConfigurationFilePath,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$Mode
|
||||
)
|
||||
|
||||
$toolkitConfigurationFileName = `
|
||||
Join-Path "Config" -ChildPath "toolkit.config.json";
|
||||
$ToolkitConfigurationFilePath = `
|
||||
Format-FilePathSpecificToOS -Path $ToolkitConfigurationFilePath;
|
||||
|
||||
try {
|
||||
# Build toolkit configuration from file
|
||||
$toolkitConfigurationJson = `
|
||||
New-ConfigurationInstance `
|
||||
-FilePath $toolkitConfigurationFileName `
|
||||
-FilePath $ToolkitConfigurationFilePath `
|
||||
-WorkingDirectory $WorkingDirectory;
|
||||
|
||||
# Getting cache information from toolkit configuration
|
||||
|
@ -1260,6 +1298,16 @@ Function Invoke-Bootstrap {
|
|||
|
||||
Write-Debug "Audit storage information is: $(ConvertTo-Json $auditStorageInformation -Depth 100)";
|
||||
|
||||
# Validation Resource Group details are only needed in validate mode
|
||||
if($Mode -eq "validate") {
|
||||
# Getting validation resource group information from toolkit configuration
|
||||
$validationResourceGroupInformation = `
|
||||
Get-ValidationResourceGroupInformation `
|
||||
-ToolkitConfigurationJson $toolkitConfigurationJson;
|
||||
|
||||
Write-Debug "Validation Resource Group information is: $(ConvertTo-Json $validationResourceGroupInformation -Depth 100)";
|
||||
}
|
||||
|
||||
# Let's create a new instance of Bootstrap
|
||||
$bootstrap = [Initialize]::new();
|
||||
|
||||
|
@ -1304,7 +1352,10 @@ Function Invoke-Bootstrap {
|
|||
throw "ToolkitComponents.Audit.StorageType not supported, currently supported types are: StorageAccount and Local";
|
||||
}
|
||||
|
||||
return $factory;
|
||||
# Return an object that wraps the factory and the validation resource group information.
|
||||
return @{ "Factory" = $factory
|
||||
"ValidationResourceGroupInformation" = $ValidationResourceGroupInformation
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Host "An error ocurred while running Invoke-Bootstrap";
|
||||
|
@ -1514,6 +1565,41 @@ Function Get-AuditStorageInformation {
|
|||
}
|
||||
}
|
||||
|
||||
Function Get-ValidationResourceGroupInformation {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[Parameter(Mandatory=$true)]
|
||||
[hashtable]
|
||||
$ToolkitConfigurationJson
|
||||
)
|
||||
|
||||
try {
|
||||
$validationResourceGroupInformation = @{};
|
||||
|
||||
# At a minimum, we expect the configuration object to have an property named "ValidationResourceGroup" of type object
|
||||
# and a child property named "Name" of type string. Other properties including Location and Tags are optional.
|
||||
if ($null -ne $ToolkitConfigurationJson.Configuration.ValidationResourceGroup -and `
|
||||
![string]::IsNullOrEmpty($ToolkitConfigurationJson.Configuration.ValidationResourceGroup.Name)) {
|
||||
# Let's get the Validation Resource Group information
|
||||
|
||||
$validationResourceGroupInformation.Name = $ToolkitConfigurationJson.Configuration.ValidationResourceGroup.Name;
|
||||
$validationResourceGroupInformation.Location = $ToolkitConfigurationJson.Configuration.ValidationResourceGroup.Location;
|
||||
$validationResourceGroupInformation.Tags = $ToolkitConfigurationJson.Configuration.ValidationResourceGroup.Tags;
|
||||
}
|
||||
else {
|
||||
$validationResourceGroupInformation.Name = `
|
||||
Get-UniqueString($ArchetypeInstanceName);
|
||||
}
|
||||
|
||||
return $validationResourceGroupInformation;
|
||||
}
|
||||
catch {
|
||||
Write-Host "An error ocurred while running Get-ValidationResourceGroupInformation";
|
||||
Write-Host $_;
|
||||
throw $_;
|
||||
}
|
||||
}
|
||||
|
||||
Function Get-ModuleConfiguration {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
|
@ -2112,6 +2198,9 @@ Function New-ResourceGroup {
|
|||
[Parameter(Mandatory=$false)]
|
||||
[string]
|
||||
$ResourceGroupLocation,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[object]
|
||||
$Tags,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[switch]
|
||||
$Validate
|
||||
|
@ -2120,7 +2209,8 @@ Function New-ResourceGroup {
|
|||
try {
|
||||
$deploymentService.CreateResourceGroup(
|
||||
$resourceGroupName,
|
||||
$resourceGroupLocation);
|
||||
$resourceGroupLocation,
|
||||
$Tags);
|
||||
}
|
||||
catch {
|
||||
Write-Host "An error ocurred while running New-ResourceGroup";
|
||||
|
@ -3035,18 +3125,20 @@ Function Remove-ValidationResourceGroup() {
|
|||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$ArchetypeInstanceName
|
||||
$ArchetypeInstanceName,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[object]
|
||||
$ValidationResourceGroupInformation
|
||||
)
|
||||
|
||||
$resourceGroupFound = `
|
||||
Assert-ValidationResourceGroup `
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName;
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName `
|
||||
-ValidationResourceGroupInformation $ValidationResourceGroupInformation;
|
||||
|
||||
if($resourceGroupFound -eq $true) {
|
||||
|
||||
$resourceGroupName = `
|
||||
Get-ValidationResourceGroupName `
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName;
|
||||
$resourceGroupName = $ValidationResourceGroupInformation.Name;
|
||||
|
||||
Start-ExponentialBackoff `
|
||||
-Expression { Remove-AzResourceGroup `
|
||||
|
@ -3065,12 +3157,16 @@ Function Assert-ValidationResourceGroup() {
|
|||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$ArchetypeInstanceName
|
||||
$ArchetypeInstanceName,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[object]
|
||||
$ValidationResourceGroupInformation
|
||||
)
|
||||
|
||||
$resourceGroup = `
|
||||
Get-ValidationResourceGroup `
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName;
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName `
|
||||
-ValidationResourceGroupInformation $ValidationResourceGroupInformation;
|
||||
|
||||
if($null -ne $resourceGroup) {
|
||||
return $true;
|
||||
|
@ -3086,30 +3182,19 @@ Function Get-ValidationResourceGroup() {
|
|||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$ArchetypeInstanceName
|
||||
$ArchetypeInstanceName,
|
||||
[Parameter(Mandatory=$false)]
|
||||
[object]
|
||||
$ValidationResourceGroupInformation
|
||||
)
|
||||
|
||||
$resourceGroupName = `
|
||||
Get-ValidationResourceGroupName `
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName;
|
||||
$resourceGroupName = $ValidationResourceGroupInformation.Name;
|
||||
|
||||
return `
|
||||
Get-AzResourceGroup $resourceGroupName `
|
||||
-ErrorAction SilentlyContinue;
|
||||
}
|
||||
|
||||
Function Get-ValidationResourceGroupName() {
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$ArchetypeInstanceName
|
||||
)
|
||||
|
||||
return `
|
||||
Get-UniqueString($ArchetypeInstanceName);
|
||||
}
|
||||
|
||||
# Entry point script, used when invoking ModuleConfigurationDeployment.ps1
|
||||
# In order to allow the module to be imported (Import-Module), let's
|
||||
# verify if the mandatory parameters are not passed.
|
||||
|
@ -3119,12 +3204,14 @@ if (![string]::IsNullOrEmpty($DefinitionPath)) {
|
|||
Start-TearDownEnvironment `
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName `
|
||||
-DefinitionPath $DefinitionPath `
|
||||
-ToolkitConfigurationFilePath $ToolkitConfigurationFilePath `
|
||||
-ModuleConfigurationName $ModuleConfigurationName `
|
||||
-WorkingDirectory $WorkingDirectory
|
||||
}
|
||||
else {
|
||||
Start-Deployment `
|
||||
-DefinitionPath $DefinitionPath `
|
||||
-ToolkitConfigurationFilePath $ToolkitConfigurationFilePath `
|
||||
-ArchetypeInstanceName $ArchetypeInstanceName `
|
||||
-ModuleConfigurationName $ModuleConfigurationName `
|
||||
-WorkingDirectory $WorkingDirectory `
|
||||
|
|
|
@ -35,7 +35,7 @@ Describe "Custom Script Execution Unit Test Cases" {
|
|||
$command,
|
||||
$arguments
|
||||
);
|
||||
$result.value | Should Be "pwsh";
|
||||
$result | Should Be "pwsh";
|
||||
}
|
||||
|
||||
It "Should execute PowerShell Cmdlets" {
|
||||
|
@ -47,7 +47,7 @@ Describe "Custom Script Execution Unit Test Cases" {
|
|||
@{}
|
||||
);
|
||||
|
||||
$result.value | Should Be "pwsh-test";
|
||||
$result | Should Be "pwsh-test";
|
||||
}
|
||||
|
||||
It "Should execute a PowerShell Script with Arguments passed" {
|
||||
|
@ -66,7 +66,7 @@ Describe "Custom Script Execution Unit Test Cases" {
|
|||
$arguments
|
||||
);
|
||||
|
||||
$result.value | Should Be "pwsh-script-test";
|
||||
$result | Should Be "pwsh-script-test";
|
||||
}
|
||||
|
||||
It "Should execute a Bash script" {
|
||||
|
@ -87,7 +87,7 @@ Describe "Custom Script Execution Unit Test Cases" {
|
|||
|
||||
|
||||
|
||||
$result.value | Should Be "bash-script-test";
|
||||
$result | Should Be "bash-script-test";
|
||||
}
|
||||
|
||||
It "Should execute a Bash script and preserve the order of arguments passed" {
|
||||
|
@ -122,7 +122,7 @@ Describe "Custom Script Execution Unit Test Cases" {
|
|||
[PSCustomObject]@{}
|
||||
);
|
||||
|
||||
$result.value | Should Be "bash-test";
|
||||
$result | Should Be "bash-test";
|
||||
}
|
||||
|
||||
It "Should throw script not supported error for invalid set of commands passed" {
|
||||
|
|
Загрузка…
Ссылка в новой задаче