2014-10-14 07:18:45 +02:00
|
|
|
# Setup the Consul provisioner to use the demo cluster
|
|
|
|
provider "consul" {
|
2016-09-22 13:49:09 +02:00
|
|
|
address = "demo.consul.io:80"
|
2015-08-31 10:19:02 +02:00
|
|
|
datacenter = "nyc1"
|
2014-10-14 07:18:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Setup an AWS provider
|
|
|
|
provider "aws" {
|
2015-08-31 10:19:02 +02:00
|
|
|
region = "${var.aws_region}"
|
2014-10-14 07:18:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Setup a key in Consul to provide inputs
|
|
|
|
resource "consul_keys" "input" {
|
2015-08-31 10:19:02 +02:00
|
|
|
key {
|
2016-09-22 13:49:09 +02:00
|
|
|
name = "size"
|
|
|
|
path = "tf_test/size"
|
2015-08-31 10:19:02 +02:00
|
|
|
default = "m1.small"
|
|
|
|
}
|
2014-10-14 07:18:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Setup a new AWS instance using a dynamic ami and
|
|
|
|
# instance type
|
|
|
|
resource "aws_instance" "test" {
|
2016-09-22 13:49:09 +02:00
|
|
|
ami = "${lookup(var.aws_amis, var.aws_region)}"
|
2015-08-31 10:19:02 +02:00
|
|
|
instance_type = "${consul_keys.input.var.size}"
|
2014-10-14 07:18:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Setup a key in Consul to store the instance id and
|
|
|
|
# the DNS name of the instance
|
|
|
|
resource "consul_keys" "test" {
|
2015-08-31 10:19:02 +02:00
|
|
|
key {
|
2016-09-22 13:49:09 +02:00
|
|
|
name = "id"
|
|
|
|
path = "tf_test/id"
|
|
|
|
value = "${aws_instance.test.id}"
|
2015-08-31 10:19:02 +02:00
|
|
|
delete = true
|
|
|
|
}
|
2016-09-22 13:49:09 +02:00
|
|
|
|
2015-08-31 10:19:02 +02:00
|
|
|
key {
|
2016-09-22 13:49:09 +02:00
|
|
|
name = "address"
|
|
|
|
path = "tf_test/public_dns"
|
|
|
|
value = "${aws_instance.test.public_dns}"
|
2015-08-31 10:19:02 +02:00
|
|
|
delete = true
|
|
|
|
}
|
2014-10-14 07:18:45 +02:00
|
|
|
}
|