Skip to content

Instantly share code, notes, and snippets.

@developerinlondon
Forked from a2ikm/Rakefile
Created May 27, 2016 21:27
Show Gist options
  • Save developerinlondon/e0ccf5409371820a2cc14c99812e7667 to your computer and use it in GitHub Desktop.
Save developerinlondon/e0ccf5409371820a2cc14c99812e7667 to your computer and use it in GitHub Desktop.
Rake tasks for Terraform
task :environment do
errors = []
%w(
TF_VAR_dnsimple_email
TF_VAR_dnsimple_token
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION
).each do |name|
errors << name if ENV[name].nil?
end
if errors.any?
abort "One or more environment variables are empty: #{errors.join(", ")}"
end
end
task :configure => :environment do
bucket = "example-terraform-state"
key = "terraform.tfstate"
sh %Q!terraform remote config -backend=S3 -backend-config="bucket=#{bucket}" -backend-config="key=#{key}"!
end
task :pull => :configure do
sh "terraform remote pull"
end
task :push => :configure do
sh "terraform remote push"
end
task :plan do
sh "terraform plan"
end
task :apply do
sh "terraform apply"
end
Rake::Task[:plan].enhance([:pull])
Rake::Task[:apply].enhance([:pull]) do
Rake::Task[:push].invoke
end
task :default => :plan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment