Created
May 23, 2022 20:15
-
-
Save onyxhat/fb705c4a07750d1a55d0cba2ff1bf3e9 to your computer and use it in GitHub Desktop.
Terraformer Export Helper
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
[CmdletBinding()] | |
param ( | |
[Parameter()] | |
[string] | |
$aws_profile = "VirtixProd", | |
[Parameter()] | |
[string[]] | |
$aws_region = @("us-east-2"), | |
[Parameter()] | |
[string[]] | |
$aws_resources = @("*") | |
) | |
Begin { | |
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path | |
[string]$regions = $aws_region -join ',' | |
[string]$resources = $aws_resources -join ',' | |
[string]$path_pattern = "{output}/{service}/" | |
} | |
Process { | |
foreach ($r in $aws_region) { | |
terraformer import aws --regions=$regions ` | |
--profile=$aws_profile ` | |
--path-output="${aws_profile}/${r}" ` | |
--path-pattern=$path_pattern ` | |
--resources=$resources | |
} | |
terraformer import aws --profile=$aws_profile ` | |
--path-output="${aws_profile}/no_region" ` | |
--path-pattern=$path_pattern ` | |
--resources=$resources | |
} | |
End { | |
$junk_files = Get-ChildItem -Recurse -Path "${ScriptDir}" | ? { $_.Name -in @("outputs.tf", "provider.tf", "terraform.tfstate", "variables.tf") } | Select-Object -ExpandProperty FullName | |
$junk_files | Remove-Item -Force | |
$empty_dirs = Get-ChildItem -Path $ScriptDir -Directory -Recurse | ? { (Get-ChildItem $_.FullName).Count -eq 0 } | Select-Object -ExpandProperty FullName | |
$empty_dirs | Remove-Item -Force | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment