Migration/AWS/AWSUtil.psm1
Import-Module -Name @(Join-Path $PSScriptRoot .. | Join-Path -ChildPath .. | Join-Path -ChildPath Common | Join-Path -ChildPath Wrappers | Join-Path -ChildPath Wrappers) function Get-RMVPCByCloudAttributes { param( [System.Object] $CloudAttributes ) $VPCs = @{} foreach($VPC in $CloudAttributes.properties.regions[0].vpcs) { $VPCs[$VPC.id] = $VPC.subnets } return $VPCs } function Get-RMSubnetIDBySubnet { param( [System.Object[]] $Subnet ) $SubnetIDs = @() foreach ($Item in $Subnet) { $SubnetIDs += $Item.id } return $SubnetIDs } function Get-RMSubnetByVPCIDAndSubnetID { param ( [string] $VPCID, [string] $SubnetID, [hashtable] $VPC ) $Subnets = $VPC[$VPCID] foreach ($Subnet in $Subnets) { if ($Subnet.id -eq $SubnetID) { return $Subnet } } return $null } function Get-RMVPCAndSecurityGroupMapping { param ( [System.Object] $CloudAttributes ) $VPCs = @{} foreach ($VPC in $CloudAttributes.properties.regions[0].vpcs) { $VPCs.Add($VPC.id, $VPC.security_groups) } return $VPCs } function Get-RMSecurityGroupIDToNameMapping { param( [string[]] $SelectedSecurityGroupName, [System.Object[]] $SecurityGroup ) $SecurityGroupMapping = @{} foreach ($SelectedSGName in $SelectedSecurityGroupName) { $FoundSG = $SecurityGroup | Where-Object {$_.name -ieq $SelectedSGName} if ($null -eq $FoundSG) { continue } $SecurityGroupMapping.Add($FoundSG.id, $FoundSG.name) } return $SecurityGroupMapping } function Read-RMInstanceType { param ( [System.Object] $CloudAttributes ) while ($true) { $ReadValue = Read-RMString -UserMessage "Enter instance type" ` -ParameterName "Instance type" -IsRequired $true if ($CloudAttributes.properties.regions[0].instance_types -notcontains $ReadValue) { Write-RMError -Message "Instance type '$ReadValue' does not exist." continue } return $ReadValue } } function Get-RMVolumeTypeByUserInput { param( [string] $UserInputVolumeType ) switch ($UserInputVolumeType) { "gp2" { return "ssd2" } "gp3" { return "ssd3" } "io1" { return "iops_ssd" } "io2" { return "iops2_ssd" } default { Throw "Volme type " + $UserInputVolumeType + "not supported" } } } |