-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57d576e
commit cbad5c8
Showing
5 changed files
with
135 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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 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,52 @@ | ||
function Get-SecurityGroupWithStack | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Return security group ID with the name of the stack that created the group | ||
Helps us to spot default SGs created by EB | ||
#> | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[string[]]$GroupId | ||
) | ||
|
||
begin | ||
{} | ||
|
||
process | ||
{ | ||
$GroupId | | ||
ForEach-Object { | ||
$sg = Get-EC2SecurityGroup -GroupId $_ | ||
|
||
if ($null -ne $sg) | ||
{ | ||
# Determine how it was created from tags | ||
$stackName = $sg.Tags | | ||
Where-Object { | ||
$_.Key -ieq 'aws:cloudformation:stack-name' | ||
} | | ||
Select-Object -ExpandProperty Value | ||
|
||
if (-not $stackName) | ||
{ | ||
$stackName = '*NONE*' | ||
} | ||
|
||
New-Object PSObject -Property @{ | ||
SecurityGroupId = $_ | ||
OwningStack = $stackName | ||
} | | ||
Add-Member -PassThru -MemberType ScriptMethod -Name ToString -Force -Value { | ||
"$($this.SecurityGroupId) ($($this.OwningStack))" | ||
} | ||
} | ||
} | ||
} | ||
|
||
end | ||
{} | ||
} | ||
|
This file contains 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
76 changes: 76 additions & 0 deletions
76
aws-toolbox/Public/EC2/Get-ATEC2SecurityGroupDependencies.ps1
This file contains 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,76 @@ | ||
function Get-ATEC2SecurityGroupDependencies | ||
{ | ||
param | ||
( | ||
[Parameter(ValueFromPipeline)] | ||
[string[]]$GroupId, | ||
|
||
[switch]$AsText | ||
) | ||
|
||
begin | ||
{ | ||
function Get-ENIDetails | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(ValueFromPipelineByPropertyName)] | ||
[string[]]$NetworkInterfaceId | ||
) | ||
|
||
begin | ||
{ } | ||
|
||
process | ||
{ | ||
$NetworkInterfaceId | | ||
Foreach-Object { | ||
New-Object PSObject -Property @{ | ||
NetworkInterface = $_ | ||
Instance = Get-EC2Instance -Filter @{ Name = 'network-interface.network-interface-id'; Values = $_ } | | ||
Select-Object -ExpandProperty Instances | | ||
Select-Object -ExpandProperty InstanceId | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
process | ||
{ | ||
$GroupId | | ||
Foreach-Object { | ||
|
||
$sgs = Get-SecurityGroupWithStack -GroupId $_ | ||
|
||
if ($null -ne $sgs) | ||
{ | ||
$sg = $sgs.SecurityGroupId | ||
|
||
New-Object PSObject -Property @{ | ||
SecurityGroup = $sgs | ||
NetworkInterfaces = Get-EC2NetworkInterface -Filter @{ Name = 'group-id'; Values = $sg } | | ||
Get-ENIDetails | ||
|
||
IngressReferences = Get-EC2SecurityGroup -Filter @{ Name = 'ip-permission.group-id'; Values = $sg } | | ||
Get-SecurityGroupWithStack | | ||
Where-Object { | ||
$_.SecurityGroupId -ne $sgs.SecurityGroupId | ||
} | ||
|
||
EgressReferences = Get-EC2SecurityGroup -Filter @{ Name = 'egress.ip-permission.group-id'; Values = $sg } | | ||
Get-SecurityGroupWithStack | | ||
Where-Object { | ||
$_.SecurityGroupId -ne $sgs.SecurityGroupId | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
end | ||
{ | ||
|
||
} | ||
} |
This file contains 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