ps/Modules/Alkami.DevOps.Common/Public/Get-DynamicAwsRegionParameter.ps1
2023-05-30 22:51:22 -07:00

71 lines
2.4 KiB
PowerShell

function Get-DynamicAwsRegionParameter {
<#
.SYNOPSIS
Returns a RuntimeDefinedParameterDictionary with all Alkami-permitted AWS Regions
.DESCRIPTION
Returns a RuntimeDefinedParameterDictionary with all Alkami-permitted AWS Regions for use as a DynamicParameter in functions.
.PARAMETER DynamicParameterName
The parameter name to set on the return value. Defaults to Region
.PARAMETER ParameterSetName
The parameter set to associate the dynamic parameter with. Defaults to all parameter sets.
.PARAMETER IsMandatoryParameter
Wheter or not the parameter is mandatory. Defaults to false.
.EXAMPLE
Get-DynamicAwsRegionParameter
Key Value
--- -----
Region System.Management.Automation.RuntimeDefinedParameter
.EXAMPLE
Get-DynamicAwsRegionParameter -DynamicParameterName "OhNoHeDidnt"
Key Value
--- -----
OhNoHeDidnt System.Management.Automation.RuntimeDefinedParameter
.LINK
Get-SupportedAwsRegions
#>
[CmdletBinding()]
[OutputType([System.Management.Automation.RuntimeDefinedParameterDictionary])]
param(
[Parameter(Mandatory = $false)]
[string]$DynamicParameterName = "Region",
[Parameter(Mandatory = $false)]
[string]$ParameterSetName = "__AllParameterSets",
[Parameter(Mandatory = $false)]
[switch]$IsMandatoryParameter
)
# Define the Paramater Attributes
$runtimeParameterDictionary = New-Object -Type System.Management.Automation.RuntimeDefinedParameterDictionary
$attributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
$parameterAttribute = New-Object -Type System.Management.Automation.ParameterAttribute
$parameterAttribute.Mandatory = $IsMandatoryParameter
$parameterAttribute.ParameterSetName = $ParameterSetName
$parameterAttribute.HelpMessage = "The AWS Region to Use for Requests"
$attributeCollection.Add($parameterAttribute)
# Generate and add the ValidateSet
$supportedRegions = Get-SupportedAwsRegions
$validateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($supportedRegions)
$attributeCollection.Add($validateSetAttribute)
# Create the dynamic parameter
$runtimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($DynamicParameterName, [string], $attributeCollection)
$runtimeParameterDictionary.Add($DynamicParameterName, $RuntimeParameter)
return $runtimeParameterDictionary
}