moved module from monorepo to independent repo

This commit is contained in:
Bertrand Lanson 2023-07-16 13:24:45 +02:00
parent 63f007f6d7
commit 77b2c46763
3 changed files with 162 additions and 1 deletions

View File

@ -2,3 +2,43 @@ terraform-nomad-base
========= =========
A brief description of the role goes here. A brief description of the role goes here.
<!-- BEGIN_TF_DOCS -->
## Requirements
No requirements.
## Providers
| Name | Version |
|------|---------|
| <a name="provider_consul"></a> [consul](#provider\_consul) | n/a |
| <a name="provider_nomad"></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 |
|------|-------------|------|---------|:--------:|
| <a name="input_consul_intentions"></a> [consul\_intentions](#input\_consul\_intentions) | List of intentions associated with the job(s) | <pre>map(object({<br> source_name = string<br> destination_name = string<br> action = string<br> }))</pre> | `{}` | no |
| <a name="input_consul_kv"></a> [consul\_kv](#input\_consul\_kv) | List key/value pairs to put at a specific prefix (mainly for traefik) | `map(any)` | `{}` | no |
| <a name="input_jobs"></a> [jobs](#input\_jobs) | The list of jobs to deploy | `map(string)` | `{}` | no |
| <a name="input_nfs_volumes"></a> [nfs\_volumes](#input\_nfs\_volumes) | List of nfs volumes associated to the job(s) | <pre>map(object({<br> type = string<br> plugin_id = string<br> namespace = string<br> capability = map(string)<br> context = map(string)<br> mount_options = object({<br> fs_type = string<br> mount_flags = list(string)<br> })<br> }))</pre> | `{}` | no |
| <a name="input_volumes"></a> [volumes](#input\_volumes) | List of volumes associated to the job(s) | <pre>map(object({<br> type = string<br> plugin_id = string<br> namespace = string<br> capacity_min = string<br> capacity_max = string<br> capability = map(string)<br> parameters = map(string)<br> secrets = map(string)<br> }))</pre> | `{}` | no |
## Outputs
No outputs.
<!-- END_TF_DOCS -->

69
main.tf
View File

@ -1 +1,70 @@
# main file for terraform-nomad-base # 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
}

View File

@ -1 +1,53 @@
# variables file for terraform-nomad-base # 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 = {}
}