Last active
August 6, 2018 11:28
-
-
Save BRMatt/9b05d38d6c9e293674f0790712cb3d4a to your computer and use it in GitHub Desktop.
A small utility for tainting a bunch of terraform resources in one go `terraform state list | grep launch_configuration | tf-multitaint`
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
#!/usr/bin/env ruby | |
resources = $stdin.readlines.map(&:split).flatten.map do |resource| | |
{ | |
module: resource.scan(%r{module\.([a-z0-9\-_]+)}).to_a.join("."), | |
identifier: resource.match(%r{(?:module\.[a-z0-9\-_]+\.)*(.*)$}).captures.first, | |
} | |
end | |
resources.each do |resource| | |
puts resource | |
args = [ | |
'taint', | |
] | |
unless resource[:module].empty? | |
args << "-module=#{resource[:module]}" | |
end | |
args << resource[:identifier].to_s | |
unless Kernel.system("terraform", *args) | |
$stderr.puts("terraform failed, exiting") | |
exit 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment