Skip to content

Commit

Permalink
Merge pull request #11 from fireflycons/dev
Browse files Browse the repository at this point in the history
Closes #9, Fixes #10
  • Loading branch information
fireflycons authored Mar 31, 2019
2 parents a0404af + 42bf06f commit aa1dc08
Show file tree
Hide file tree
Showing 15 changed files with 1,439 additions and 152 deletions.
4 changes: 2 additions & 2 deletions PSCloudFormation/PSCloudFormation.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PSCloudFormation.psm1'

# Version number of this module.
ModuleVersion = '0.3.1'
ModuleVersion = '0.4.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -110,7 +110,7 @@
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = 'Fix several issues with stack updates. Now supports oversize templates (> 51200 bytes)'
ReleaseNotes = 'Outputs stack events to console when waiting for updates to complete.'

} # End of PSData hashtable

Expand Down
2 changes: 1 addition & 1 deletion PSCloudFormation/Private/Get-CloudFormationBucket.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function Get-CloudFormationBucket

}

$bucketName = "cf-templates-pscloudformation-$(Get-CurrentRegion -CredentialArguments $CredentialArguments)-$((Get-STSCallerIdentity).Account)"
$bucketName = "cf-templates-pscloudformation-$(Get-CurrentRegion -CredentialArguments $CredentialArguments)-$((Get-STSCallerIdentity @CredentialArguments).Account)"

try
{
Expand Down
44 changes: 44 additions & 0 deletions PSCloudFormation/Private/Get-StackEvents.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function Get-StackEvents
{
<#
.SYNOPSIS
Recursively get stack events from parent and nested stacks
.PARAMETER StackArn
ARN(s) of stack(s) to get events for
.OUTPUTS
[Amazon.CloudFormation.Model.StackEvent[]]
Array of stack failure events.
#>
param
(
[string[]]$StackArn,
[hashtable]$CredentialArguments,
[DateTime]$EventsAfter
)

$StackArn |
Where-Object {
$null -ne $_
} |
ForEach-Object {

Get-CFNStackEvent -StackName $_ @CredentialArguments |
Where-Object {
$_.Timestamp -gt $EventsAfter
}

Get-CFNStackResourceList -StackName $_ @CredentialArguments |
Where-Object {
$_.ResourceType -ieq 'AWS::CloudFormation::Stack'
} |
ForEach-Object {

if ($_ -and $_.PhysicalResourceId)
{
Get-StackEvents -StackArn $_.PhysicalResourceId -EventsAfter $EventsAfter -CredentialArguments $CredentialArguments
}
}
}
}
42 changes: 0 additions & 42 deletions PSCloudFormation/Private/Get-StackFailureEvents.ps1

This file was deleted.

93 changes: 93 additions & 0 deletions PSCloudFormation/Private/Wait-PSCFNStack.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
function Wait-PSCFNStack
{
<#
.SYNOPSIS
Wait for a stack to do something, printing events along the way.
.PARAMETER StackArn
Stack(s) to wait on.
.PARAMETER CredentialArguments
Hash of common credetial and region arguments.
.PARAMETER StartTime
Time the stack update command was issued
.OUTPUTS
[bool] true if operation succeeded; else false
#>
param
(
[string[]]$StackArn,

[hashtable]$CredentialArguments,

[DateTime]$StartTime
)

$checkTime = $StartTime

# Copy input array so as not to trash it.
$arns = $StackArn |
Foreach-Object {
$_
}

# States indicating any stack operation complete
$completionStates = @(
'CREATE_COMPLETE'
'CREATE_FAILED'
'DELETE_COMPLETE'
'DELETE_FAILED'
'ROLLBACK_COMPLETE'
'ROLLBACK_FAILED'
'UPDATE_COMPLETE'
'UPDATE_ROLLBACK_COMPLETE'
'UPDATE_ROLLBACK_FAILED'
)

$anyFailed = $false

$writeHeaders = $true

while (($arns | Measure-Object).Count -gt 0)
{
Start-Sleep -Seconds 15

$stacks = $arns |
Foreach-Object {

Get-CFNStack -StackName $_ @CredentialArguments
}

$completedStackArns = $stacks |
Where-Object {

if ($_.StackStatus -ilike '*ROLLBACK*' -or $_.StackStatus -ilike '*FAILED*')
{
$anyFailed = $true
}

$completionStates -icontains $_.StackStatus
} |
Select-Object -ExpandProperty StackId

if ($completedStackArns)
{
$arns = Compare-Object -ReferenceObject $arns -DifferenceObject $completedStackArns -PassThru
}

$ts = Write-StackEvents -StackArn $arns -EventsAfter $checkTime $CredentialArguments -WriteHeaders $writeHeaders
$writeHeaders = $false

if ($ts)
{
$checkTime = $ts
}
}

Write-StackEvents -StackArn $StackArn -EventsAfter $checkTime $CredentialArguments -WriteHeaders $false

# Output boolean - any final state containing ROLLBACK or FAILED indicates operation unsuccessful
-not $anyFailed
}
Loading

0 comments on commit aa1dc08

Please sign in to comment.