Created
September 30, 2014 13:43
-
-
Save Phelms215/621b256058ffec297fb3 to your computer and use it in GitHub Desktop.
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
::Chef::Recipe.send(:include, Chef::Mixin::PowershellOut) | |
Output = powershell_out!(' | |
$web = New-Object Net.WebClient | |
$instanceID = $web.DownloadString("http://169.254.169.254/latest/meta-data/instance-id") | |
$web2 = New-Object Net.WebClient | |
$AvailZone = $web.DownloadString("http://169.254.169.254/latest/meta-data/placement/availability-zone") | |
$region = $AvailZone.Substring(0,$AvailZone.Length-1) | |
$pinfo = New-Object System.Diagnostics.ProcessStartInfo | |
$pinfo.FileName = "aws" | |
$pinfo.Arguments = "ec2 describe-tags --filters `"Name=resource-id,Values=$instanceID`" `"Name=tag-key,Values=ChefTags`" --region $region --query `"Tags[*].Value`"" | |
$pinfo.UseShellExecute = $false | |
$pinfo.CreateNoWindow = $true | |
$pinfo.RedirectStandardOutput = $true | |
$pinfo.RedirectStandardError = $true | |
$process = New-Object System.Diagnostics.Process | |
$process.StartInfo = $pinfo | |
$process.Start() | |
return $process.StandardOutput.ReadToEnd()') | |
TagsArray = Output.stdout.chop.split(",") | |
TagsArray.each do |key| | |
puts key | |
if not tagged?(key) | |
puts "Adding Tag "+ #{key} | |
tag(key) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment