Skip to content

Fixing subscription values #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@

## Synopsis

This is a PowerShell module that provides a set of cmdlets to manage Azure Landing Zones.
This is a PowerShell module that provides a set of cmdlets to create and manage Azure Landing Zones.

## Description

This module provides a set of cmdlets to manage Azure Landing Zones.
This module provides a set of cmdlets to create and manage Azure Landing Zones.

## Why

The goal of this project it is to make easy to get started with Azure Landing Zones and to speed up some basic tasks that you would be using while managing your Azure Landing Zones.
The goal of this project it is to make easy to get started with Azure Landing Zones and to speed up some basic tasks that you would need to perform whilst managing your Azure Landing Zones.

## Getting Started

### Prerequisites

In order to use this module you will need powershell 7.1 or higher.
In order to use this module you will need PowerShell 7.1 or higher.

### Installation

Expand All @@ -32,24 +32,31 @@ Install-Module -Name ALZ

### Quick start

Before start o utilize the functionality of the module you can verify if you have all the prerequisites installed, with the built in command:
Before you start you can utilize the functionality of the module to verify if you have all the prerequisites installed with the built in command:

```powershell
Test-ALZPrerequisites
Test-ALZRequirement
```

#### Create a new Azure Landing Zone Environment
Currently this tests for:

```powershell
* Supported minimum PowerShell version
* Azure PowerShell Module
* Git
* Azure CLI
* Bicep

#### Create a new Azure Landing Zone Environment

```powershell
New-ALZEnvironment -o <output_directory>
```

## Development

### Prerequisites
### Development Prerequisites

In order to develop this module you will need powershell 7.1 or higher.
In order to develop this module you will need PowerShell 7.1 or higher.

### Commands to install a build locally

Expand All @@ -61,22 +68,16 @@ Import-Module .\src\Artifacts\ALZ.psd1 -Force

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

## Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
trademarks or logos is subject to and must follow
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.
Any use of third-party trademarks or logos are subject to those third-party's policies.
2 changes: 1 addition & 1 deletion src/ALZ/Assets/alz-bicep-config/v0.14.1-pre.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
},
"AllSubscriptionIds": {
"Type": "Computed",
"Process": "@($args | Select-Object -Unique)",
"Process": "@($args | ForEach-Object { $_.ToLower() } | Select-Object -Unique)",
"Value": [
"{%ManagementSubscriptionId%}",
"{%ConnectivitySubscriptionId%}",
Expand Down
1 change: 1 addition & 0 deletions src/ALZ/Private/Edit-ALZConfigurationFilesInPlace.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function Edit-ALZConfigurationFilesInPlace {
if ($null -ne $configKey.Value.Process) {
$scriptBlock = [ScriptBlock]::Create($configKey.Value.Process)
$formattedValues = Invoke-Command -ScriptBlock $scriptBlock -ArgumentList $formattedValues
$formattedValues = @($formattedValues)
}

$bicepConfigNode[$leafPropertyName] = $formattedValues
Expand Down
97 changes: 97 additions & 0 deletions src/Tests/Unit/Private/Edit-ALZConfigurationFilesInPlace.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,103 @@ InModuleScope 'ALZ' {
-Scope It
}

It 'Computed, Processed array values replace values correctly in a case insensitive deduplication.' {
$config = [pscustomobject]@{
Nested = [pscustomobject]@{
Type = "Computed"
Description = "A Test Value"
Process = '@($args | ForEach-Object { $_.ToLower() } | Select-Object -Unique)'
Value = @(
"A",
"a",
"A",
"a"
)
Targets = @(
[pscustomobject]@{
Name = "parValue.value"
Destination = "Parameters"
})
}
}

$fileContent = '{
"parameters": {
"parValue": {
"value": []
}
}
}'

$expectedContent = '{
"parameters": {
"parValue": {
"value": [ "a" ]
}
}
}'

Mock -CommandName Get-Content -ParameterFilter { $Path -eq $testFile1Name } -MockWith {
$fileContent
}

$expectedContent = Format-ExpectedResult -expectedJson $expectedContent

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config

Should -Invoke -CommandName Out-File `
-ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
-Scope It
}

It 'Computed, Processed array values replace values correctly and keep array type when only one item remains.' {
$config = [pscustomobject]@{
Nested = [pscustomobject]@{
Type = "Computed"
Description = "A Test Value"
Process = '@($args | Select-Object -Unique)'
Value = @(
"1",
"1",
"1"
)
Targets = @(
[pscustomobject]@{
Name = "parValue.value"
Destination = "Parameters"
})
}
}

$fileContent = '{
"parameters": {
"parValue": {
"value": []
}
}
}'

$expectedContent = '{
"parameters": {
"parValue": {
"value": [ "1" ]
}
}
}'

Mock -CommandName Get-Content -ParameterFilter { $Path -eq $testFile1Name } -MockWith {
$fileContent
}

$expectedContent = Format-ExpectedResult -expectedJson $expectedContent

Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination '.' -configuration $config

Should -Invoke -CommandName Out-File `
-ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
-Scope It
}

It 'Computed, Processed values replace values correctly' {
$config = [pscustomobject]@{
Nested = [pscustomobject]@{
Expand Down