Permalink
Browse files

Merge pull request #6 from dmacdougall/ensure_user

Add ensure_user helper
  • Loading branch information...
2 parents ce1118f + df4f71f commit c2ea2b8492a061dd8f4404f6dff76aa771042e7e @cespare cespare committed Oct 11, 2012
Showing with 17 additions and 0 deletions.
  1. +10 −0 lib/terraform/dsl.rb
  2. +7 −0 test/unit/terraform/dsl_test.rb
View
@@ -141,5 +141,15 @@ def ensure_rbenv_ruby(ruby_version)
end
end
end
+
+ def user_exists?(username) !!`id #{username} 2> /dev/null`.match(/^uid=\d+/) end
+ def create_user(username) shell "useradd -m #{username}" end
+
+ def ensure_user(username)
+ dep "user: #{username}" do
+ met? { user_exists?(username) }
+ meet { create_user(username) }
+ end
+ end
end
end
@@ -115,4 +115,11 @@ def do_meet() end
assert meet_run
end
end
+
+ context "ensure_user" do
+ should "determine if a user exists" do
+ assert user_exists?("root")
+ refute user_exists?("fake_username")
+ end
+ end
end

0 comments on commit c2ea2b8

Please sign in to comment.