Class: Util

Inherits:
Object
  • Object
show all
Defined in:
lib/terraorg/model/util.rb

Class Method Summary collapse

Class Method Details

.gsuite_group_tf(name, domain, persons, description) ⇒ Object

Take a list of Persons and generate a gsuite_group containing all of those members with expected organizational settings.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/terraorg/model/util.rb', line 11

def self.gsuite_group_tf(name, domain, persons, description)
  email = "#{name}@#{domain}"
  tf = <<-TERRAFORM
# G Suite group for #{email}
resource "gsuite_group" "#{name}" {
email = "#{email}"
name  = "#{name}"
description = "#{description}"
}

resource "gsuite_group_settings" "#{name}" {
email = gsuite_group.#{name}.email
who_can_discover_group = "ALL_IN_DOMAIN_CAN_DISCOVER"
who_can_view_membership = "ALL_IN_DOMAIN_CAN_VIEW"
who_can_leave_group = "NONE_CAN_LEAVE"
who_can_join = "INVITED_CAN_JOIN"
who_can_post_message = "ALL_IN_DOMAIN_CAN_POST"
}

resource "gsuite_group_members" "#{name}" {
group_email = gsuite_group.#{name}.email
TERRAFORM

  # Add a member block for everyone
  # downcase is used as internal G Suite representation is always lowercase
  # this avoids unnecessary state churn
  persons.each do |p|
    tf += <<-TERRAFORM
member {
  email = "#{p.email.downcase}"
  role = "MEMBER"
}
TERRAFORM
  end

  tf += "\n}"
  tf
end

.persons_tf(persons) ⇒ Object

Take a list of Persons and turn it into a newline delimited, comma separated array definition suitable for inclusion in terraform. Each line contains an okta id and a comment indicating the person’s name.



5
6
7
# File 'lib/terraorg/model/util.rb', line 5

def self.persons_tf(persons)
  "[\n" + persons.map { |p| "    \"#{p.okta_id}\", # #{p.name}" }.join("\n") + "\n]\n"
end