LoginSignup
0
0

More than 1 year has passed since last update.

特定のタグが無いAWSリソースを探したい

Posted at
$targetResource = @('ec2','rds')
$results = New-Object System.Collections.ArrayList

$targetResource | ForEach-Object {
    $resouces = aws resourcegroupstaggingapi get-resources --resource-type-filter $_
    $resouces = $resouces | ConvertFrom-Json
    $resouces.ResourceTagMappingList | ForEach-Object {
        $tagCheck = $false
        $_.Tags | ForEach-Object {
            if($_.Key -eq "CostDivision") {
                $tagCheck = $true
            }
        }
        if($tagCheck -eq $false) {
            $result = New-Object psobject | Select-Object ResourceARN , Tags
            $result.ResourceARN = $_.ResourceARN
            $result.Tags = $_.Tags
            [void]$results.Add($result)
        }
    }
}
$results
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0