diff --git a/README.md b/README.md index 27cb95d..728efcf 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,44 @@ terraform-nomad-base ========= -A brief description of the role goes here. \ No newline at end of file +A brief description of the role goes here. + +## Requirements + +No requirements. + +## Providers + +| Name | Version | +|------|---------| +| [consul](#provider\_consul) | n/a | +| [nomad](#provider\_nomad) | n/a | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [consul_intention.this](https://registry.terraform.io/providers/hashicorp/consul/latest/docs/resources/intention) | resource | +| [consul_key_prefix.this](https://registry.terraform.io/providers/hashicorp/consul/latest/docs/resources/key_prefix) | resource | +| [nomad_external_volume.this](https://registry.terraform.io/providers/hashicorp/nomad/latest/docs/resources/external_volume) | resource | +| [nomad_job.this](https://registry.terraform.io/providers/hashicorp/nomad/latest/docs/resources/job) | resource | +| [nomad_volume.this](https://registry.terraform.io/providers/hashicorp/nomad/latest/docs/resources/volume) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [consul\_intentions](#input\_consul\_intentions) | List of intentions associated with the job(s) |
map(object({
source_name = string
destination_name = string
action = string
}))
| `{}` | no | +| [consul\_kv](#input\_consul\_kv) | List key/value pairs to put at a specific prefix (mainly for traefik) | `map(any)` | `{}` | no | +| [jobs](#input\_jobs) | The list of jobs to deploy | `map(string)` | `{}` | no | +| [nfs\_volumes](#input\_nfs\_volumes) | List of nfs volumes associated to the job(s) |
map(object({
type = string
plugin_id = string
namespace = string
capability = map(string)
context = map(string)
mount_options = object({
fs_type = string
mount_flags = list(string)
})
}))
| `{}` | no | +| [volumes](#input\_volumes) | List of volumes associated to the job(s) |
map(object({
type = string
plugin_id = string
namespace = string
capacity_min = string
capacity_max = string
capability = map(string)
parameters = map(string)
secrets = map(string)
}))
| `{}` | no | + +## Outputs + +No outputs. + \ No newline at end of file diff --git a/main.tf b/main.tf index ecdb79d..b61b9e3 100644 --- a/main.tf +++ b/main.tf @@ -1 +1,70 @@ # main file for terraform-nomad-base +resource "nomad_job" "this" { + for_each = var.jobs + depends_on = [ + nomad_external_volume.this, + consul_key_prefix.this, + # consul_config_entry.this + consul_intention.this + ] + + jobspec = file("${each.value}") + purge_on_destroy = true + hcl2 { + enabled = true + allow_fs = true + } +} + +resource "nomad_external_volume" "this" { + for_each = var.volumes + + volume_id = each.key + name = each.key + type = each.value.type + plugin_id = each.value.plugin_id + namespace = each.value.namespace + capacity_min = each.value.capacity_min + capacity_max = each.value.capacity_max + capability { + access_mode = each.value.capability.access_mode + attachment_mode = each.value.capability.attachment_mode + } + parameters = sensitive(each.value.parameters) + secrets = sensitive(each.value.secrets) +} + +resource "nomad_volume" "this" { + for_each = var.nfs_volumes + + volume_id = each.key + external_id = each.key + name = each.key + type = each.value.type + plugin_id = each.value.plugin_id + namespace = each.value.namespace + capability { + access_mode = each.value.capability.access_mode + attachment_mode = each.value.capability.attachment_mode + } + context = each.value.context + mount_options { + fs_type = each.value.mount_options.fs_type + mount_flags = each.value.mount_options.mount_flags + } +} + +resource "consul_key_prefix" "this" { + for_each = var.consul_kv + + path_prefix = each.key + subkeys = each.value +} + +resource "consul_intention" "this" { + for_each = var.consul_intentions + + source_name = each.value.source_name + destination_name = each.value.destination_name + action = each.value.action +} \ No newline at end of file diff --git a/variables.tf b/variables.tf index dc0c9fd..f5162e1 100644 --- a/variables.tf +++ b/variables.tf @@ -1 +1,53 @@ # variables file for terraform-nomad-base +variable "jobs" { + type = map(string) + description = "The list of jobs to deploy" + default = {} +} + +variable "volumes" { + type = map(object({ + type = string + plugin_id = string + namespace = string + capacity_min = string + capacity_max = string + capability = map(string) + parameters = map(string) + secrets = map(string) + })) + description = "List of volumes associated to the job(s)" + default = {} +} + +variable "nfs_volumes" { + type = map(object({ + type = string + plugin_id = string + namespace = string + capability = map(string) + context = map(string) + mount_options = object({ + fs_type = string + mount_flags = list(string) + }) + })) + description = "List of nfs volumes associated to the job(s)" + default = {} +} + +variable "consul_kv" { + type = map(any) + description = "List key/value pairs to put at a specific prefix (mainly for traefik)" + default = {} +} + +variable "consul_intentions" { + type = map(object({ + source_name = string + destination_name = string + action = string + })) + description = "List of intentions associated with the job(s)" + default = {} +} \ No newline at end of file