-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add support for an existing resource group to the build-image.ps1 script #13933
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
Open
eduardkuijpers86
wants to merge
17
commits into
actions:main
Choose a base branch
from
eduardkuijpers86:feature/add-fixed-rg-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+169
−22
Open
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0af816f
Added support for existing resource groups
eduardkuijpers86 6a8fbe9
Added pester tests
eduardkuijpers86 c12113e
Merge branch 'actions:main' into feature/add-fixed-rg-support
eduardkuijpers86 c1e91fb
Removed whitespaces
eduardkuijpers86 03f8644
Refactor to remove duplication in passing variables to packer
eduardkuijpers86 fd76281
Fixed packer variable for build_resource_group_name
eduardkuijpers86 4061d3b
Updated documentation packer variables
eduardkuijpers86 c4428f4
added function to add -var flag
eduardkuijpers86 478aa59
Added packer argument checks in current pester switch tests
eduardkuijpers86 b5a23a6
removed unused afterall
eduardkuijpers86 74699ad
Merge branch 'actions:main' into feature/add-fixed-rg-support
eduardkuijpers86 f690ac9
Fix indentation
eduardkuijpers86 255cf07
Merge branch 'feature/add-fixed-rg-support' of https://github.com/edu…
eduardkuijpers86 b7d76e3
Updated doc
eduardkuijpers86 3e45df1
Fixed doc typo
eduardkuijpers86 9cdddc2
Fixed doc optional variables list
eduardkuijpers86 a6324c1
Merge branch 'actions:main' into feature/add-fixed-rg-support
eduardkuijpers86 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| Describe "build-image.ps1 parameter sets" { | ||
| BeforeAll { | ||
| $scriptPath = (Resolve-Path (Join-Path $PSScriptRoot "..\build-image.ps1")).Path | ||
| $command = Get-Command -Name $scriptPath | ||
| } | ||
|
|
||
| It "defines exactly two parameter sets" { | ||
| $command.ParameterSets | Should -HaveCount 2 | ||
| } | ||
|
|
||
| It "requires temp resource group parameters in TempResourceGroup set" { | ||
| $tempSet = $command.ParameterSets | Where-Object Name -eq "TempResourceGroup" | ||
| $tempSet | Should -Not -BeNullOrEmpty | ||
|
|
||
| ($tempSet.Parameters | Where-Object Name -eq "Location") | Should -Not -BeNullOrEmpty | ||
| ($tempSet.Parameters | Where-Object Name -eq "Location").IsMandatory | Should -BeTrue | ||
|
|
||
| ($tempSet.Parameters | Where-Object Name -eq "TempResourceGroupName") | Should -Not -BeNullOrEmpty | ||
| ($tempSet.Parameters | Where-Object Name -eq "TempResourceGroupName").IsMandatory | Should -BeTrue | ||
|
|
||
| $tempSet.Parameters.Name | Should -Not -Contain "ExistingResourceGroupName" | ||
| } | ||
|
|
||
| It "requires existing resource group parameter in ExistingResourceGroup set" { | ||
| $existingSet = $command.ParameterSets | Where-Object Name -eq "ExistingResourceGroup" | ||
| $existingSet | Should -Not -BeNullOrEmpty | ||
|
|
||
| ($existingSet.Parameters | Where-Object Name -eq "ExistingResourceGroupName") | Should -Not -BeNullOrEmpty | ||
| ($existingSet.Parameters | Where-Object Name -eq "ExistingResourceGroupName").IsMandatory | Should -BeTrue | ||
|
|
||
| $existingSet.Parameters.Name | Should -Not -Contain "Location" | ||
| $existingSet.Parameters.Name | Should -Not -Contain "TempResourceGroupName" | ||
| } | ||
| } | ||
|
|
||
| Describe "build-image.ps1 switch" { | ||
| BeforeAll { | ||
| $scriptPath = (Resolve-Path (Join-Path $PSScriptRoot "..\build-image.ps1")).Path | ||
|
|
||
| Mock -CommandName Write-Host | ||
|
|
||
| $global:packerInvocations = @() | ||
| Mock -CommandName packer -MockWith { | ||
| param( | ||
| [Parameter(ValueFromRemainingArguments = $true)] | ||
| [string[]] $arguments | ||
| ) | ||
|
|
||
| $global:packerInvocations += ,$arguments | ||
| "mocked packer output" | ||
| } | ||
| } | ||
|
|
||
| Context "TempResourceGroup" { | ||
| It "calls packer build with temp resource group parameters" { | ||
|
|
||
| & $scriptPath -TemplatePath ".\" ` | ||
| -BuildTemplateName "template.TestBuild" ` | ||
| -TempResourceGroupName "TestTempRG" ` | ||
| -ClientId "TestClientId" ` | ||
| -Location "TestLocation" ` | ||
| -ImageName "TestImage" ` | ||
| -ImageResourceGroupName "TestImageRG" ` | ||
| -SubscriptionId "TestSubId" ` | ||
| -TenantId "TestTenantId" ` | ||
| -ImageOS "TestOS" | Out-Null | ||
|
|
||
| Should -Invoke -CommandName Write-Host -Times 1 -Exactly -ParameterFilter { | ||
| $Object -eq "Use temporary resource group TestTempRG" | ||
| } | ||
|
|
||
| Should -Invoke -CommandName packer -Times 1 -Exactly -ParameterFilter { | ||
| $arguments -contains "temp_resource_group_name=TestTempRG" -and | ||
| $arguments -contains "location=TestLocation" -and | ||
| $arguments -contains "-var" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Context "ExistingResourceGroup" { | ||
| It "calls packer build with existing resource group parameters" { | ||
|
|
||
| & $scriptPath -TemplatePath ".\" ` | ||
| -BuildTemplateName "template.TestBuild" ` | ||
| -ExistingResourceGroupName "TestExistingRG" ` | ||
| -ClientId "TestClientId" ` | ||
| -ImageName "TestImage" ` | ||
| -ImageResourceGroupName "TestImageRG" ` | ||
| -SubscriptionId "TestSubId" ` | ||
| -TenantId "TestTenantId" ` | ||
| -ImageOS "TestOS" | Out-Null | ||
|
|
||
| Should -Invoke -CommandName Write-Host -Times 1 -Exactly -ParameterFilter { | ||
| $Object -eq "Use existing resource group TestExistingRG" | ||
| } | ||
|
|
||
| Should -Invoke -CommandName packer -Times 1 -Exactly -ParameterFilter { | ||
| $arguments -contains "build_resource_group_name=TestExistingRG" -and | ||
| $arguments -contains "-var" | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.