Debian Codegraph @

case_studies/micromanage/tests/amazon/test_single_instance.jsonnet

raw
1 local cmd = import "mmlib/v0.1.2/cmd/cmd.libsonnet";
2 local amis_ubuntu = import "mmlib/v0.1.2/amis/ubuntu.libsonnet";
3 local amis_debian = import "mmlib/v0.1.2/amis/debian.libsonnet";
4
5 {
6 environments: import "../testenv.libsonnet",
7
8 local SingleAmazonInstance(name) = {
9 local service = self,
10
11 // Cut off the last letter
12 local region_from_zone(z) = std.substr(z, 0, std.length(z) - 1),
13
14 environment: "amazon",
15
16 zone:: error "Must override zone.",
17 amiMap:: error "Must override amiMap or ami.",
18 ami:: null,
19 machineType:: "t2.small",
20 keyName:: null,
21 cmds:: [],
22
23 externalIp:: false,
24 infrastructure: {
25 aws_instance: {
26 name: {
27 [if service.keyName != null then "key_name"]: service.keyName,
28 instance_type: service.machineType,
29 availability_zone: service.zone,
30 ami: if service.ami != null then service.ami else service.amiMap[region_from_zone(service.zone)],
31 associate_public_ip_address: service.externalIp,
32 cmds: service.cmds,
33 },
34 },
35 },
36 outputs: {
37 name + "-address": "${aws_instance.%s.public_ip}" % name,
38 name + "-id": "${aws_instance.%s.id}" % name,
39 },
40 },
41
42 ubuntu_aws: SingleAmazonInstance('ubuntu_aws') {
43 externalIp: true,
44 keyName: "kp",
45 amiMap: amis_ubuntu.trusty.amd64["20151117"],
46 zone: "us-west-1b",
47 cmds: [
48 "echo hi > /hi.txt",
49 cmd.LiteralFile {
50 to: "/var/log/bye.txt",
51 content: |||
52 bye
53 |||,
54 filePermissions: "700",
55 },
56 ],
57 },
58
59
60 ubuntu_aws_ami: SingleAmazonInstance('ubuntu_aws_ami') {
61 externalIp: true,
62 keyName: "kp",
63 ami: {
64 sourceAmi: amis_ubuntu.trusty.amd64["20151117"]["us-west-1"],
65 instanceType: "t2.small",
66 sshUser: "ubuntu",
67 cmds: [
68 "echo hi > /hi.txt",
69 cmd.LiteralFile {
70 to: "/var/log/bye.txt",
71 content: |||
72 bye
73 |||,
74 filePermissions: "700",
75 },
76 ],
77 },
78 zone: "us-west-1b",
79 },
80
81
82 debian_aws: SingleAmazonInstance('debian_aws') {
83 externalIp: true,
84 keyName: "kp",
85 amiMap: amis_debian.wheezy.amd64["20150128"],
86 zone: "us-west-1c",
87 cmds: [
88 "echo hi > /hi.txt",
89 cmd.LiteralFile {
90 to: "/var/log/bye.txt",
91 content: |||
92 bye
93 |||,
94 filePermissions: "700",
95 },
96 ],
97 },
98
99
100 debian_aws_ami: SingleAmazonInstance('debian_aws_ami') {
101 externalIp: true,
102 keyName: "kp",
103 ami: {
104 sourceAmi: amis_debian.wheezy.amd64["20150128"]["us-west-1"],
105 instanceType: "t2.small",
106 sshUser: "admin",
107 cmds: [
108 "echo hi > /hi.txt",
109 cmd.LiteralFile {
110 to: "/var/log/bye.txt",
111 content: |||
112 bye
113 |||,
114 filePermissions: "700",
115 },
116 ],
117 },
118 zone: "us-west-1b",
119 },
120 }