| 1 |
// These can split into separate files, come from environment variables / commandline etc., as |
| 2 |
// desired. |
| 3 |
local aws_region = 'us-east-1'; |
| 4 |
|
| 5 |
// Ubuntu Precise 12.04 LTS (x64) |
| 6 |
local aws_amis = { |
| 7 |
'eu-west-1': 'ami-b1cf19c6', |
| 8 |
'us-east-1': 'ami-de7ab6b6', |
| 9 |
'us-west-1': 'ami-3f75767a', |
| 10 |
'us-west-2': 'ami-21f78e11', |
| 11 |
}; |
| 12 |
|
| 13 |
// Can also give an explicit list of indexes, or a list of names |
| 14 |
local web_indexes = std.range(1, 4); |
| 15 |
|
| 16 |
{ |
| 17 |
// Specify the provider and access details |
| 18 |
provider: { |
| 19 |
aws: { |
| 20 |
region: aws_region, |
| 21 |
access_key: 'XXX', |
| 22 |
secret_key: 'YYY', |
| 23 |
}, |
| 24 |
}, |
| 25 |
|
| 26 |
resource: { |
| 27 |
aws_elb: { |
| 28 |
web: { |
| 29 |
name: 'terraform-example-elb', |
| 30 |
|
| 31 |
// The same availability zone as our instances |
| 32 |
// (Array comprehension syntax, as in Python) |
| 33 |
availability_zones: ['${aws_instance.web-%d.availability_zone}' % i for i in web_indexes], |
| 34 |
|
| 35 |
listener: { |
| 36 |
instance_port: 80, |
| 37 |
instance_protocol: 'http', |
| 38 |
lb_port: 80, |
| 39 |
lb_protocol: 'http', |
| 40 |
}, |
| 41 |
|
| 42 |
// The instances are registered automatically |
| 43 |
instances: ['${aws_instance.web-%d.id}' % i for i in web_indexes], |
| 44 |
}, |
| 45 |
}, |
| 46 |
|
| 47 |
aws_instance: { |
| 48 |
|
| 49 |
// Object comprehension syntax (similar to Python) |
| 50 |
['web-%d' % i]: { |
| 51 |
// i is a scoped variable here |
| 52 |
instance_type: 'm1.small', |
| 53 |
ami: aws_amis[aws_region], |
| 54 |
} |
| 55 |
for i in web_indexes |
| 56 |
}, |
| 57 |
|
| 58 |
}, |
| 59 |
output: { |
| 60 |
address: { |
| 61 |
value: 'Instances: ' + std.join(', ', ['${aws_instance.web-%d.id}' % i for i in web_indexes]), |
| 62 |
}, |
| 63 |
}, |
| 64 |
} |