Skip to content

Commit

Permalink
Fix bug: Invoke-PasmCleanUp
Browse files Browse the repository at this point in the history
  • Loading branch information
nekrassov01 committed Nov 7, 2021
1 parent 16118ba commit 557ad83
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ ResourceType : NetworkAcl
ResourceName : test-acl-01
ResourceId : acl-e1t2d3g4c5bryfhvn
Detached : {subnet-q1z2x3w4e5cvrtbny, subnet-w1x2c3e4r5vbtynmu}
Skipped :
Skipped :
Action : CleanUp
ResourceType : PrefixList
ResourceName : test-pl-01
ResourceId : pl-a1d2s3f4d5gfhgjhk
Detached : {rtb-a1b2c3d4e5fghijkl, rtb-x1y2z3x4y5zxyzxyz, sg-1a2s3d4f5g6h7j890}
Skipped :
Skipped :
Action : CleanUp
```

Expand Down
22 changes: 11 additions & 11 deletions src/Functions/Invoke-PasmCleanUp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ function Invoke-PasmCleanUp {
ResourceType = [Pasm.Parameter.Resource]::SecurityGroup
ResourceName = $target.GroupName
ResourceId = $target.GroupId
Detached = if ($detachedList) { @($detachedList) } else { @{} }
Skipped = if ($remainingList) { @($remainingList) } else { @{} }
Detached = if ($detachedList) { $detachedList } else { $null }
Skipped = if ($remainingList) { $remainingList } else { $null }
Action = $action
}
)
Expand Down Expand Up @@ -124,8 +124,8 @@ function Invoke-PasmCleanUp {
ResourceType = [Pasm.Parameter.Resource]::NetworkAcl
ResourceName = $target.Tags.Value
ResourceId = $target.NetworkAclId
Detached = if ($subnetList) { @($subnetList) } else { @{} }
Skipped = @{}
Detached = if ($subnetList) { $subnetList } else { $null }
Skipped = $null
Action = 'CleanUp'
}
)
Expand All @@ -141,7 +141,7 @@ function Invoke-PasmCleanUp {
if ($null -ne $target) {
$resourceList = [list[string]]::new()
$plAssocs = Get-EC2ManagedPrefixListAssociation -PrefixListId $target.PrefixListId
if ($plAssocs) {
if ($plAssocs) {
foreach ($plAssoc in $plAssocs) {
if ($plAssoc.ResourceId -match '^sg-[0-9a-z]{17}$') {
$targetSg = Get-EC2SecurityGroup -Filter @{ Name = 'group-id'; Values = $plAssoc.ResourceId }
Expand All @@ -158,10 +158,10 @@ function Invoke-PasmCleanUp {
}
}
if ($plAssoc.ResourceId -match '^rtb-[0-9a-z]{17}$') {
$targetRoute = Get-EC2RouteTable -Filter @{ Name = 'route.destination-prefix-list-id'; Values = $plAssoc.ResourceId }
if ($targetRoute) {
foreach ($route in $targetRoute) {
Remove-EC2Route -RouteTableId $route.RouteTableId -DestinationPrefixListId $plAssoc.ResourceId -Confirm:$false | Out-Null
$targetRtb = Get-EC2RouteTable -Filter @{ Name = 'route.destination-prefix-list-id'; Values = $target.PrefixListId }
if ($targetRtb) {
foreach ($rtb in $targetRtb) {
Remove-EC2Route -RouteTableId $rtb.RouteTableId -DestinationPrefixListId $target.PrefixListId -Confirm:$false | Out-Null
$resourceList.Add($plAssoc.ResourceId)
}
}
Expand All @@ -175,8 +175,8 @@ function Invoke-PasmCleanUp {
ResourceType = [Pasm.Parameter.Resource]::PrefixList
ResourceName = $target.PrefixListName
ResourceId = $target.PrefixListId
Detached = if ($resourceList) { @($resourceList) } else { @{} }
Skipped = @{}
Detached = if ($resourceList) { $resourceList } else { $null }
Skipped = $null
Action = 'CleanUp'
}
)
Expand Down

0 comments on commit 557ad83

Please sign in to comment.