Skip to content

Commit

Permalink
fix: make sure variables.tf used in tests is the same as the one in m…
Browse files Browse the repository at this point in the history
…odule (#61)

* fix: allow empty capabilities and docker_networks

* test: make sure variables.tf used in tests is the same as module

examples/basic/variables.tf should be exactly the same as the one used
in the module. It allow us to get any errors when any variable is
omitted.

* ci: add diff action to check variables.tf
  • Loading branch information
alinefr authored Jun 16, 2023
1 parent 2064505 commit 1bb3109
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 70 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: GuillaumeFalourd/diff-action@v1
with:
first_file_path: variables.tf
second_file_path: examples/basic/variables.tf
expected_result: PASSED
- uses: hashicorp/[email protected]
with:
terraform_wrapper: false
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ No modules.
| <a name="input_container_name"></a> [container\_name](#input\_container\_name) | Custom container name | `string` | `null` | no |
| <a name="input_devices"></a> [devices](#input\_devices) | Device mappings | <pre>map(object({<br> container_path = string<br> permissions = string<br> }))</pre> | `{}` | no |
| <a name="input_dns"></a> [dns](#input\_dns) | Set custom dns servers for the container | `list(string)` | `null` | no |
| <a name="input_docker_networks"></a> [docker\_networks](#input\_docker\_networks) | List of custom networks to create<pre>hcl<br>docker_networks = [<br> {<br> name = "proxy-tier"<br> ipam_config = {<br> aux_address = {}<br> gateway = "10.0.0.1"<br> subnet = "10.0.0.0/24"<br> }<br> }<br>]</pre> | `any` | `null` | no |
| <a name="input_docker_networks"></a> [docker\_networks](#input\_docker\_networks) | List of custom networks to create<pre>hcl<br>docker_networks = [<br> {<br> name = "proxy-tier"<br> ipam_config = {<br> aux_address = {}<br> gateway = "10.0.0.1"<br> subnet = "10.0.0.0/24"<br> }<br> }<br>]</pre> | `any` | `[]` | no |
| <a name="input_entrypoint"></a> [entrypoint](#input\_entrypoint) | Override the default entrypoint | `list(string)` | `null` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | Add environment variables | `map(string)` | `null` | no |
| <a name="input_healthcheck"></a> [healthcheck](#input\_healthcheck) | Test to check if container is healthy | <pre>object({<br> interval = string<br> retries = number<br> start_period = string<br> test = list(string)<br> timeout = string<br> })</pre> | `null` | no |
Expand Down
38 changes: 20 additions & 18 deletions examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,26 @@ No resources.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_capabilities"></a> [capabilities](#input\_capabilities) | n/a | `map(any)` | `{}` | no |
| <a name="input_command"></a> [command](#input\_command) | n/a | `list(string)` | `null` | no |
| <a name="input_container_name"></a> [container\_name](#input\_container\_name) | n/a | `string` | n/a | yes |
| <a name="input_devices"></a> [devices](#input\_devices) | n/a | `map(any)` | `{}` | no |
| <a name="input_dns"></a> [dns](#input\_dns) | n/a | `list(string)` | `null` | no |
| <a name="input_docker_networks"></a> [docker\_networks](#input\_docker\_networks) | n/a | `list(any)` | `[]` | no |
| <a name="input_entrypoint"></a> [entrypoint](#input\_entrypoint) | n/a | `list(string)` | `null` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | n/a | `map(string)` | `null` | no |
| <a name="input_host_paths"></a> [host\_paths](#input\_host\_paths) | n/a | `map(any)` | `{}` | no |
| <a name="input_hostname"></a> [hostname](#input\_hostname) | n/a | `string` | `null` | no |
| <a name="input_image"></a> [image](#input\_image) | n/a | `string` | n/a | yes |
| <a name="input_named_volumes"></a> [named\_volumes](#input\_named\_volumes) | n/a | `map(any)` | `{}` | no |
| <a name="input_network_mode"></a> [network\_mode](#input\_network\_mode) | n/a | `string` | `null` | no |
| <a name="input_networks_advanced"></a> [networks\_advanced](#input\_networks\_advanced) | n/a | `list(any)` | `[]` | no |
| <a name="input_ports"></a> [ports](#input\_ports) | n/a | `list(any)` | `null` | no |
| <a name="input_privileged"></a> [privileged](#input\_privileged) | n/a | `bool` | `false` | no |
| <a name="input_restart_policy"></a> [restart\_policy](#input\_restart\_policy) | n/a | `string` | `null` | no |
| <a name="input_working_dir"></a> [working\_dir](#input\_working\_dir) | n/a | `string` | `null` | no |
| <a name="input_capabilities"></a> [capabilities](#input\_capabilities) | Add or drop container capabilities | <pre>object({<br> add = list(string)<br> drop = list(string)<br> })</pre> | `null` | no |
| <a name="input_command"></a> [command](#input\_command) | Override the default command | `list(string)` | `null` | no |
| <a name="input_container_name"></a> [container\_name](#input\_container\_name) | Custom container name | `string` | `null` | no |
| <a name="input_devices"></a> [devices](#input\_devices) | Device mappings | <pre>map(object({<br> container_path = string<br> permissions = string<br> }))</pre> | `{}` | no |
| <a name="input_dns"></a> [dns](#input\_dns) | Set custom dns servers for the container | `list(string)` | `null` | no |
| <a name="input_docker_networks"></a> [docker\_networks](#input\_docker\_networks) | List of custom networks to create<pre>hcl<br>docker_networks = [<br> {<br> name = "proxy-tier"<br> ipam_config = {<br> aux_address = {}<br> gateway = "10.0.0.1"<br> subnet = "10.0.0.0/24"<br> }<br> }<br>]</pre> | `any` | `[]` | no |
| <a name="input_entrypoint"></a> [entrypoint](#input\_entrypoint) | Override the default entrypoint | `list(string)` | `null` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | Add environment variables | `map(string)` | `null` | no |
| <a name="input_healthcheck"></a> [healthcheck](#input\_healthcheck) | Test to check if container is healthy | <pre>object({<br> interval = string<br> retries = number<br> start_period = string<br> test = list(string)<br> timeout = string<br> })</pre> | `null` | no |
| <a name="input_host_paths"></a> [host\_paths](#input\_host\_paths) | Mount host paths | <pre>map(object({<br> container_path = string<br> read_only = bool<br> }))</pre> | `{}` | no |
| <a name="input_hostname"></a> [hostname](#input\_hostname) | Set docker hostname | `string` | `null` | no |
| <a name="input_image"></a> [image](#input\_image) | Specify the image to start the container from. Can either be a repository/tag or a partial image ID | `string` | n/a | yes |
| <a name="input_named_volumes"></a> [named\_volumes](#input\_named\_volumes) | Mount named volumes | <pre>map(object({<br> container_path = string<br> read_only = bool<br> create = bool<br> }))</pre> | `{}` | no |
| <a name="input_network_mode"></a> [network\_mode](#input\_network\_mode) | Specify a custom network mode | `string` | `null` | no |
| <a name="input_networks_advanced"></a> [networks\_advanced](#input\_networks\_advanced) | Advanced network options for the container<pre>hcl<br>networks_advanced = [<br> {<br> name = "proxy-tier"<br> ipv4_address = "10.0.0.14"<br> },<br> {<br> name = "media-tier"<br> ipv4_address = "172.0.0.14"<br> }<br>]</pre> | `any` | `null` | no |
| <a name="input_ports"></a> [ports](#input\_ports) | Expose ports | <pre>list(object({<br> internal = number<br> external = number<br> protocol = string<br> }))</pre> | `null` | no |
| <a name="input_privileged"></a> [privileged](#input\_privileged) | Give extended privileges to this container | `bool` | `false` | no |
| <a name="input_restart_policy"></a> [restart\_policy](#input\_restart\_policy) | Restart policy. Default: no | `string` | `"no"` | no |
| <a name="input_volumes_from_containers"></a> [volumes\_from\_containers](#input\_volumes\_from\_containers) | Mount volumes from another container | `list(any)` | `null` | no |
| <a name="input_working_dir"></a> [working\_dir](#input\_working\_dir) | Working directory inside the container | `string` | `null` | no |

## Outputs

Expand Down
163 changes: 113 additions & 50 deletions examples/basic/variables.tf
Original file line number Diff line number Diff line change
@@ -1,87 +1,150 @@
variable "image" {
type = string
description = "Specify the image to start the container from. Can either be a repository/tag or a partial image ID"
type = string
}

variable "container_name" {
type = string
description = "Custom container name"
type = string
default = null
}

variable "hostname" {
type = string
default = null
description = "Set docker hostname"
type = string
default = null
}

variable "restart_policy" {
type = string
default = null
}

variable "working_dir" {
type = string
default = null
description = "Working directory inside the container"
type = string
default = null
}
variable "restart_policy" {
description = "Restart policy. Default: no"
type = string
default = "no"
}

variable "privileged" {
type = bool
default = false
description = "Give extended privileges to this container"
type = bool
default = false
}

variable "network_mode" {
type = string
default = null
description = "Specify a custom network mode"
type = string
default = null
}

variable "dns" {
type = list(string)
default = null
description = "Set custom dns servers for the container"
type = list(string)
default = null
}

variable "entrypoint" {
type = list(string)
default = null
description = "Override the default entrypoint"
type = list(string)
default = null
}

variable "command" {
type = list(string)
default = null
description = "Override the default command"
type = list(string)
default = null
}

variable "ports" {
type = list(any)
description = "Expose ports"
type = list(object({
internal = number
external = number
protocol = string
}))
default = null
}

variable "named_volumes" {
type = map(any)
description = "Mount named volumes"
type = map(object({
container_path = string
read_only = bool
create = bool
}))
default = {}
}

variable "host_paths" {
type = map(any)
description = "Mount host paths"
type = map(object({
container_path = string
read_only = bool
}))
default = {}
}

variable "volumes_from_containers" {
description = "Mount volumes from another container"
type = list(any)
default = null
}
variable "devices" {
type = map(any)
description = "Device mappings"
type = map(object({
container_path = string
permissions = string
}))
default = {}
}

variable "capabilities" {
type = map(any)
default = {}
}

variable "environment" {
type = map(string)
description = "Add or drop container capabilities"
type = object({
add = list(string)
drop = list(string)
})
default = null
}

variable "networks_advanced" {
type = list(any)
default = []
description = <<EOD
Advanced network options for the container
```hcl
networks_advanced = [
{
name = "proxy-tier"
ipv4_address = "10.0.0.14"
},
{
name = "media-tier"
ipv4_address = "172.0.0.14"
}
]
```
EOD
type = any
default = null
}
variable "healthcheck" {
description = "Test to check if container is healthy"
type = object({
interval = string
retries = number
start_period = string
test = list(string)
timeout = string
})
default = null
}
variable "environment" {
description = "Add environment variables"
type = map(string)
default = null
}

variable "docker_networks" {
type = list(any)
default = []
description = <<EOD
List of custom networks to create
```hcl
docker_networks = [
{
name = "proxy-tier"
ipam_config = {
aux_address = {}
gateway = "10.0.0.1"
subnet = "10.0.0.0/24"
}
}
]
```
EOD
type = any
default = []
}
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,5 @@ docker_networks = [
```
EOD
type = any
default = null
default = []
}

0 comments on commit 1bb3109

Please sign in to comment.