diff --git a/README.md b/README.md index 5806c64..feda154 100644 --- a/README.md +++ b/README.md @@ -74,29 +74,30 @@ However, you have to be consistent across variables, you cannot mix styles. ## Inputs -| Name | Description | Type | Default | Required | -| ------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | -------------------------------------------------------------------------------------------------------------- | :------: | -| annotations | Map of annotations to add on containers. | `map(string)` | `{}` | no | -| args | Arguments to pass to the container | `any` | `{}` | no | -| command | Command that the container will run | `any` | `{}` | no | -| environment\_variables | Map of environment variables to inject in containers. | `any` | `{}` | no | -| environment\_variables\_from\_secret | Map of environment variables to inject in containers, from existing secrets. | `any` | `{}` | no | -| hpa | settings for the horizontal pod autoscaler | `any` |
{
"enabled": false,
"max_replicas": 6,
"min_replicas": 2,
"target_cpu": 80
}
| no | -| image | The image to deploy. | `any` | n/a | yes | -| image\_pull\_secrets | List of image pull secrets to use with the containers | `list(string)` | `[]` | no | -| inject\_linkerd | Add the necessary annotations for linkerd injection | `bool` | `false` | no | -| liveness\_probes | Map of liveness probes per container. Pass the regular terraform object as is : https://www.terraform.io/docs/providers/kubernetes/r/deployment.html#liveness_probe-1 | `any` | n/a | yes | -| name | The name of the deployment. Will be used for all other resources | `string` | n/a | yes | -| namespace | The namespace where this deployment will live. Must exists. | `string` | n/a | yes | -| node\_selector | Map of labels and values for node selection | `map(string)` | `{}` | no | -| ports | Map of ports to expose, and associated settings. | `any` | `{}` | no | -| readiness\_probes | Map of readiness probes per container. Pass the regular terraform object as is : https://www.terraform.io/docs/providers/kubernetes/r/deployment.html#readiness_probe-1 | `any` | n/a | yes | -| replicas | Amount of replicas | `number` | `1` | no | -| resources\_limits | Map of resources limits to assign to the container | `map` |
{
"cpu": "0.2",
"memory": "256Mi"
}
| no | -| resources\_requests | Map of resources requests to assign to the container | `map` |
{
"cpu": "0.1",
"memory": "128Mi"
}
| no | -| volume\_mounts | Map of volumes to mount. | `any` | `{}` | no | -| volumes\_mounts\_from\_config\_map | Map of volumes to mount from config maps. | `any` | `{}` | no | -| volumes\_mounts\_from\_secret | Map of volumes to mount from secrets. | `any` | `{}` | no | +| Name | Description | Type | Default | Required | +| ------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- | -------------------------------------------------------------------------------------------------------------- | :------: | +| annotations | Map of annotations to add on containers. | `map(string)` | `{}` | no | +| args | Arguments to pass to the container | `any` | `{}` | no | +| command | Command that the container will run | `any` | `{}` | no | +| environment\_variables | Map of environment variables to inject in containers. | `any` | `{}` | no | +| environment\_variables\_from\_secret | Map of environment variables to inject in containers, from existing secrets. | `any` | `{}` | no | +| host\_aliases | Host aliases to set up in the pod. | `map(list(string))` | `{}` | no | +| hpa | settings for the horizontal pod autoscaler | `any` |
{
"enabled": false,
"max_replicas": 6,
"min_replicas": 2,
"target_cpu": 80
}
| no | +| image | The image to deploy. | `any` | n/a | yes | +| image\_pull\_secrets | List of image pull secrets to use with the containers | `list(string)` | `[]` | no | +| inject\_linkerd | Add the necessary annotations for linkerd injection | `bool` | `false` | no | +| liveness\_probes | Map of liveness probes per container. Pass the regular terraform object as is : https://www.terraform.io/docs/providers/kubernetes/r/deployment.html#liveness_probe-1 | `any` | n/a | yes | +| name | The name of the deployment. Will be used for all other resources | `string` | n/a | yes | +| namespace | The namespace where this deployment will live. Must exists. | `string` | n/a | yes | +| node\_selector | Map of labels and values for node selection | `map(string)` | `{}` | no | +| ports | Map of ports to expose, and associated settings. | `any` | `{}` | no | +| readiness\_probes | Map of readiness probes per container. Pass the regular terraform object as is : https://www.terraform.io/docs/providers/kubernetes/r/deployment.html#readiness_probe-1 | `any` | n/a | yes | +| replicas | Amount of replicas | `number` | `1` | no | +| resources\_limits | Map of resources limits to assign to the container | `map` |
{
"cpu": "0.2",
"memory": "256Mi"
}
| no | +| resources\_requests | Map of resources requests to assign to the container | `map` |
{
"cpu": "0.1",
"memory": "128Mi"
}
| no | +| volume\_mounts | Map of volumes to mount. | `any` | `{}` | no | +| volumes\_mounts\_from\_config\_map | Map of volumes to mount from config maps. | `any` | `{}` | no | +| volumes\_mounts\_from\_secret | Map of volumes to mount from secrets. | `any` | `{}` | no | ## Example values @@ -259,6 +260,16 @@ annotations = { } ``` +### Host aliases + +A map `{string = list(string)}` defining host aliases to set up in the pod. +```hcl +host_aliases = { + "127.0.0.1" = ["foo.bar"], + "127.0.0.128" = ["bar.baz", "baz.qux"] +} +``` + ## Terraform plan output with the example values diff --git a/deployment.tf b/deployment.tf index d1aa573..cbb67f8 100644 --- a/deployment.tf +++ b/deployment.tf @@ -26,6 +26,13 @@ resource "kubernetes_deployment" "container" { } spec { + dynamic "host_aliases" { + for_each = var.host_aliases + content { + hostnames = host_aliases.value + ip = host_aliases.key + } + } automount_service_account_token = true diff --git a/doc.tfvars b/doc.tfvars index 15e875b..689f048 100644 --- a/doc.tfvars +++ b/doc.tfvars @@ -42,6 +42,11 @@ annotations = { "bar" = "baz" } +host_aliases = { + "127.0.0.1" = ["foo.bar"], + "8.8.8.8" = ["bar.baz", "baz.qux"] +} + environment_variables_from_secret = { "container-a" = { "FOO_SECRET" = { diff --git a/test/terraform_apply_destroy_test.go b/test/terraform_apply_destroy_test.go index b230de2..1534e73 100644 --- a/test/terraform_apply_destroy_test.go +++ b/test/terraform_apply_destroy_test.go @@ -89,7 +89,7 @@ func TestApplyAndDestroyWithDefaultValues(t *testing.T) { pod := pods[0] container := pod.Spec.Containers[0] - assert.Equal(t,len(pods),2) + assert.Equal(t, len(pods), 2) assert.Equal(t, "training/webapp:latest", container.Image) assert.NotContains(t, pod.ObjectMeta.Annotations, "linkerd.io/inject") assert.Contains(t, pod.ObjectMeta.Annotations, "foo") @@ -135,6 +135,10 @@ func TestApplyAndDestroyWithSingleContainer(t *testing.T) { options.Vars["image_pull_secrets"] = []string{"'my-secret'", "'my-other-secret'"} + options.Vars["host_aliases"] = map[string]interface{}{ + "127.0.0.1": []string{"foo.bar", "bar.baz"}, + } + options.Vars["liveness_probes"] = map[string]interface{}{ "tcp_socket": map[string]interface{}{ "port": 5000, @@ -176,12 +180,14 @@ func TestApplyAndDestroyWithSingleContainer(t *testing.T) { pod := pods[0] container := pod.Spec.Containers[0] - assert.Equal(t,len(pods),1) + assert.Equal(t, len(pods), 1) assert.Equal(t, "training/webapp:latest", container.Image) assert.Contains(t, pod.ObjectMeta.Annotations, "linkerd.io/inject") assert.Contains(t, pod.ObjectMeta.Annotations, "foo") assert.Contains(t, pod.ObjectMeta.Annotations, "bar") assert.Equal(t, "bar", pod.ObjectMeta.Annotations["foo"]) + assert.EqualValues(t, "127.0.0.1", pod.Spec.HostAliases[0].IP) + assert.EqualValues(t, []string{"foo.bar", "bar.baz"}, pod.Spec.HostAliases[0].Hostnames) assert.Equal(t, "enabled", pod.ObjectMeta.Annotations["linkerd.io/inject"]) } diff --git a/variables.tf b/variables.tf index bb6388d..93e1939 100644 --- a/variables.tf +++ b/variables.tf @@ -25,6 +25,11 @@ variable "inject_linkerd" { description = "Add the necessary annotations for linkerd injection" } +variable "host_aliases" { + type = map(list(string)) + default = {} +} + variable "args" { type = any description = "Arguments to pass to the container"