hashicorp/consul-terraform-sync

Module inputs duplicated in state store

mkam opened this issue · 0 comments

mkam commented

Describe the bug

Module inputs are duplicated in the state store because the merge function does not account for if the module inputs that are being merged are the same. This doesn't have any impact currently on the end-to-end behavior of CTS, but will be an issue when we extend the use of the state store.

When a task is set in the state store and the task already exists, the task is merged (see SetTask()). The task is initially set when it's loaded into the state from the configuration. It's then set again when it's created and run for the first time. Additionally, if a task is enabled/disabled, the task is merged and duplication occurs.

Configuration File(s)

Example Tasks
task {
  name = "kv-task"
  module = "lornasong/cts_kv_file/local"
  providers = ["local"]
  condition "services" {
    names = ["api", "db"]
    use_as_module_input = false
  }
  module_input "consul-kv" {
    path = "test"
  }
}

task {
  name = "schedule-task"
  module = "mkam/hello/cts"
  condition "schedule" {
    cron = "*/20 * * * * * *"
  }
  module_input "services" {
    names = ["web", "api"]
  }
}

Expected Behavior

The module inputs of a task should not contain duplicates.

Actual Behavior

Module inputs are duplicated when created and updated.

Steps to Reproduce

  1. Start CTS with a task
  2. Use a debugger to view the task's module inputs

Additional Context

Another complication is that for names in the services module input, the order may be different even if the contents are the same. We should treat these as a set where order does not matter.