Configure Consul-Terraform-Sync

    A task captures a network automation process by defining which network resources to update on a given condition. Configure CTS with one or more tasks that contain a list of Consul services, a Terraform module, and various Terraform providers.

    Within the task block, the list of services for a task represents the service layer that drives network automation. The is the discovery location of the Terraform module that defines the network automation process for the task. The condition, not shown below, defaults to the services condition when unconfigured such that network resources are updated on changes to the list of services over time.

    1. task {
    2. name = "website-x"
    3. description = "automate services for website-x"
    4. module = "namespace/example/module"
    5. version = "1.0.0"
    6. providers = ["myprovider"]
    7. condition "services" {
    8. names = ["web", "api"]
    9. }
    10. }

    Configuring Terraform providers within CTS requires 2 config components. The first component is required within the . All providers configured for CTS must be listed within the required_providers stanza to satisfy a Terraform v0.13+ requirement for Terraform to discover and install them. The providers listed are later organized by CTS to be included in the appropriate Terraform configuration files for each task.

    1. driver "terraform" {
    2. required_providers {
    3. myprovider = {
    4. source = "namespace/myprovider"
    5. version = "1.3.0"
    6. }
    7. }

    The second component for configuring a provider is the . This block resembles provider blocks for Terraform configuration and has the same responsibility for understanding API interactions and exposing resources for a specific infrastructure platform.

    1. terraform_provider "myprovider" {
    2. address = "myprovider.example.com"
    3. }

    Piecing it all together, the configuration file for CTS will have several HCL blocks in addition to other options for configuring the CTS daemon: task, driver.terraform, and terraform_provider blocks.

    An example HCL configuration file is shown below to automate one task to execute a Terraform module on the condition when there are changes to two services.

    cts-example-config.hcl

    1. log_level = "info"
    2. syslog {
    3. enabled = true
    4. }
    5. consul {
    6. address = "consul.example.com"
    7. }
    8. task {
    9. name = "website-x"
    10. description = "automate services for website-x"
    11. module = "namespace/example/module"
    12. providers = ["myprovider"]
    13. condition "services" {
    14. }
    15. buffer_period {
    16. min = "10s"
    17. }
    18. }
    19. driver "terraform" {
    20. log = true
    21. required_providers {
    22. myprovider = {
    23. source = "namespace/myprovider"
    24. version = "1.3.0"
    25. }
    26. }
    27. }
    28. terraform_provider "myprovider" {
    29. }