|
9 | 9 | * |
10 | 10 | */ |
11 | 11 |
|
12 | | -# variables used by this snippet of init shellcode |
13 | | -variable "device_path" { |
14 | | - default = "/dev/xvdf" |
15 | | - description = "path, to the device's path in /dev/" |
16 | | - type = string |
17 | | -} |
18 | | - |
19 | | -variable "init_prefix" { |
20 | | - default = "" |
21 | | - description = "initial init (shellcode) to prefix this snippet with" |
22 | | - type = string |
23 | | -} |
24 | | - |
25 | | -variable "init_suffix" { |
26 | | - default = "" |
27 | | - description = "init (shellcode) to append to the end of this snippet" |
28 | | - type = string |
29 | | -} |
30 | | - |
31 | | -variable "log_level" { |
32 | | - default = "info" |
33 | | - description = "default log level verbosity for apps that support it" |
34 | | - type = string |
35 | | -} |
36 | | - |
37 | | -variable "log_prefix" { |
38 | | - default = "OPS: " |
39 | | - description = "string to prefix log messages with" |
40 | | - type = string |
41 | | -} |
42 | | - |
43 | | -variable "region" { |
44 | | - description = "AWS region the volume is in" |
45 | | - type = string |
46 | | -} |
47 | | - |
48 | | -variable "wait_interval" { |
49 | | - default = "5" |
50 | | - description = "time (in seconds) to wait when looping to find the device" |
51 | | - type = number |
52 | | -} |
53 | | - |
54 | | -variable "volume_id" { |
55 | | - description = "ID of the EBS volume to attach" |
56 | | - type = string |
| 12 | +locals { |
| 13 | + device_paths = var.compatible_with_single_volume ? [var.device_path] : var.device_paths |
| 14 | + volume_ids = var.compatible_with_single_volume ? [var.volume_id] : var.volume_ids |
57 | 15 | } |
58 | 16 |
|
59 | 17 | # render init script for a cluster using our generic template |
60 | 18 | data "template_file" "init_snippet" { |
| 19 | + count = length(local.volume_ids) |
| 20 | + |
61 | 21 | template = file("${path.module}/snippet.tpl") |
62 | 22 |
|
63 | 23 | vars = { |
64 | | - device_path = var.device_path |
65 | | - init_prefix = var.init_prefix |
66 | | - init_suffix = var.init_suffix |
| 24 | + device_path = local.device_paths[count.index] |
67 | 25 | log_prefix = var.log_prefix |
68 | 26 | log_level = var.log_level |
69 | 27 | region = var.region |
70 | | - volume_id = var.volume_id |
| 28 | + volume_id = local.volume_ids[count.index] |
71 | 29 | wait_interval = var.wait_interval |
72 | 30 | } |
73 | 31 | } |
74 | 32 |
|
| 33 | +data "template_file" "instance_id" { |
| 34 | + template = file("${path.module}/instance_id.tpl") |
| 35 | +} |
| 36 | + |
75 | 37 | output "init_snippet" { |
76 | | - value = data.template_file.init_snippet.rendered |
| 38 | + value = <<EOF |
| 39 | +${var.init_prefix} |
| 40 | +${data.template_file.instance_id.rendered} |
| 41 | +${join("\n", data.template_file.init_snippet.*.rendered)} |
| 42 | +${var.init_suffix} |
| 43 | +EOF |
77 | 44 | } |
78 | 45 |
|
0 commit comments