aboutsummaryrefslogtreecommitdiff
path: root/manifests/init.pp
blob: 368b5589749127f9e7b33b3a7fe89fe1f19051d6 (plain)
1
2
3
4
5
6
7
8
9
10
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
49
50
51
52
53
54
55
# @summary Global defaults for defined resource types.
#
# @param worker_work_dir
#   Default work dir for each worker
# @param default_cluster
#   Cluster used by all resources if no specific cluster is specified.
# @param worker_service
#   Name of the the system service for workers.
# @param clusters
#   Hash from cluster name to default values for each cluster.
#   Each key should be the name of a cluster, and the options are as follows:
# @option clusters :external_domain
# @option clusters :postgres_user
# @option clusters :postgres_password
# @option clusters :session_signing_key
# @option clusters :tsa_private_key
# @option clusters :tsa_public_key
# @option clusters :db_name
class concourse (
  String $default_cluster,
  String $worker_work_dir = '/opt/concourse/worker',
  String $worker_service = 'concourse-worker',
  Hash[String, Hash[String, Any]] $clusters = {},
) {
  # Merge all configured clusters we find in hiera, and append those
  # explicitly added to the class.
  $configured_clusters_ = lookup('concourse::clusters', {
      merge         => 'hash',
      default_value => {},
  }) + $clusters

  # Populate each configured cluster with some default values.
  $populated_clusters_ = $configured_clusters_.map |$cluster_name, $opts| {
    # Defaults need to be declared *inside* the loop, since they may
    # depend on other values in the configuration.
    $cluster_defaults = {
      'db_name'       => "atc-${cluster_name}",
      'postgres_user' => 'concourse',
    }

    $finalized_opts = $cluster_defaults.keys().reduce($opts) |$opts, $key| {
      if $key in $opts {
        $opts
      } else {
        $opts + { $key => $cluster_defaults[$key] }
      }
    }

    [$cluster_name, $finalized_opts]
  }

  # This variable is the "exported" item other resources should look at to get
  # cluster default configuration.
  $configured_clusters = Hash($populated_clusters_)
}