Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add ensure_user helper

Fixes #5
  • Loading branch information...
commit ea6485eb9540cb221d69beb9ca8d39a2fa2de139 1 parent ce1118f
@dmac dmac authored
Showing with 17 additions and 0 deletions.
  1. +10 −0 lib/terraform/dsl.rb
  2. +7 −0 test/unit/terraform/dsl_test.rb
View
10 lib/terraform/dsl.rb
@@ -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
View
7 test/unit/terraform/dsl_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.