github.com/andresvia/terraform@v0.6.15-0.20160412045437-d51c75946785/examples/consul/README.md (about) 1 # Consul Example 2 3 [Consul](http://www.consul.io) is a tool for service discovery, configuration 4 and orchestration. The Key/Value store it provides is often used to store 5 application configuration and information about the infrastructure necessary 6 to process requests. 7 8 Terraform provides a [Consul provider](https://www.terraform.io/docs/providers/consul/index.html) which 9 can be used to interface with Consul from inside a Terraform configuration. 10 11 For our example, we use the [Consul demo cluster](http://demo.consul.io) 12 to both read configuration and store information about a newly created EC2 instance. 13 The size of the EC2 instance will be determined by the "tf\_test/size" key in Consul, 14 and will default to "m1.small" if that key does not exist. Once the instance is created 15 the "tf\_test/id" and "tf\_test/public\_dns" keys will be set with the computed 16 values for the instance. 17 18 Before we run the example, use the [Web UI](http://demo.consul.io/ui/#/nyc1/kv/) 19 to set the "tf\_test/size" key to "t1.micro". Once that is done, 20 copy the configuration into a configuration file ("consul.tf" works fine). 21 Either provide the AWS credentials as a default value in the configuration 22 or invoke `apply` with the appropriate variables set. 23 24 Once the `apply` has completed, we can see the keys in Consul by 25 visiting the [Web UI](http://demo.consul.io/ui/#/nyc1/kv/). We can see 26 that the "tf\_test/id" and "tf\_test/public\_dns" values have been 27 set. 28 29 We can now teardown the infrastructure following the 30 [instructions here](https://www.terraform.io/intro/getting-started/destroy.html). Because 31 we set the 'delete' property of two of the Consul keys, Terraform 32 will cleanup those keys on destroy. We can verify this by using 33 the Web UI. 34 35 The point of this example is to show that Consul can be used with 36 Terraform both to enable dynamic inputs, but to also store outputs. 37 38 Inputs like AMI name, security groups, puppet roles, bootstrap scripts, 39 etc can all be loaded from Consul. This allows the specifics of an 40 infrastructure to be decoupled from its overall architecture. This enables 41 details to be changed without updating the Terraform configuration. 42 43 Outputs from Terraform can also be easily stored in Consul. One powerful 44 features this enables is using Consul for inventory management. If an 45 application relies on ELB for routing, Terraform can update the application's 46 configuration directly by setting the ELB address into Consul. Any resource 47 attribute can be stored in Consul, allowing an operator to capture anything 48 useful. 49