Skip to content

Commit

Permalink
feat(generic_resource): add discrete and named generic resource to re…
Browse files Browse the repository at this point in the history
…servation for all services
  • Loading branch information
tafaust committed Aug 10, 2024
1 parent 843fba3 commit b461c41
Show file tree
Hide file tree
Showing 27 changed files with 77 additions and 17 deletions.
2 changes: 1 addition & 1 deletion modules/base_docker_service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ No modules.
| <a name="input_network_aliases"></a> [network\_aliases](#input\_network\_aliases) | (Optional) Aliases (alternative hostnames) for this service on all specified networks. Other containers on the same network can use either the service name or this alias to connect to one of the service's containers. See https://docs.docker.com/compose/compose-file/compose-file-v3/#aliases for more information. | `list(string)` | `[]` | no |
| <a name="input_networks"></a> [networks](#input\_networks) | (Optional) The networks attached to this service | `set(string)` | `[]` | no |
| <a name="input_ports"></a> [ports](#input\_ports) | (Optional) The ports to expose on the swarm for the service.<br><br> ports = [{<br> target\_port = The port inside the container.<br> name = A random name for the port.<br> protocol = Represents the protocol of a port: tcp, udp or sctp. Defaults to 'tcp'.<br> publish\_mode = Represents the mode in which the port is to be published: 'ingress' or 'host'. Defaults to 'ingress'.<br> published\_port = The port on the swarm hosts.<br> }] | <pre>list(object({<br> target_port = number,<br> name = optional(string),<br> protocol = optional(string, "tcp"),<br> publish_mode = optional(string, "ingress")<br> published_port = optional(number),<br> }))</pre> | `[]` | no |
| <a name="input_reservation"></a> [reservation](#input\_reservation) | (Optional) The resource reservation of service, memory unit is MB | <pre>object({<br> cores = optional(number)<br> memory = optional(number)<br> })</pre> | `null` | no |
| <a name="input_reservation"></a> [reservation](#input\_reservation) | (Optional) The resource reservation of service, memory unit is MB | <pre>object({<br> cores = optional(number)<br> memory = optional(number)<br> generic_resources = optional(object({<br> discrete_resources_spec = optional(set(string))<br> named_resources_spec = optional(set(string))<br> }))<br> })</pre> | `null` | no |
| <a name="input_restart_policy"></a> [restart\_policy](#input\_restart\_policy) | (Optional) Restart policy for containers.<br><br> restart\_policy = {<br> condition = Condition for restart; possible options are "none" which does not automatically restart, "on-failure" restarts on non-zero exit, "any" (default) restarts regardless of exit status.<br> delay = Delay between restart attempts (default is 5s) (ms\|s\|m\|h).<br> max\_attempts = How many times to attempt to restart a container before giving up (default: 0, i.e. never give up). If the restart does not succeed within the configured window, this attempt doesn't count toward the configured max\_attempts value. For example, if max\_attempts is set to '2', and the restart fails on the first attempt, more than two restarts must be attempted.<br> window = The time window used to evaluate the restart policy (default value is 5s, 0 means unbounded) (ms\|s\|m\|h).<br> } | <pre>object({<br> condition = optional(string, "any")<br> delay = optional(string, "5s")<br> max_attempts = optional(number, 0)<br> window = optional(string, "5s")<br> })</pre> | <pre>{<br> "condition": "any",<br> "delay": "5s",<br> "max_attempts": 0,<br> "window": "5s"<br>}</pre> | no |
| <a name="input_secret_map"></a> [secret\_map](#input\_secret\_map) | (Optional) Similar to the secrets variable but allows for docker secret creation from terraform resources.<br><br> secret\_map = {<br> key = {<br> file\_name = Represents the final filename in the filesystem.<br> secret\_id = ID of the specific secret that we're referencing.<br> file\_gid = Represents the file GID. Defaults to '0'.<br> file\_mode = Represents represents the FileMode of the file. Defaults to '0o444'.<br> file\_uid = Represents the file UID. Defaults to '0'.<br> secret\_name = Name of the secret that this references, but this is just provided for lookup/display purposes. The config in the reference will be identified by its ID.<br> }<br> } | <pre>map(object({<br> file_name = string<br> # secret_id = string # secret will be created and we take that resource id<br> file_gid = optional(string, "0")<br> file_mode = optional(number, 0444)<br> file_uid = optional(string, "0")<br> secret_name = optional(string, null)<br> secret_data = string<br> }))</pre> | `{}` | no |
| <a name="input_secrets"></a> [secrets](#input\_secrets) | (Optional) The secrets to create with and add to the docker container. Creates docker secrets from non-terraform-resources. | <pre>set(object({<br> file_name = optional(string)<br> secret_id = optional(string, null) # secret_id will be auto-generated if not provided; secrets with secret_id must exist beforehand<br> file_gid = optional(string, "0")<br> file_mode = optional(number, 0444)<br> file_uid = optional(string, "0")<br> secret_name = optional(string, null)<br> secret_data = string<br> }))</pre> | `[]` | no |
Expand Down
8 changes: 8 additions & 0 deletions modules/base_docker_service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ resource "docker_service" "this" {
content {
nano_cpus = reservation.value.cores == null ? null : reservation.value.cores * 1e9
memory_bytes = reservation.value.memory == null ? null : reservation.value.memory * 1e6

dynamic "generic_resources" {
for_each = reservation.value.generic_resources == null ? [] : [1]
content {
discrete_resources_spec = reservation.value.generic_resources.discrete_resources_spec
named_resources_spec = reservation.value.generic_resources.discrete_resources_spec
}
}
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions modules/base_docker_service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ variable "reservation" {
type = object({
cores = optional(number)
memory = optional(number)
generic_resources = optional(object({
discrete_resources_spec = optional(set(string))
named_resources_spec = optional(set(string))
}))
})
description = "(Optional) The resource reservation of service, memory unit is MB"
default = null
Expand Down
2 changes: 1 addition & 1 deletion modules/certbot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ No resources.
| <a name="input_network_aliases"></a> [network\_aliases](#input\_network\_aliases) | (Optional) Aliases (alternative hostnames) for this service on all specified networks. Other containers on the same network can use either the service name or this alias to connect to one of the service's containers. See https://docs.docker.com/compose/compose-file/compose-file-v3/#aliases for more information. | `list(string)` | `[]` | no |
| <a name="input_networks"></a> [networks](#input\_networks) | (Optional) The networks attached to this service | `set(string)` | `[]` | no |
| <a name="input_ports"></a> [ports](#input\_ports) | (Optional) The ports to expose on the swarm for the service.<br><br> ports = [{<br> target\_port = The port inside the container.<br> name = A random name for the port.<br> protocol = Represents the protocol of a port: tcp, udp or sctp. Defaults to 'tcp'.<br> publish\_mode = Represents the mode in which the port is to be published: 'ingress' or 'host'. Defaults to 'ingress'.<br> published\_port = The port on the swarm hosts.<br> }] | <pre>list(object({<br> target_port = number,<br> name = optional(string),<br> protocol = optional(string, "tcp"),<br> publish_mode = optional(string, "ingress")<br> published_port = optional(number),<br> }))</pre> | `[]` | no |
| <a name="input_reservation"></a> [reservation](#input\_reservation) | (Optional) The resource reservation of service, memory unit is MB | <pre>object({<br> cores = optional(number)<br> memory = optional(number)<br> })</pre> | `null` | no |
| <a name="input_reservation"></a> [reservation](#input\_reservation) | (Optional) The resource reservation of service, memory unit is MB | <pre>object({<br> cores = optional(number)<br> memory = optional(number)<br> generic_resources = optional(object({<br> discrete_resources_spec = optional(set(string))<br> named_resources_spec = optional(set(string))<br> }))<br> })</pre> | `null` | no |
| <a name="input_restart_policy"></a> [restart\_policy](#input\_restart\_policy) | (Optional) Restart policy for containers.<br><br> restart\_policy = {<br> condition = Condition for restart; possible options are "none" which does not automatically restart, "on-failure" restarts on non-zero exit, "any" (default) restarts regardless of exit status.<br> delay = Delay between restart attempts (default is 5s) (ms\|s\|m\|h).<br> max\_attempts = How many times to attempt to restart a container before giving up (default: 0, i.e. never give up). If the restart does not succeed within the configured window, this attempt doesn't count toward the configured max\_attempts value. For example, if max\_attempts is set to '2', and the restart fails on the first attempt, more than two restarts must be attempted.<br> window = The time window used to evaluate the restart policy (default value is 5s, 0 means unbounded) (ms\|s\|m\|h).<br> } | <pre>object({<br> condition = optional(string, "any")<br> delay = optional(string, "5s")<br> max_attempts = optional(number, 0)<br> window = optional(string, "5s")<br> })</pre> | <pre>{<br> "condition": "any",<br> "delay": "5s",<br> "max_attempts": 0,<br> "window": "5s"<br>}</pre> | no |
| <a name="input_secret_map"></a> [secret\_map](#input\_secret\_map) | (Optional) Similar to the secrets variable but allows for docker secret creation from terraform resources.<br><br> secret\_map = {<br> key = {<br> file\_name = Represents the final filename in the filesystem.<br> secret\_id = ID of the specific secret that we're referencing.<br> file\_gid = Represents the file GID. Defaults to '0'.<br> file\_mode = Represents represents the FileMode of the file. Defaults to '0o444'.<br> file\_uid = Represents the file UID. Defaults to '0'.<br> secret\_name = Name of the secret that this references, but this is just provided for lookup/display purposes. The config in the reference will be identified by its ID.<br> }<br> } | <pre>map(object({<br> file_name = string<br> # secret_id = string # secret will be created and we take that resource id<br> file_gid = optional(string, "0")<br> file_mode = optional(number, 0444)<br> file_uid = optional(string, "0")<br> secret_name = optional(string, null)<br> secret_data = string<br> }))</pre> | `{}` | no |
| <a name="input_secrets"></a> [secrets](#input\_secrets) | (Optional) The secrets to create with and add to the docker container. Creates docker secrets from non-terraform-resources. | <pre>set(object({<br> file_name = string<br> # secret_id = string # secret will be created and we take that resource id<br> file_gid = optional(string, "0")<br> file_mode = optional(number, 0444)<br> file_uid = optional(string, "0")<br> secret_name = optional(string, null)<br> secret_data = string<br> }))</pre> | `[]` | no |
Expand Down
4 changes: 4 additions & 0 deletions modules/certbot/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ variable "reservation" {
type = object({
cores = optional(number)
memory = optional(number)
generic_resources = optional(object({
discrete_resources_spec = optional(set(string))
named_resources_spec = optional(set(string))
}))
})
description = "(Optional) The resource reservation of service, memory unit is MB"
default = null
Expand Down
2 changes: 1 addition & 1 deletion modules/grafana/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ No resources.
| <a name="input_namespace"></a> [namespace](#input\_namespace) | (Optional) The namespace of Docker Swarm | `string` | `null` | no |
| <a name="input_network_aliases"></a> [network\_aliases](#input\_network\_aliases) | (Optional) Aliases (alternative hostnames) for this service on all specified networks. Other containers on the same network can use either the service name or this alias to connect to one of the service's containers. See https://docs.docker.com/compose/compose-file/compose-file-v3/#aliases for more information. | `list(string)` | `[]` | no |
| <a name="input_networks"></a> [networks](#input\_networks) | (Optional) The networks attached to this service | `set(string)` | `[]` | no |
| <a name="input_reservation"></a> [reservation](#input\_reservation) | (Optional) The resource reservation of service, memory unit is MB | <pre>object({<br> cores = optional(number)<br> memory = optional(number)<br> })</pre> | `null` | no |
| <a name="input_reservation"></a> [reservation](#input\_reservation) | (Optional) The resource reservation of service, memory unit is MB | <pre>object({<br> cores = optional(number)<br> memory = optional(number)<br> generic_resources = optional(object({<br> discrete_resources_spec = optional(set(string))<br> named_resources_spec = optional(set(string))<br> }))<br> })</pre> | `null` | no |
| <a name="input_restart_policy"></a> [restart\_policy](#input\_restart\_policy) | (Optional) Restart policy for containers.<br><br> restart\_policy = {<br> condition = Condition for restart; possible options are "none" which does not automatically restart, "on-failure" restarts on non-zero exit, "any" (default) restarts regardless of exit status.<br> delay = Delay between restart attempts (default is 5s) (ms\|s\|m\|h).<br> max\_attempts = How many times to attempt to restart a container before giving up (default: 0, i.e. never give up). If the restart does not succeed within the configured window, this attempt doesn't count toward the configured max\_attempts value. For example, if max\_attempts is set to '2', and the restart fails on the first attempt, more than two restarts must be attempted.<br> window = The time window used to evaluate the restart policy (default value is 5s, 0 means unbounded) (ms\|s\|m\|h).<br> } | <pre>object({<br> condition = optional(string, "any")<br> delay = optional(string, "5s")<br> max_attempts = optional(number, 0)<br> window = optional(string, "5s")<br> })</pre> | <pre>{<br> "condition": "any",<br> "delay": "5s",<br> "max_attempts": 0,<br> "window": "5s"<br>}</pre> | no |
| <a name="input_secret_map"></a> [secret\_map](#input\_secret\_map) | (Optional) Similar to the secrets variable but allows for docker secret creation from terraform resources.<br><br> secret\_map = {<br> key = {<br> file\_name = Represents the final filename in the filesystem.<br> secret\_id = ID of the specific secret that we're referencing.<br> file\_gid = Represents the file GID. Defaults to '0'.<br> file\_mode = Represents represents the FileMode of the file. Defaults to '0o444'.<br> file\_uid = Represents the file UID. Defaults to '0'.<br> secret\_name = Name of the secret that this references, but this is just provided for lookup/display purposes. The config in the reference will be identified by its ID.<br> }<br> } | <pre>map(object({<br> file_name = string<br> # secret_id = string # secret will be created and we take that resource id<br> file_gid = optional(string, "0")<br> file_mode = optional(number, 0444)<br> file_uid = optional(string, "0")<br> secret_name = optional(string, null)<br> secret_data = string<br> }))</pre> | `{}` | no |
| <a name="input_secrets"></a> [secrets](#input\_secrets) | (Optional) The secrets to create with and add to the docker container. Creates docker secrets from non-terraform-resources. | <pre>set(object({<br> file_name = string<br> # secret_id = string # secret will be created and we take that resource id<br> file_gid = optional(string, "0")<br> file_mode = optional(number, 0444)<br> file_uid = optional(string, "0")<br> secret_name = optional(string, null)<br> secret_data = string<br> }))</pre> | `[]` | no |
Expand Down
4 changes: 4 additions & 0 deletions modules/grafana/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ variable "reservation" {
type = object({
cores = optional(number)
memory = optional(number)
generic_resources = optional(object({
discrete_resources_spec = optional(set(string))
named_resources_spec = optional(set(string))
}))
})
description = "(Optional) The resource reservation of service, memory unit is MB"
default = null
Expand Down
Loading

0 comments on commit b461c41

Please sign in to comment.