diff --git a/README.md b/README.md index 466b992..5806c64 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ However, you have to be consistent across variables, you cannot mix styles. | 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 | diff --git a/deployment.tf b/deployment.tf index c55452b..d1aa573 100644 --- a/deployment.tf +++ b/deployment.tf @@ -15,6 +15,8 @@ resource "kubernetes_deployment" "container" { } } + replicas = var.replicas + template { metadata { labels = { diff --git a/test/terraform_apply_destroy_test.go b/test/terraform_apply_destroy_test.go index e445ea9..b230de2 100644 --- a/test/terraform_apply_destroy_test.go +++ b/test/terraform_apply_destroy_test.go @@ -51,6 +51,7 @@ func TestApplyAndDestroyWithDefaultValues(t *testing.T) { k8s.KubectlApply(t, k8sOptions, kubeResourcePath) options.Vars["image"] = map[string]interface{}{"test-container": "training/webapp:latest"} + options.Vars["replicas"] = 2 options.Vars["annotations"] = map[string]interface{}{"foo": "bar"} options.Vars["ports"] = map[string]interface{}{ @@ -83,9 +84,12 @@ func TestApplyAndDestroyWithDefaultValues(t *testing.T) { _, err = terraform.InitAndApplyE(t, options) assert.NoError(t, err) - pod := k8s.ListPods(t, k8sOptions, metav1.ListOptions{LabelSelector: "app=test-name"})[0] + pods := k8s.ListPods(t, k8sOptions, metav1.ListOptions{LabelSelector: "app=test-name"}) + + pod := pods[0] container := pod.Spec.Containers[0] + 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") @@ -167,9 +171,12 @@ func TestApplyAndDestroyWithSingleContainer(t *testing.T) { _, err = terraform.InitAndApplyE(t, options) assert.NoError(t, err) - pod := k8s.ListPods(t, k8sOptions, metav1.ListOptions{LabelSelector: "app=test-name"})[0] + pods := k8s.ListPods(t, k8sOptions, metav1.ListOptions{LabelSelector: "app=test-name"}) + + pod := pods[0] container := pod.Spec.Containers[0] + 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") diff --git a/variables.tf b/variables.tf index 59f3416..bb6388d 100644 --- a/variables.tf +++ b/variables.tf @@ -13,6 +13,12 @@ variable "image" { description = "The image to deploy." } +variable "replicas" { + type = number + default = 1 + description = "The number of replicas." +} + variable "inject_linkerd" { type = bool default = false