terraform 0.0.6 → 0.0.7.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -42,6 +42,11 @@ The Terraform DSL provides these functions which are commonly used when provisio
42
42
  <td>ensure_packages(*package_names)</td>
43
43
  <td>Ensures the given packages are installed via apt-get.</td>
44
44
  </tr>
45
+ <tr>
46
+ <td>ensure_apt_get_update(oldest_acceptable_time)</td>
47
+ <td>Runs apt-get update if it hasn't been run since the oldest_acceptable_time (a Time object).
48
+ Defaults to 30 days ago.</td>
49
+ </tr>
45
50
  <tr>
46
51
  <td>ensure_ppa(ppa_url)</td>
47
52
  <td>Ensures the given PPA (used on Ubuntu) is installed. "ppa_url" is of the form "ppa:user/name".</td>
@@ -110,6 +115,46 @@ machines it gets deployed to. You can see its system provisioning script written
110
115
  [here](https://github.com/ooyala/barkeep/blob/master/script/system_setup.rb), and its Fezzik deploy script
111
116
  [here](https://github.com/ooyala/barkeep/blob/master/config/tasks/deploy.rake).
112
117
 
118
+ Plugins
119
+ ----------
120
+ Terraform can be easily extended with custom deps distributed as gems or scripts. A library that defines new
121
+ Terraform deps should call `Terraform.add_plugin(__FILE__)` in any file that adds to the Terraform DSL. For
122
+ example, if you wanted to package a dep as a gem, the contents of your project might look like this:
123
+
124
+ ```
125
+ terraform-yourgem/
126
+ `-lib/
127
+ `-terraform/
128
+ `-yourgem.rb
129
+
130
+ yourgem.rb
131
+ ----------
132
+ require "terraform"
133
+
134
+ module Terraform
135
+ module DSL
136
+ # Define your deps
137
+ end
138
+ end
139
+
140
+ Terraform.add_plugin(__FILE__)
141
+ ```
142
+
143
+ Then in your application setup script you would write:
144
+
145
+ ```ruby
146
+ require "terraform"
147
+ require "terraform/yourgem"
148
+
149
+ Terraform.write_terraform_files("./terraform")
150
+ ```
151
+
152
+ This will write out the core Terraform DSL plus all required plugins, ready to be required by your bootstrap
153
+ code on the server.
154
+
155
+ For more complete example see [terraform-rbenv](https://github.com/dmacdougall/terraform-rbenv), which
156
+ reimplements Terraform's existing rbenv deps as a plugin.
157
+
113
158
  Contribute
114
159
  ----------
115
160
  When developing this gem you can quickly preview and test your changes by loading your local copy of the gem
@@ -2,9 +2,22 @@ require "terraform/version"
2
2
  require "fileutils"
3
3
 
4
4
  module Terraform
5
+ # DEPRECATED
6
+ # Replaced by `write_terraform_files`. Remove in next major version release.
5
7
  # Writes the terraform_dsl.rb to the given file or directory.
6
8
  def self.write_dsl_file(path)
9
+ puts "WARNING: `Terraform.write_dsl_file` is deprecated. Instead use `Terraform.write_terraform_files`."
7
10
  path = File.join(path, "terraform_dsl.rb") if File.directory?(path)
8
11
  FileUtils.cp(File.expand_path(File.join(File.dirname(__FILE__), "terraform/dsl.rb")), path)
9
12
  end
13
+
14
+ @@plugin_files = Set.new [File.expand_path(File.join(File.dirname(__FILE__), "terraform/dsl.rb"))]
15
+ def self.register_plugin(path) @@plugin_files.add(path) end
16
+
17
+ def self.write_terraform_files(path)
18
+ FileUtils.mkdir_p(path)
19
+ @@plugin_files.each do |plugin|
20
+ FileUtils.cp(File.expand_path(plugin), File.join(path, File.basename(plugin)))
21
+ end
22
+ end
10
23
  end
@@ -31,6 +31,7 @@ module Terraform
31
31
 
32
32
  def satisfy_dependencies
33
33
  STDOUT.sync = true # Ensure that we flush logging output as we go along.
34
+ @dependencies ||= []
34
35
  @dependencies.each do |dep|
35
36
  unless dep[:met?].call
36
37
  puts "* Dependency #{dep[:name]} is not met. Meeting it."
@@ -59,6 +60,16 @@ module Terraform
59
60
  end
60
61
  end
61
62
 
63
+ def ensure_apt_get_update(oldest_acceptable_time = Time.now - 30*24*60*60)
64
+ dep "apt-get update" do
65
+ met? do
66
+ File.exists?("#{ENV['HOME']}/.apt_get_updated") &&
67
+ File.mtime("#{ENV['HOME']}/.apt_get_updated") >= oldest_acceptable_time
68
+ end
69
+ meet { `sudo apt-get update && touch $HOME/.apt_get_updated` }
70
+ end
71
+ end
72
+
62
73
  # Ensure an Ubuntu PPA is installed. The argument is the ppa location, in the form ppa:[USER]/[NAME]
63
74
  def ensure_ppa(ppa)
64
75
  ppa_part, location = ppa.split(":", 2)
@@ -112,12 +123,14 @@ module Terraform
112
123
  end
113
124
 
114
125
  def ensure_rbenv
115
- ensure_package "git-core"
126
+ # TODO(caleb): The package is 'git-core' in older Ubuntu releases. We should have a mechanism for
127
+ # handling different releases; see https://github.com/philc/terraform/issues/15.
128
+ ensure_package "git"
116
129
  dep "rbenv" do
117
130
  met? { in_path?("rbenv") }
118
131
  meet do
119
- # These instructions are from https://github.com/sstephenson/rbenv/wiki/Using-rbenv-in-Production
120
- shell "wget -q -O - https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash"
132
+ # These instructions are from https://github.com/fesplugas/rbenv-installer
133
+ shell "curl https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash"
121
134
  # We need to run rbenv init after install, which adjusts the path. If exec is causing us problems
122
135
  # down the road, we can perhaps simulate running rbenv init without execing.
123
136
  unless ARGV.include?("--forked-after-rbenv") # To guard against an infinite forking loop.
@@ -1,3 +1,3 @@
1
1
  module Terraform
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7.rc1"
3
3
  end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terraform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
5
- prerelease:
4
+ version: 0.0.7.rc1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Phil Crosby
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-11 00:00:00.000000000Z
12
+ date: 2013-03-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: scope
16
- requirement: &28526960 !ruby/object:Gem::Requirement
16
+ requirement: &70308188001180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.2.3
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *28526960
24
+ version_requirements: *70308188001180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rr
27
- requirement: &28526300 !ruby/object:Gem::Requirement
27
+ requirement: &70308188000560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 1.0.4
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *28526300
35
+ version_requirements: *70308188000560
36
36
  description:
37
37
  email:
38
38
  - phil.crosby@gmail.com
@@ -65,14 +65,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  none: false
67
67
  requirements:
68
- - - ! '>='
68
+ - - ! '>'
69
69
  - !ruby/object:Gem::Version
70
- version: '0'
70
+ version: 1.3.1
71
71
  requirements: []
72
72
  rubyforge_project: terraform
73
73
  rubygems_version: 1.8.10
74
74
  signing_key:
75
75
  specification_version: 3
76
76
  summary: Set up a cold, inhospitable system using Terraform.
77
- test_files: []
77
+ test_files:
78
+ - test/test_helper.rb
79
+ - test/unit/terraform/dsl_test.rb
78
80
  has_rdoc: