resource "nomad_job" "redis" {
  hcl2 {
    enabled = true
  }

  jobspec = file("${path.module}/redis.nomad")

  # Block until deployed as there are servics dependent on this one
  detach = false
}

resource "nomad_job" "rediscommander" {
  hcl2 {
    enabled = true
  }

  jobspec = file("${path.module}/rediscommander.nomad")
}

resource "consul_config_entry" "redis_intents" {
  name = "redis"
  kind = "service-intentions"

  config_json = jsonencode({
    Sources = [
      {
        Action     = "allow"
        Name       = "blocky-api"
        Precedence = 9
        Type       = "consul"
      },
      {
        Action     = "allow"
        Name       = "rediscommander"
        Precedence = 9
        Type       = "consul"
      },
      {
        Action     = "allow"
        Name       = "authelia"
        Precedence = 9
        Type       = "consul"
      },
    ]
  })
}