Skip to content

Instantly share code, notes, and snippets.

@BRMatt
Last active August 6, 2018 11:28
Show Gist options
  • Save BRMatt/9b05d38d6c9e293674f0790712cb3d4a to your computer and use it in GitHub Desktop.
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`
#!/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