File: consul.jsonnet

package info (click to toggle)
jsonnet 0.17.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,344 kB
  • sloc: cpp: 23,062; python: 1,705; ansic: 865; sh: 708; javascript: 576; makefile: 187; java: 140
file content (70 lines) | stat: -rw-r--r-- 1,578 bytes parent folder | download | duplicates (4)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// These can split into separate files, come from environment variables / commandline etc., as
// desired.
local aws_region = 'us-east-1';

// Ubuntu Precise 12.04 LTS (x64)
local aws_amis = {
  'eu-west-1': 'ami-b1cf19c6',
  'us-east-1': 'ami-de7ab6b6',
  'us-west-1': 'ami-3f75767a',
  'us-west-2': 'ami-21f78e11',
};

{
  provider: {
    // Setup the Consul provisioner to use the demo cluster
    consul: {
      address: 'demo.consul.io:80',
      datacenter: 'nyc1',
      scheme: 'http',
    },
    // Setup an AWS provider
    aws: {
      region: aws_region,
      access_key: 'XXX',
      secret_key: 'YYY',
    },
  },

  resource: {
    aws_instance: {

      // Object comprehension syntax (similar to Python)
      test: {
        // i is a scoped variable here
        instance_type: '${consul_keys.input.var.size}',
        ami: aws_amis[aws_region],
      },
    },

    consul_keys: {
      // Setup a key in Consul to provide inputs
      input: {
        key: {
          name: 'size',
          path: 'tf_test/size',
          default: 'm1.small',
        },
      },

      // Setup a key in Consul to store the instance id and
      // the DNS name of the instance
      test: {
        key: [
          {
            name: 'id',
            path: 'tf_test/id',
            value: '${aws_instance.test.id}',
            delete: true,
          },
          {
            name: 'address',
            path: 'tf_test/public_dns',
            value: '${aws_instance.test.public_dns}',
            delete: true,
          },
        ],
      },
    },
  },
}