terraform 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,26 +1,123 @@
1
- Terraform is a small goal-oriented DSL for setting up a machine, similar in purpose to Chef and Puppet. Its
2
- design is inspired by Babushka, but it's simpler and tailored specifically for provisioning a machine for a
3
- webapp.
1
+ Terraform
2
+ ---------
3
+
4
+ Terraform is a small goal-oriented Ruby DSL for setting up a machine, similar in purpose to Chef and Puppet,
5
+ but without the complexity. It's tailored for the kinds of tasks needed for deploying web apps and is designed
6
+ to be refreshingly easy to understand and debug. You can read through the entire Terraform library in two
7
+ minutes and know precisely what it will and won't do for you. Its design is inspired by Babushka.
4
8
 
5
9
  Usage
6
10
  -----
11
+ This is the basic structure of a system provisioning script written using Terraform:
7
12
 
8
13
  require "terraform_dsl"
9
- include Terraform::Dsl
10
- dep "my library" do
11
- met? { (check if your dependency is met) }
12
- meet { (install your dependency) }
14
+ include Terraform::DSL
15
+
16
+ dep "pygments" do
17
+ met? { in_path? "pygmentize" } # Check if your dependency is met.
18
+ meet { shell "pip install pygments" } # Install your dependency.
13
19
  end
14
20
 
15
- A more detailed README is coming shortly.
21
+ ...
22
+
23
+ satisfy_dependencies()
24
+
25
+ The Terraform DSL provides these functions which are commonly used when provisioning systems to run web services:
26
+
27
+ <table>
28
+ <tr>
29
+ <td>shell(command)</td>
30
+ <td>Executes a shell command. Use this generally instead of backticks. It raises an exception if the exit
31
+ status of the command was nonzero, and prints the command string as well as the output.</td>
32
+ </tr>
33
+ <tr>
34
+ <td>in_path?(command)</td>
35
+ <td>True if the command is in the current path.</td>
36
+ </tr>
37
+ <tr>
38
+ <td>package_installed?(package_name)</td>
39
+ <td>True if a package is installed. Currently only apt-get is supported.</td>
40
+ </tr>
41
+ <tr>
42
+ <td>ensure_packages(*package_names)</td>
43
+ <td>Ensures the given packages are installed via apt-get.</td>
44
+ </tr>
45
+ <tr>
46
+ <td>ensure_ppa(ppa_url)</td>
47
+ <td>Ensures the given PPA (used on Ubuntu) is installed. "ppa_url" is of the form "ppa:user/name".</td>
48
+ </tr>
49
+ <tr>
50
+ <td>gem_installed?(name)</td>
51
+ <td>True if the given Ruby gem is installed.</td>
52
+ </tr>
53
+ <tr>
54
+ <td>ensure_gem(name)</td>
55
+ <td>Ensures the given Ruby gem is installed.</td>
56
+ </tr>
57
+ <tr>
58
+ <td>ensure_rbenv()</td>
59
+ <td>Ensures rbenv is installed.</td>
60
+ </tr>
61
+ <tr>
62
+ <td>ensure_rbenv_ruby(ruby_version)</td>
63
+ <td>Ensures the given version of Ruby is installed. `ruby_version` is an rbenv Ruby version string like
64
+ "1.9.2.-p290".</td>
65
+ </tr>
66
+ <tr>
67
+ <td>ensure_run_once(dependency_name, block)</td>
68
+ <td>Runs the given block once. Use for tasks that you're too lazy to write a proper `met?` block for, like running database migrations.</td>
69
+ </tr>
70
+ <tr>
71
+ <td>ensure_file(source_path, dest_path, on_change)</td>
72
+ <td>Ensures the file at dest_path is the exact same as the file at source_path. Use this for copying
73
+ configuration files (e.g. nginx.conf) to their proper locations.</td>
74
+ </tr>
75
+ <tr>
76
+ <td>fail_and_exit(message)</td>
77
+ <td>Use when your meet() block encounters an error and cannot satisfy a dependency.</td>
78
+ </tr>
79
+ </table>
80
+
81
+ For further details, see [the source](https://github.com/philc/terraform/blob/master/lib/terraform/dsl.rb).
82
+ It's a short, well-documented file and there's no magic.
83
+
84
+ Installation
85
+ ------------
86
+ 1. Install the Terraform gem on your local machine (the machine you're deploying from): `gem install
87
+ terraform`
88
+
89
+ 2. Write your system provisioning script using the Terraform DSL.
90
+
91
+ 3. Copy your system provisioning script and the Terraform library (which is a single file) to your remote
92
+ machine and run it. Do this as part of your deploy script.
93
+
94
+ You can use the Terraform gem to write the Terraform library out to a single file as part of your deploy
95
+ script, prior to copying it over to your remote machine:
96
+
97
+ require "terraform"
98
+ Terraform.write_dsl_file("/tmp/staging/my_app/terraform_dsl.rb")
99
+
100
+ Terraform is designed to be run on a barebones machine with little preinstalled software. The only requirement
101
+ is that some version (any version) of Ruby is installed on the machine you're provisioning.
102
+
103
+ Examples
104
+ --------
105
+ See the [Terraform library itself](https://github.com/philc/terraform/blob/master/lib/terraform/dsl.rb), which
106
+ makes use of the DSL quite a bit.
107
+
108
+ [Barkeep](https://github.com/ooyala/barkeep) is a code review system which uses Terraform for provisioning the
109
+ machines it gets deployed to. You can see its system provisioning script written using Terraform
110
+ [here](https://github.com/ooyala/barkeep/blob/master/script/system_setup.rb), and its Fezzik deploy script
111
+ [here](https://github.com/ooyala/barkeep/blob/master/config/tasks/deploy.rake).
16
112
 
17
113
  Contribute
18
114
  ----------
19
- When editing this gem, to test your changes, you can load your local copy of the gem in your project by using
20
- this in your Gemfile:
115
+ When developing this gem you can quickly preview and test your changes by loading your local copy of the gem
116
+ in your project's Gemfile:
21
117
 
22
- gem "terraform", :path => "~/p/terraform"
118
+ gem "terraform", :path => "~/path/to/terraform_checkout"
23
119
 
24
120
  Credits
25
121
  -------
26
- Dmac -- thanks for the name!
122
+ * Daniel MacDougall ([dmacdougall](https://github.com/dmacdougall)) -- thanks for the name.
123
+ * Caleb Spare ([cespare](https://github.com/cespare))
data/lib/terraform/dsl.rb CHANGED
@@ -2,7 +2,7 @@ require "fileutils"
2
2
  require "digest/md5"
3
3
 
4
4
  module Terraform
5
- module Dsl
5
+ module DSL
6
6
  def dep(name)
7
7
  @dependencies ||= []
8
8
  # If a dep gets required or defined twice, only run it once.
@@ -18,8 +18,8 @@ module Terraform
18
18
  def fail_and_exit(message) puts message; exit 1 end
19
19
 
20
20
  # Runs a command and raises an exception if its exit status was nonzero.
21
+ # Options:
21
22
  # - silent: if false, log the command being run and its stdout. False by default.
22
- # - check_exit_code: raises an error if the command had a non-zero exit code. True by default.
23
23
  def shell(command, options = {})
24
24
  silent = (options[:silent] != false)
25
25
  puts command unless silent
@@ -1,3 +1,3 @@
1
1
  module Terraform
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraform
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Phil Crosby
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-27 00:00:00 -07:00
18
+ date: 2012-04-17 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency