github.com/wikibal01/hashicorp-terraform@v0.11.12-beta1/website/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 Source Code**](https://github.com/terraform-providers/terraform-provider-consul/tree/master/examples/kv)
    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](https://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](https://demo.consul.io/ui/dc1/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](https://demo.consul.io/ui/dc1/kv/). We can see
    36  that the `tf_test/id` and `tf_test/public_dns` values have been
    37  set.
    38  
    39  You can now [tear down the infrastructure](/intro/getting-started/destroy.html)
    40  Because we set the `delete` property of two of the Consul keys, Terraform
    41  will clean up those keys on destroy. We can verify this by using
    42  the Web UI.
    43  
    44  This example has shown that Consul can be used with Terraform both to read
    45  existing values and to store generated results.
    46  
    47  Inputs like AMI name, security groups, Puppet roles, bootstrap scripts,
    48  etc can all be loaded from Consul. This allows the specifics of an
    49  infrastructure to be decoupled from its overall architecture. This enables
    50  details to be changed without updating the Terraform configuration.
    51  
    52  Outputs from Terraform can also be easily stored in Consul. One powerful
    53  feature this enables is using Consul for inventory management. If an
    54  application relies on ELB for routing, Terraform can update the application's
    55  configuration directly by setting the ELB address into Consul. Any resource
    56  attribute can be stored in Consul, allowing an operator to capture anything
    57  useful.