Skip to content
Open
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
50 changes: 50 additions & 0 deletions VaporShell/Public/Intrinsic Functions/Add-FnLength.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
function Add-FnLength {
<#
.SYNOPSIS
Adds the intrinsic function "Fn::Length" to a resource property

.DESCRIPTION
The intrinsic function Fn::Length returns the number of elements within an array or the number of characters in a string.

.LINK
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-length.html

.PARAMETER Object
The array or string for which you want to get the length.

.EXAMPLE
Add-FnLength -Object (Add-FnSplit -Delimiter "," -SourceString "a,b,c")

When the template is exported, this will convert to: {"Fn::Length":{"Fn::Split":[",","a,b,c"]}}

.NOTES
You can use the following functions in the Fn::Length function:
Fn::Split
Fn::GetAZs
Ref

.FUNCTIONALITY
Vaporshell
#>
[OutputType('Vaporshell.Function.Length')]
[cmdletbinding()]
Param
(
[parameter(Mandatory = $true,Position = 0)]
[ValidateScript({
$allowedTypes = "Vaporshell.Function.Split","Vaporshell.Function.GetAZs","Vaporshell.Function.Ref","System.String","System.Object[]"
if ([string]$($_.PSTypeNames) -match "($(($allowedTypes|ForEach-Object{[RegEx]::Escape($_)}) -join '|'))") {
$true
}
else {
$PSCmdlet.ThrowTerminatingError((New-VSError -String "This parameter only accepts the following types: $($allowedTypes -join ", "). The current types of the value are: $($_.PSTypeNames -join ", ")."))
}
})]
$Object
)
$obj = [PSCustomObject][Ordered]@{
"Fn::Length" = $Object
}
$obj | Add-ObjectDetail -TypeName 'Vaporshell.Function','Vaporshell.Function.Length'
Write-Verbose "Resulting JSON from $($MyInvocation.MyCommand): `n`n`t$($obj | ConvertTo-Json -Depth 10 -Compress)`n"
}
38 changes: 38 additions & 0 deletions VaporShell/Public/Intrinsic Functions/Add-FnToJsonString.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
function Add-FnToJsonString {
<#
.SYNOPSIS
Adds the intrinsic function "Fn::ToJsonString" to a resource property

.DESCRIPTION
The intrinsic function Fn::ToJsonString converts an object or array to its corresponding JSON string.

.LINK
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ToJsonString.html

.PARAMETER Object
The object or array to convert to a JSON string.

.EXAMPLE
Add-FnToJsonString -Object @{key1 = "value1"; key2 = "value2"}

When the template is exported, this will convert to: {"Fn::ToJsonString":{"key1":"value1","key2":"value2"}}

.NOTES
You can use any intrinsic function within Fn::ToJsonString.

.FUNCTIONALITY
Vaporshell
#>
[OutputType('Vaporshell.Function.ToJsonString')]
[cmdletbinding()]
Param
(
[parameter(Mandatory = $true,Position = 0)]
$Object
)
$obj = [PSCustomObject][Ordered]@{
"Fn::ToJsonString" = $Object
}
$obj | Add-ObjectDetail -TypeName 'Vaporshell.Function','Vaporshell.Function.ToJsonString'
Write-Verbose "Resulting JSON from $($MyInvocation.MyCommand): `n`n`t$($obj | ConvertTo-Json -Depth 10 -Compress)`n"
}
2 changes: 1 addition & 1 deletion VaporShell/Public/Primary Functions/New-VaporResource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function New-VaporResource {
[System.String]
$DeletionPolicy,
[parameter(Mandatory = $false)]
[ValidateSet("Delete","Retain","Snapshot","RetainExceptOnCreate")]
[ValidateSet("Delete","Retain","Snapshot")]
[System.String]
$UpdateReplacePolicy,
[parameter(Mandatory = $false,Position = 5)]
Expand Down
2 changes: 1 addition & 1 deletion VaporShell/VaporShell.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Version number of this module.
# NB do not change this in ECP when rebuilding only without making manual code changes in the repository.
# Date will be appended to the PS module version automatically as part of the build process
ModuleVersion = '2.16.0'
ModuleVersion = '2.17.0'

# ID used to uniquely identify this module
GUID = 'd526494c-6e59-41ff-ad05-eedbc1473b6a'
Expand Down
4 changes: 2 additions & 2 deletions ci/Convert-SpecToFunction.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function $FunctionName {

UpdateReplacePolicy differs from the DeletionPolicy attribute in that it only applies to resources replaced during stack updates. Use DeletionPolicy for resources deleted when a stack is deleted, or when the resource definition itself is deleted from the template as part of a stack update.

You must use one of the following options: "Delete","Retain","Snapshot","RetainExceptOnCreate"`n
You must use one of the following options: "Delete","Retain","Snapshot"`n
"@
}

Expand Down Expand Up @@ -408,7 +408,7 @@ function $FunctionName {

if ($addCommonCfnProperty['UpdateReplacePolicy']) {
$scriptContents += @"
[ValidateSet("Delete","Retain","Snapshot","RetainExceptOnCreate")]
[ValidateSet("Delete","Retain","Snapshot")]
[System.String]
`$UpdateReplacePolicy,`n
"@
Expand Down