github.com/hobbeswalsh/terraform@v0.3.7-0.20150619183303-ad17cf55a0fa/website/source/intro/examples/consul.html.markdown (about)

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