locals {
  wireguard_version = var.wireguard_version
  wireguard_config = try(templatefile("${path.module}/resources/wireguard.conf.tpl", {
    wireguard_private_key    = var.wireguard_config.private_key
    wireguard_public_key     = var.wireguard_config.public_key
    wireguard_pre_shared_key = var.wireguard_config.pre_shared_key
    wireguard_address        = var.wireguard_config.address
    wireguard_dns            = var.wireguard_config.dns
    wireguard_allowed_ips    = join(", ", var.wireguard_config.allowed_ips)
    wireguard_endpoint       = "${var.wireguard_config.endpoint}:${var.wireguard_config.endpoint_port}"
  }), "null")
  wireguard_config_checksum = nonsensitive(sha256(local.wireguard_config))

  stunnel_version = var.stunnel_version
  stunnel_config = templatefile("${path.module}/resources/stunnel.conf.tpl", {
    local_targets  = var.local_targets
    remote_targets = var.remote_targets
  })
  stunnel_config_checksum = sha256(local.stunnel_config)
}
