From a5fe4c4393b6059c6081147ee5ccc412c2bec05d Mon Sep 17 00:00:00 2001 From: Neil Peterson Date: Sun, 24 Mar 2019 10:20:40 -0700 Subject: [PATCH 01/15] Added probes --- azurerm/resource_arm_container_group.go | 283 ++++++++++++++++++++++++ 1 file changed, 283 insertions(+) diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index da4dcde03d19..2dacb555f750 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -307,6 +307,154 @@ func resourceArmContainerGroup() *schema.Resource { }, }, }, + + "liveness_probe": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "exec": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + + "httpget": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "path": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "port": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + "scheme": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + string(containerinstance.HTTP), + string(containerinstance.HTTPS), + }, true), + }, + }, + }, + }, + + "inital_delay_seconds": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + + "period_seconds": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + + "failure_threashold": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + + "sucess_threashold": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + + "timeout_seconds": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + }, + }, + }, + + "readiness_probe": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "exec": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + + "httpget": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "path": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "port": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + "scheme": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + }, + }, + }, + + "inital_delay_seconds": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + + "period_seconds": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + + "failure_threashold": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + + "sucess_threashold": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + + "timeout_seconds": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + }, + }, + }, }, }, }, @@ -661,6 +809,16 @@ func expandContainerGroupContainers(d *schema.ResourceData) (*[]containerinstanc } } + if v, ok := data["liveness_probe"]; ok { + livenessProbe := expandContainerProbe(v) + container.ContainerProperties.LivenessProbe = livenessProbe + } + + if v, ok := data["readiness_probe"]; ok { + readinessProbe := expandContainerProbe(v) + container.ContainerProperties.ReadinessProbe = readinessProbe + } + containers = append(containers, container) } @@ -762,6 +920,73 @@ func expandContainerVolumes(input interface{}) (*[]containerinstance.VolumeMount return &volumeMounts, &containerGroupVolumes } +func expandContainerProbe(input interface{}) *containerinstance.ContainerProbe { + probe := containerinstance.ContainerProbe{} + probeRaw := input.([]interface{}) + + if len(probeRaw) == 0 { + return nil + } + + for _, p := range probeRaw { + probeConfig := p.(map[string]interface{}) + + if initialDelaySeconds := probeConfig["inital_delay_seconds"].(int); initialDelaySeconds > 0 { + probe.InitialDelaySeconds = utils.Int32(int32(initialDelaySeconds)) + } + + if periodSeconds := probeConfig["period_seconds"].(int); periodSeconds > 0 { + probe.PeriodSeconds = utils.Int32(int32(periodSeconds)) + } + + if failureThreshold := probeConfig["failure_threashold"].(int); failureThreshold > 0 { + probe.FailureThreshold = utils.Int32(int32(failureThreshold)) + } + + if successThreshold := probeConfig["sucess_threashold"].(int); successThreshold > 0 { + probe.SuccessThreshold = utils.Int32(int32(successThreshold)) + } + + if timeoutSeconds := probeConfig["timeout_seconds"].(int); timeoutSeconds > 0 { + probe.TimeoutSeconds = utils.Int32(int32(timeoutSeconds)) + } + + commands := probeConfig["exec"].([]interface{}) + if len(commands) > 0 { + execRaw := make([]string, 0, len(commands)) + + for _, command := range commands { + execRaw = append(execRaw, command.(string)) + } + + exec := containerinstance.ContainerExec{ + Command: &execRaw, + } + probe.Exec = &exec + } + + httpRaw := probeConfig["httpget"].([]interface{}) + if len(httpRaw) > 0 { + + for _, httpget := range httpRaw { + x := httpget.(map[string]interface{}) + + path := x["path"].(string) + port := x["port"].(int) + scheme := x["scheme"].(string) + + ContainerHTTPGet := containerinstance.ContainerHTTPGet{ + Path: utils.String(string(path)), + Port: utils.Int32(int32(port)), + Scheme: containerinstance.Scheme(scheme), + } + probe.HTTPGet = &ContainerHTTPGet + } + } + } + return &probe +} + func flattenContainerImageRegistryCredentials(d *schema.ResourceData, input *[]containerinstance.ImageRegistryCredential) []interface{} { if input == nil { return nil @@ -907,6 +1132,14 @@ func flattenContainerGroupContainers(d *schema.ResourceData, containers *[]conta containerConfig["volume"] = flattenContainerVolumes(container.VolumeMounts, containerGroupVolumes, containerVolumesConfig) } + if container.LivenessProbe != nil { + containerConfig["liveness_probe"] = flattenContainerProbes(container.LivenessProbe) + } + + if container.ReadinessProbe != nil { + containerConfig["readiness_probe"] = flattenContainerProbes(container.ReadinessProbe) + } + containerCfg = append(containerCfg, containerConfig) } @@ -1002,6 +1235,56 @@ func flattenContainerVolumes(volumeMounts *[]containerinstance.VolumeMount, cont return volumeConfigs } +func flattenContainerProbes(input *containerinstance.ContainerProbe) []interface{} { + outputs := make([]interface{}, 0) + if input == nil { + return outputs + } + + output := make(map[string]interface{}) + + if Exec := input.Exec; Exec != nil { + var exec []string + for _, v := range *input.Exec.Command { + exec = append(exec, v) + } + output["exec"] = exec + } + + if HTTPGet := input.HTTPGet; HTTPGet != nil { + httpget := make(map[string]interface{}) + httpget["path"] = *input.HTTPGet.Path + httpget["port"] = *input.HTTPGet.Port + httpget["scheme"] = input.HTTPGet.Scheme + + output["httpget"] = []interface{}{httpget} + + } + + if FailureThreshold := input.FailureThreshold; FailureThreshold != nil { + output["failure_threashold"] = input.FailureThreshold + } + + if InitialDelaySeconds := input.InitialDelaySeconds; InitialDelaySeconds != nil { + output["inital_delay_seconds"] = input.InitialDelaySeconds + } + + if PeriodSeconds := input.PeriodSeconds; PeriodSeconds != nil { + output["period_seconds"] = input.PeriodSeconds + } + + if SuccessThreshold := input.SuccessThreshold; SuccessThreshold != nil { + output["sucess_threashold"] = input.SuccessThreshold + } + + if TimeoutSeconds := input.TimeoutSeconds; TimeoutSeconds != nil { + output["timeout_seconds"] = input.TimeoutSeconds + } + + outputs = append(outputs, output) + return outputs +} + func expandContainerGroupDiagnostics(input []interface{}) *containerinstance.ContainerGroupDiagnostics { if len(input) == 0 { return nil From fecffef47325a5dd5f47369b5a8a37c3b72be32d Mon Sep 17 00:00:00 2001 From: Neil Peterson Date: Sun, 24 Mar 2019 19:14:12 -0700 Subject: [PATCH 02/15] Added test and docs --- azurerm/resource_arm_container_group_test.go | 92 +++++++++++++++++++- website/docs/r/container_group.html.markdown | 58 ++++++++++++ 2 files changed, 146 insertions(+), 4 deletions(-) diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index 3e189e649e60..3186096da0f0 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -225,6 +225,26 @@ func TestAccAzureRMContainerGroup_linuxComplete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "diagnostics.0.log_analytics.0.metadata.%", "1"), resource.TestCheckResourceAttrSet(resourceName, "diagnostics.0.log_analytics.0.workspace_id"), resource.TestCheckResourceAttrSet(resourceName, "diagnostics.0.log_analytics.0.workspace_key"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.#", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.#", "2"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.0", "cat"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.1", "/tmp/healthy"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.httpget.#", "0"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.inital_delay_seconds", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.period_seconds", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.failure_threashold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.sucess_threashold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.timeout_seconds", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.#", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.failure_threashold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.#", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.path", "/"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.port", "443"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.scheme", "Http"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.inital_delay_seconds", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.period_seconds", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.sucess_threashold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.timeout_seconds", "1"), ), }, { @@ -307,6 +327,26 @@ func TestAccAzureRMContainerGroup_windowsComplete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "diagnostics.0.log_analytics.0.metadata.%", "1"), resource.TestCheckResourceAttrSet(resourceName, "diagnostics.0.log_analytics.0.workspace_id"), resource.TestCheckResourceAttrSet(resourceName, "diagnostics.0.log_analytics.0.workspace_key"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.#", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.#", "2"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.0", "cat"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.1", "/tmp/healthy"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.httpget.#", "0"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.inital_delay_seconds", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.period_seconds", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.failure_threashold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.sucess_threashold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.timeout_seconds", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.#", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.failure_threashold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.#", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.path", "/"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.port", "443"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.scheme", "Http"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.inital_delay_seconds", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.period_seconds", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.sucess_threashold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.timeout_seconds", "1"), ), }, { @@ -605,7 +645,29 @@ resource "azurerm_container_group" "test" { secure_environment_variables = { "secureFoo" = "secureBar" "secureFoo1" = "secureBar1" - } + } + + readiness_probe { + exec = ["cat","/tmp/healthy"] + inital_delay_seconds = 1 + period_seconds = 1 + failure_threashold = 1 + sucess_threashold = 1 + timeout_seconds = 1 + } + + liveness_probe { + httpget { + path = "/" + port = 443 + scheme = "Http" + } + inital_delay_seconds = 1 + period_seconds = 1 + failure_threashold = 1 + sucess_threashold = 1 + timeout_seconds = 1 + } commands = ["cmd.exe", "echo", "hi"] } @@ -619,7 +681,7 @@ resource "azurerm_container_group" "test" { "node-name" = "acctestContainerGroup" } } - } + } tags = { environment = "Testing" @@ -715,7 +777,29 @@ resource "azurerm_container_group" "test" { secure_environment_variables = { "secureFoo" = "secureBar" "secureFoo1" = "secureBar1" - } + } + + readiness_probe { + exec = ["cat","/tmp/healthy"] + inital_delay_seconds = 1 + period_seconds = 1 + failure_threashold = 1 + sucess_threashold = 1 + timeout_seconds = 1 + } + + liveness_probe { + httpget { + path = "/" + port = 443 + scheme = "Http" + } + inital_delay_seconds = 1 + period_seconds = 1 + failure_threashold = 1 + sucess_threashold = 1 + timeout_seconds = 1 + } commands = ["/bin/bash", "-c", "ls"] } @@ -729,7 +813,7 @@ resource "azurerm_container_group" "test" { "node-name" = "acctestContainerGroup" } } - } + } tags = { environment = "Testing" diff --git a/website/docs/r/container_group.html.markdown b/website/docs/r/container_group.html.markdown index 47af628745d9..e29860a530f5 100644 --- a/website/docs/r/container_group.html.markdown +++ b/website/docs/r/container_group.html.markdown @@ -66,6 +66,14 @@ resource "azurerm_container_group" "aci-helloworld" { "ACCESS_KEY" = "secure_testing" } + readiness_probe { + exec = ["/bin/sh","-c","touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600"] + } + + liveness_probe { + exec = ["cat", "/tmp/healthy"] + } + commands = ["/bin/bash", "-c", "'/path to/myscript.sh'"] volume { @@ -144,6 +152,10 @@ A `container` block supports: * `secure_environment_variables` - (Optional) A list of sensitive environment variables to be set on the container. Specified as a map of name/value pairs. Changing this forces a new resource to be created. +* `readiness_probe` - (Optional) The definition of a readiness probe for this container as documented in the `readiness_probe` block below. Changing this forces a new resource to be created. + +* `liveness_probe` - (Optional) The definition of a readiness probe for this container as documented in the `liveness_probe` block below. Changing this forces a new resource to be created. + * `command` - (Optional) A command line to be run on the container. ~> **NOTE:** The field `command` has been deprecated in favor of `commands` to better match the API. @@ -212,6 +224,52 @@ A `volume` block supports: * `share_name` - (Required) The Azure storage share that is to be mounted as a volume. This must be created on the storage account specified as above. Changing this forces a new resource to be created. +--- + +The `readiness_probe` block supports: + +* `exec` - (Optional) Commands to be run to validate container readiness. Changing this forces a new resource to be created. + +* `httpget` - (Optional) The definition of the httpget for this container as documented in the `httpget` block below. Changing this forces a new resource to be created. + +* `inital_delay_seconds` - (Optional) Number of seconds after the container has started before liveness or readiness probes are initiated. Changing this forces a new resource to be created. + +* `period_seconds` - (Optional) How often (in seconds) to perform the probe Changing this forces a new resource to be created. + +* `failure_threashold` - (Optional) How many times to try the probe before restarting the container (liveness probe) or marking the container as unhealthy (readiness probe). Changing this forces a new resource to be created. + +* `sucess_threashold` - (Optional) Minimum consecutive successes for the probe to be considered successful after having failed. Changing this forces a new resource to be created. + +* `timeout_seconds` - (Optional) Number of seconds after which the probe times out. Changing this forces a new resource to be created. + +--- + +The `liveness_probe` block supports: + +* `exec` - (Optional) Commands to be run to validate container readiness. Changing this forces a new resource to be created. + +* `httpget` - (Optional) The definition of the httpget for this container as documented in the `httpget` block below. Changing this forces a new resource to be created. + +* `inital_delay_seconds` - (Optional) Number of seconds after the container has started before liveness or readiness probes are initiated. Changing this forces a new resource to be created. + +* `period_seconds` - (Optional) How often (in seconds) to perform the probe Changing this forces a new resource to be created. + +* `failure_threashold` - (Optional) How many times to try the probe before restarting the container (liveness probe) or marking the container as unhealthy (readiness probe). Changing this forces a new resource to be created. + +* `sucess_threashold` - (Optional) Minimum consecutive successes for the probe to be considered successful after having failed. Changing this forces a new resource to be created. + +* `timeout_seconds` - (Optional) Number of seconds after which the probe times out. Changing this forces a new resource to be created. + +--- + +The `httpget` block supports: + +* `path` - (Optional) Path to access on the HTTP server. Changing this forces a new resource to be created. + +* `port` - (Optional) Number of the port to access on the container. Changing this forces a new resource to be created. + +* `scheme` - (Optional) Scheme to use for connecting to the host. Possible values are `HTTP` & `HTTPS`. Changing this forces a new resource to be created. + ## Attributes Reference The following attributes are exported: From a6ed85517def05182513be97c9e6051ba762aff5 Mon Sep 17 00:00:00 2001 From: Neil Peterson Date: Mon, 25 Mar 2019 13:12:54 -0700 Subject: [PATCH 03/15] Fixed linting issue and test feedback --- azurerm/resource_arm_container_group.go | 8 +- azurerm/resource_arm_container_group_test.go | 84 ++++++++++---------- 2 files changed, 44 insertions(+), 48 deletions(-) diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index 2dacb555f750..068289587f68 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -976,7 +976,7 @@ func expandContainerProbe(input interface{}) *containerinstance.ContainerProbe { scheme := x["scheme"].(string) ContainerHTTPGet := containerinstance.ContainerHTTPGet{ - Path: utils.String(string(path)), + Path: utils.String(path), Port: utils.Int32(int32(port)), Scheme: containerinstance.Scheme(scheme), } @@ -1244,11 +1244,7 @@ func flattenContainerProbes(input *containerinstance.ContainerProbe) []interface output := make(map[string]interface{}) if Exec := input.Exec; Exec != nil { - var exec []string - for _, v := range *input.Exec.Command { - exec = append(exec, v) - } - output["exec"] = exec + output["exec"] = *input.Exec.Command } if HTTPGet := input.HTTPGet; HTTPGet != nil { diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index 3186096da0f0..64aaf0b07e89 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -645,29 +645,29 @@ resource "azurerm_container_group" "test" { secure_environment_variables = { "secureFoo" = "secureBar" "secureFoo1" = "secureBar1" - } + } - readiness_probe { - exec = ["cat","/tmp/healthy"] - inital_delay_seconds = 1 - period_seconds = 1 - failure_threashold = 1 - sucess_threashold = 1 - timeout_seconds = 1 - } + readiness_probe { + exec = ["cat","/tmp/healthy"] + inital_delay_seconds = 1 + period_seconds = 1 + failure_threashold = 1 + sucess_threashold = 1 + timeout_seconds = 1 + } - liveness_probe { - httpget { - path = "/" - port = 443 - scheme = "Http" - } - inital_delay_seconds = 1 - period_seconds = 1 - failure_threashold = 1 - sucess_threashold = 1 - timeout_seconds = 1 - } + liveness_probe { + httpget { + path = "/" + port = 443 + scheme = "Http" + } + inital_delay_seconds = 1 + period_seconds = 1 + failure_threashold = 1 + sucess_threashold = 1 + timeout_seconds = 1 + } commands = ["cmd.exe", "echo", "hi"] } @@ -779,27 +779,27 @@ resource "azurerm_container_group" "test" { "secureFoo1" = "secureBar1" } - readiness_probe { - exec = ["cat","/tmp/healthy"] - inital_delay_seconds = 1 - period_seconds = 1 - failure_threashold = 1 - sucess_threashold = 1 - timeout_seconds = 1 - } + readiness_probe { + exec = ["cat","/tmp/healthy"] + inital_delay_seconds = 1 + period_seconds = 1 + failure_threashold = 1 + sucess_threashold = 1 + timeout_seconds = 1 + } - liveness_probe { - httpget { - path = "/" - port = 443 - scheme = "Http" - } - inital_delay_seconds = 1 - period_seconds = 1 - failure_threashold = 1 - sucess_threashold = 1 - timeout_seconds = 1 - } + liveness_probe { + httpget { + path = "/" + port = 443 + scheme = "Http" + } + inital_delay_seconds = 1 + period_seconds = 1 + failure_threashold = 1 + sucess_threashold = 1 + timeout_seconds = 1 + } commands = ["/bin/bash", "-c", "ls"] } @@ -813,7 +813,7 @@ resource "azurerm_container_group" "test" { "node-name" = "acctestContainerGroup" } } - } + } tags = { environment = "Testing" From 360fedae4985782dd95d1bf4e6661ac133998f8a Mon Sep 17 00:00:00 2001 From: Neil Peterson Date: Mon, 25 Mar 2019 17:33:41 -0700 Subject: [PATCH 04/15] Added validation, nil check, and style updates --- azurerm/resource_arm_container_group.go | 194 +++++++++++-------- website/docs/r/container_group.html.markdown | 16 +- 2 files changed, 123 insertions(+), 87 deletions(-) diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index 068289587f68..8b614db4d648 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -319,7 +319,10 @@ func resourceArmContainerGroup() *schema.Resource { Type: schema.TypeList, Optional: true, ForceNew: true, - Elem: &schema.Schema{Type: schema.TypeString}, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, + }, }, "httpget": { @@ -329,14 +332,16 @@ func resourceArmContainerGroup() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "path": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, }, "port": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + ValidateFunc: validate.PortNumber, }, "scheme": { Type: schema.TypeString, @@ -352,33 +357,43 @@ func resourceArmContainerGroup() *schema.Resource { }, "inital_delay_seconds": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Default: 0, + ValidateFunc: validation.NoZeroValues, }, "period_seconds": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Default: 10, + ValidateFunc: validation.IntAtLeast(1), }, "failure_threashold": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Default: 3, + ValidateFunc: validation.IntAtLeast(1), }, "sucess_threashold": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Default: 1, + ValidateFunc: validation.IntAtLeast(1), }, "timeout_seconds": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Default: 1, + ValidateFunc: validation.IntAtLeast(1), }, }, }, @@ -395,7 +410,10 @@ func resourceArmContainerGroup() *schema.Resource { Type: schema.TypeList, Optional: true, ForceNew: true, - Elem: &schema.Schema{Type: schema.TypeString}, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, + }, }, "httpget": { @@ -405,52 +423,68 @@ func resourceArmContainerGroup() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "path": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, }, "port": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + ValidateFunc: validate.PortNumber, }, "scheme": { Type: schema.TypeString, Optional: true, ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + string(containerinstance.HTTP), + string(containerinstance.HTTPS), + }, true), }, }, }, }, "inital_delay_seconds": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Default: 0, + ValidateFunc: validation.NoZeroValues, }, "period_seconds": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Default: 10, + ValidateFunc: validation.IntAtLeast(1), }, "failure_threashold": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Default: 3, + ValidateFunc: validation.IntAtLeast(1), }, "sucess_threashold": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Default: 1, + ValidateFunc: validation.IntAtLeast(1), }, "timeout_seconds": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + Default: 1, + ValidateFunc: validation.IntAtLeast(1), }, }, }, @@ -810,8 +844,7 @@ func expandContainerGroupContainers(d *schema.ResourceData) (*[]containerinstanc } if v, ok := data["liveness_probe"]; ok { - livenessProbe := expandContainerProbe(v) - container.ContainerProperties.LivenessProbe = livenessProbe + container.ContainerProperties.LivenessProbe = expandContainerProbe(v) } if v, ok := data["readiness_probe"]; ok { @@ -931,36 +964,30 @@ func expandContainerProbe(input interface{}) *containerinstance.ContainerProbe { for _, p := range probeRaw { probeConfig := p.(map[string]interface{}) - if initialDelaySeconds := probeConfig["inital_delay_seconds"].(int); initialDelaySeconds > 0 { - probe.InitialDelaySeconds = utils.Int32(int32(initialDelaySeconds)) + if v := probeConfig["inital_delay_seconds"].(int); v > 0 { + probe.InitialDelaySeconds = utils.Int32(int32(v)) } - if periodSeconds := probeConfig["period_seconds"].(int); periodSeconds > 0 { - probe.PeriodSeconds = utils.Int32(int32(periodSeconds)) + if v := probeConfig["period_seconds"].(int); v > 0 { + probe.PeriodSeconds = utils.Int32(int32(v)) } - if failureThreshold := probeConfig["failure_threashold"].(int); failureThreshold > 0 { - probe.FailureThreshold = utils.Int32(int32(failureThreshold)) + if v := probeConfig["failure_threashold"].(int); v > 0 { + probe.FailureThreshold = utils.Int32(int32(v)) } - if successThreshold := probeConfig["sucess_threashold"].(int); successThreshold > 0 { - probe.SuccessThreshold = utils.Int32(int32(successThreshold)) + if v := probeConfig["sucess_threashold"].(int); v > 0 { + probe.SuccessThreshold = utils.Int32(int32(v)) } - if timeoutSeconds := probeConfig["timeout_seconds"].(int); timeoutSeconds > 0 { - probe.TimeoutSeconds = utils.Int32(int32(timeoutSeconds)) + if v := probeConfig["timeout_seconds"].(int); v > 0 { + probe.TimeoutSeconds = utils.Int32(int32(v)) } commands := probeConfig["exec"].([]interface{}) if len(commands) > 0 { - execRaw := make([]string, 0, len(commands)) - - for _, command := range commands { - execRaw = append(execRaw, command.(string)) - } - exec := containerinstance.ContainerExec{ - Command: &execRaw, + Command: utils.ExpandStringArray(commands), } probe.Exec = &exec } @@ -1243,38 +1270,47 @@ func flattenContainerProbes(input *containerinstance.ContainerProbe) []interface output := make(map[string]interface{}) - if Exec := input.Exec; Exec != nil { - output["exec"] = *input.Exec.Command + if v := input.Exec; v != nil { + output["exec"] = *v.Command } - if HTTPGet := input.HTTPGet; HTTPGet != nil { + if v := input.HTTPGet; v != nil { httpget := make(map[string]interface{}) - httpget["path"] = *input.HTTPGet.Path - httpget["port"] = *input.HTTPGet.Port - httpget["scheme"] = input.HTTPGet.Scheme + + if v := input.HTTPGet.Path; v != nil { + httpget["path"] = *v + } + + if v := input.HTTPGet.Port; v != nil { + httpget["port"] = *v + } + + if v := string(input.HTTPGet.Scheme); &v != nil { + httpget["scheme"] = v + } output["httpget"] = []interface{}{httpget} } - if FailureThreshold := input.FailureThreshold; FailureThreshold != nil { - output["failure_threashold"] = input.FailureThreshold + if v := input.FailureThreshold; v != nil { + output["failure_threashold"] = *v } - if InitialDelaySeconds := input.InitialDelaySeconds; InitialDelaySeconds != nil { - output["inital_delay_seconds"] = input.InitialDelaySeconds + if v := input.InitialDelaySeconds; v != nil { + output["inital_delay_seconds"] = *v } - if PeriodSeconds := input.PeriodSeconds; PeriodSeconds != nil { - output["period_seconds"] = input.PeriodSeconds + if v := input.PeriodSeconds; v != nil { + output["period_seconds"] = *v } - if SuccessThreshold := input.SuccessThreshold; SuccessThreshold != nil { - output["sucess_threashold"] = input.SuccessThreshold + if v := input.SuccessThreshold; v != nil { + output["sucess_threashold"] = *v } - if TimeoutSeconds := input.TimeoutSeconds; TimeoutSeconds != nil { - output["timeout_seconds"] = input.TimeoutSeconds + if v := input.TimeoutSeconds; v != nil { + output["timeout_seconds"] = *v } outputs = append(outputs, output) diff --git a/website/docs/r/container_group.html.markdown b/website/docs/r/container_group.html.markdown index e29860a530f5..7f4cc63b8554 100644 --- a/website/docs/r/container_group.html.markdown +++ b/website/docs/r/container_group.html.markdown @@ -234,13 +234,13 @@ The `readiness_probe` block supports: * `inital_delay_seconds` - (Optional) Number of seconds after the container has started before liveness or readiness probes are initiated. Changing this forces a new resource to be created. -* `period_seconds` - (Optional) How often (in seconds) to perform the probe Changing this forces a new resource to be created. +* `period_seconds` - (Optional) How often (in seconds) to perform the probe. The default value is `10` and the minimum value is `1`. Changing this forces a new resource to be created. -* `failure_threashold` - (Optional) How many times to try the probe before restarting the container (liveness probe) or marking the container as unhealthy (readiness probe). Changing this forces a new resource to be created. +* `failure_threashold` - (Optional) How many times to try the probe before restarting the container (liveness probe) or marking the container as unhealthy (readiness probe). The default value is `3` and the minimum value is `1`. Changing this forces a new resource to be created. -* `sucess_threashold` - (Optional) Minimum consecutive successes for the probe to be considered successful after having failed. Changing this forces a new resource to be created. +* `sucess_threashold` - (Optional) Minimum consecutive successes for the probe to be considered successful after having failed. The default value is `1` and the minimum value is `1`. Changing this forces a new resource to be created. -* `timeout_seconds` - (Optional) Number of seconds after which the probe times out. Changing this forces a new resource to be created. +* `timeout_seconds` - (Optional) Number of seconds after which the probe times out. The default value is `1` and the minimum value is `1`. Changing this forces a new resource to be created. --- @@ -252,13 +252,13 @@ The `liveness_probe` block supports: * `inital_delay_seconds` - (Optional) Number of seconds after the container has started before liveness or readiness probes are initiated. Changing this forces a new resource to be created. -* `period_seconds` - (Optional) How often (in seconds) to perform the probe Changing this forces a new resource to be created. +* `period_seconds` - (Optional) How often (in seconds) to perform the probe. The default value is `10` and the minimum value is `1`. Changing this forces a new resource to be created. -* `failure_threashold` - (Optional) How many times to try the probe before restarting the container (liveness probe) or marking the container as unhealthy (readiness probe). Changing this forces a new resource to be created. +* `failure_threashold` - (Optional) How many times to try the probe before restarting the container (liveness probe) or marking the container as unhealthy (readiness probe). The default value is `3` and the minimum value is `1`. Changing this forces a new resource to be created. -* `sucess_threashold` - (Optional) Minimum consecutive successes for the probe to be considered successful after having failed. Changing this forces a new resource to be created. +* `sucess_threashold` - (Optional) Minimum consecutive successes for the probe to be considered successful after having failed. The default value is `1` and the minimum value is `1`. Changing this forces a new resource to be created. -* `timeout_seconds` - (Optional) Number of seconds after which the probe times out. Changing this forces a new resource to be created. +* `timeout_seconds` - (Optional) Number of seconds after which the probe times out. The default value is `1` and the minimum value is `1`. Changing this forces a new resource to be created. --- From f72c8628e0921f5cc339e9617666adce113db0f3 Mon Sep 17 00:00:00 2001 From: Neil Peterson Date: Mon, 25 Mar 2019 17:44:36 -0700 Subject: [PATCH 05/15] Linting issue: nilness: tautological condition: non-nil != nil --- azurerm/resource_arm_container_group.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index 8b614db4d648..ed17205ae4ba 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -1285,8 +1285,8 @@ func flattenContainerProbes(input *containerinstance.ContainerProbe) []interface httpget["port"] = *v } - if v := string(input.HTTPGet.Scheme); &v != nil { - httpget["scheme"] = v + if v := input.HTTPGet.Scheme; &v != nil { + httpget["scheme"] = string(v) } output["httpget"] = []interface{}{httpget} From 74fe7f367ddb1c2b372a8163ade5f71877e08998 Mon Sep 17 00:00:00 2001 From: Neil Peterson Date: Mon, 25 Mar 2019 22:24:05 -0700 Subject: [PATCH 06/15] Fixed linting issue --- azurerm/resource_arm_container_group.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index ed17205ae4ba..d6f5164d617f 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -1285,8 +1285,8 @@ func flattenContainerProbes(input *containerinstance.ContainerProbe) []interface httpget["port"] = *v } - if v := input.HTTPGet.Scheme; &v != nil { - httpget["scheme"] = string(v) + if input.HTTPGet.Scheme != "" { + httpget["scheme"] = input.HTTPGet.Scheme } output["httpget"] = []interface{}{httpget} From d0396508d727ad1265df0115960030d4404b8217 Mon Sep 17 00:00:00 2001 From: Neil Peterson Date: Wed, 27 Mar 2019 16:55:38 -0700 Subject: [PATCH 07/15] Added helper function for probe schema and removed property defaults --- azurerm/helpers/azure/container_group.go | 91 +++++++++++ azurerm/resource_arm_container_group.go | 184 +---------------------- 2 files changed, 94 insertions(+), 181 deletions(-) create mode 100644 azurerm/helpers/azure/container_group.go diff --git a/azurerm/helpers/azure/container_group.go b/azurerm/helpers/azure/container_group.go new file mode 100644 index 000000000000..722c29f3fb52 --- /dev/null +++ b/azurerm/helpers/azure/container_group.go @@ -0,0 +1,91 @@ +package azure + +import ( + "github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance" + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" +) + +func SchemaContainerGroupProbe() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeList, + Optional: true, + ForceNew: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "exec": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.NoZeroValues, + }, + }, + + "httpget": { + Type: schema.TypeList, + Optional: true, + ForceNew: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "path": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validate.NoEmptyStrings, + }, + "port": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + ValidateFunc: validate.PortNumber, + }, + "scheme": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringInSlice([]string{ + string(containerinstance.HTTP), + string(containerinstance.HTTPS), + }, true), + }, + }, + }, + }, + + "inital_delay_seconds": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + + "period_seconds": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + + "failure_threashold": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + + "sucess_threashold": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + + "timeout_seconds": { + Type: schema.TypeInt, + Optional: true, + ForceNew: true, + }, + }, + }, + } +} diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index d6f5164d617f..10b63b6a311d 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -12,7 +12,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" - + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" @@ -308,187 +308,9 @@ func resourceArmContainerGroup() *schema.Resource { }, }, - "liveness_probe": { - Type: schema.TypeList, - Optional: true, - ForceNew: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "exec": { - Type: schema.TypeList, - Optional: true, - ForceNew: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validation.NoZeroValues, - }, - }, - - "httpget": { - Type: schema.TypeList, - Optional: true, - ForceNew: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "path": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validate.NoEmptyStrings, - }, - "port": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - ValidateFunc: validate.PortNumber, - }, - "scheme": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{ - string(containerinstance.HTTP), - string(containerinstance.HTTPS), - }, true), - }, - }, - }, - }, - - "inital_delay_seconds": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - Default: 0, - ValidateFunc: validation.NoZeroValues, - }, - - "period_seconds": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - Default: 10, - ValidateFunc: validation.IntAtLeast(1), - }, - - "failure_threashold": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - Default: 3, - ValidateFunc: validation.IntAtLeast(1), - }, - - "sucess_threashold": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - Default: 1, - ValidateFunc: validation.IntAtLeast(1), - }, - - "timeout_seconds": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - Default: 1, - ValidateFunc: validation.IntAtLeast(1), - }, - }, - }, - }, + "liveness_probe": azure.SchemaContainerGroupProbe(), - "readiness_probe": { - Type: schema.TypeList, - Optional: true, - ForceNew: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "exec": { - Type: schema.TypeList, - Optional: true, - ForceNew: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validation.NoZeroValues, - }, - }, - - "httpget": { - Type: schema.TypeList, - Optional: true, - ForceNew: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "path": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validate.NoEmptyStrings, - }, - "port": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - ValidateFunc: validate.PortNumber, - }, - "scheme": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{ - string(containerinstance.HTTP), - string(containerinstance.HTTPS), - }, true), - }, - }, - }, - }, - - "inital_delay_seconds": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - Default: 0, - ValidateFunc: validation.NoZeroValues, - }, - - "period_seconds": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - Default: 10, - ValidateFunc: validation.IntAtLeast(1), - }, - - "failure_threashold": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - Default: 3, - ValidateFunc: validation.IntAtLeast(1), - }, - - "sucess_threashold": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - Default: 1, - ValidateFunc: validation.IntAtLeast(1), - }, - - "timeout_seconds": { - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - Default: 1, - ValidateFunc: validation.IntAtLeast(1), - }, - }, - }, - }, + "readiness_probe": azure.SchemaContainerGroupProbe(), }, }, }, From b74174e52a29530a084ee1673fe47af66cabf39e Mon Sep 17 00:00:00 2001 From: Neil Peterson Date: Wed, 27 Mar 2019 22:00:57 -0700 Subject: [PATCH 08/15] Removed tabs --- azurerm/resource_arm_container_group_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index 64aaf0b07e89..039d9796075b 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -681,7 +681,7 @@ resource "azurerm_container_group" "test" { "node-name" = "acctestContainerGroup" } } - } + } tags = { environment = "Testing" From dd684b34c34230bf42ffdf76316a068f60adc62e Mon Sep 17 00:00:00 2001 From: Neil Peterson Date: Sun, 31 Mar 2019 13:17:37 -0700 Subject: [PATCH 09/15] style upsates --- azurerm/resource_arm_container_group.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index 10b63b6a311d..7c75b2d5f39c 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -670,8 +670,7 @@ func expandContainerGroupContainers(d *schema.ResourceData) (*[]containerinstanc } if v, ok := data["readiness_probe"]; ok { - readinessProbe := expandContainerProbe(v) - container.ContainerProperties.ReadinessProbe = readinessProbe + container.ContainerProperties.ReadinessProbe = expandContainerProbe(v) } containers = append(containers, container) @@ -1096,19 +1095,19 @@ func flattenContainerProbes(input *containerinstance.ContainerProbe) []interface output["exec"] = *v.Command } - if v := input.HTTPGet; v != nil { + if get := input.HTTPGet; get != nil { httpget := make(map[string]interface{}) - if v := input.HTTPGet.Path; v != nil { + if v := get.Path; v != nil { httpget["path"] = *v } - if v := input.HTTPGet.Port; v != nil { + if v := get.Port; v != nil { httpget["port"] = *v } - if input.HTTPGet.Scheme != "" { - httpget["scheme"] = input.HTTPGet.Scheme + if get.Scheme != "" { + httpget["scheme"] = get.Scheme } output["httpget"] = []interface{}{httpget} From 3b0af291772927fb38bfa5af9a75ef5a29fff567 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 6 Apr 2019 09:50:22 +0200 Subject: [PATCH 10/15] r/container_group: fixing the casing of the Scheme --- azurerm/helpers/azure/container_group.go | 7 +++---- website/docs/r/container_group.html.markdown | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/azurerm/helpers/azure/container_group.go b/azurerm/helpers/azure/container_group.go index 722c29f3fb52..3b81ff8247bd 100644 --- a/azurerm/helpers/azure/container_group.go +++ b/azurerm/helpers/azure/container_group.go @@ -1,7 +1,6 @@ package azure import ( - "github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" @@ -48,9 +47,9 @@ func SchemaContainerGroupProbe() *schema.Schema { Optional: true, ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ - string(containerinstance.HTTP), - string(containerinstance.HTTPS), - }, true), + "Http", + "Https", + }, false), }, }, }, diff --git a/website/docs/r/container_group.html.markdown b/website/docs/r/container_group.html.markdown index 7f4cc63b8554..9c67da982045 100644 --- a/website/docs/r/container_group.html.markdown +++ b/website/docs/r/container_group.html.markdown @@ -268,7 +268,7 @@ The `httpget` block supports: * `port` - (Optional) Number of the port to access on the container. Changing this forces a new resource to be created. -* `scheme` - (Optional) Scheme to use for connecting to the host. Possible values are `HTTP` & `HTTPS`. Changing this forces a new resource to be created. +* `scheme` - (Optional) Scheme to use for connecting to the host. Possible values are `Http` and `Https`. Changing this forces a new resource to be created. ## Attributes Reference From 89fb75a31561a4062eb5f06903baf4af08a4be62 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 6 Apr 2019 09:51:46 +0200 Subject: [PATCH 11/15] r/container_group: fixing the whitespace of the test --- azurerm/resource_arm_container_group_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index 039d9796075b..7d9fb13cddc2 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -635,7 +635,7 @@ resource "azurerm_container_group" "test" { ports { port = 80 protocol = "TCP" - } + } environment_variables = { "foo" = "bar" @@ -770,14 +770,14 @@ resource "azurerm_container_group" "test" { } environment_variables = { - "foo" = "bar" + "foo" = "bar" "foo1" = "bar1" } secure_environment_variables = { "secureFoo" = "secureBar" "secureFoo1" = "secureBar1" - } + } readiness_probe { exec = ["cat","/tmp/healthy"] @@ -805,7 +805,7 @@ resource "azurerm_container_group" "test" { } diagnostics { - log_analytics { + log_analytics { workspace_id = "${azurerm_log_analytics_workspace.test.workspace_id}" workspace_key = "${azurerm_log_analytics_workspace.test.primary_shared_key}" log_type = "ContainerInsights" From 6b25fd9c92372c8b26a644f1896d27a200c18597 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 6 Apr 2019 09:53:07 +0200 Subject: [PATCH 12/15] r/container_group: fixing typo's --- azurerm/helpers/azure/container_group.go | 4 +-- azurerm/resource_arm_container_group.go | 8 ++--- azurerm/resource_arm_container_group_test.go | 32 ++++++++++---------- website/docs/r/container_group.html.markdown | 8 ++--- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/azurerm/helpers/azure/container_group.go b/azurerm/helpers/azure/container_group.go index 3b81ff8247bd..34cae446d3f6 100644 --- a/azurerm/helpers/azure/container_group.go +++ b/azurerm/helpers/azure/container_group.go @@ -67,13 +67,13 @@ func SchemaContainerGroupProbe() *schema.Schema { ForceNew: true, }, - "failure_threashold": { + "failure_threshold": { Type: schema.TypeInt, Optional: true, ForceNew: true, }, - "sucess_threashold": { + "success_threshold": { Type: schema.TypeInt, Optional: true, ForceNew: true, diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index 7c75b2d5f39c..826be064a0fc 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -793,11 +793,11 @@ func expandContainerProbe(input interface{}) *containerinstance.ContainerProbe { probe.PeriodSeconds = utils.Int32(int32(v)) } - if v := probeConfig["failure_threashold"].(int); v > 0 { + if v := probeConfig["failure_threshold"].(int); v > 0 { probe.FailureThreshold = utils.Int32(int32(v)) } - if v := probeConfig["sucess_threashold"].(int); v > 0 { + if v := probeConfig["success_threshold"].(int); v > 0 { probe.SuccessThreshold = utils.Int32(int32(v)) } @@ -1115,7 +1115,7 @@ func flattenContainerProbes(input *containerinstance.ContainerProbe) []interface } if v := input.FailureThreshold; v != nil { - output["failure_threashold"] = *v + output["failure_threshold"] = *v } if v := input.InitialDelaySeconds; v != nil { @@ -1127,7 +1127,7 @@ func flattenContainerProbes(input *containerinstance.ContainerProbe) []interface } if v := input.SuccessThreshold; v != nil { - output["sucess_threashold"] = *v + output["success_threshold"] = *v } if v := input.TimeoutSeconds; v != nil { diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index 7d9fb13cddc2..20e47d14df44 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -232,18 +232,18 @@ func TestAccAzureRMContainerGroup_linuxComplete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.httpget.#", "0"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.inital_delay_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.period_seconds", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.failure_threashold", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.sucess_threashold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.failure_threshold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.success_threshold", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.timeout_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.failure_threashold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.failure_threshold", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.#", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.path", "/"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.port", "443"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.scheme", "Http"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.inital_delay_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.period_seconds", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.sucess_threashold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.success_threshold", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.timeout_seconds", "1"), ), }, @@ -334,18 +334,18 @@ func TestAccAzureRMContainerGroup_windowsComplete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.httpget.#", "0"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.inital_delay_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.period_seconds", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.failure_threashold", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.sucess_threashold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.failure_threshold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.success_threshold", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.timeout_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.failure_threashold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.failure_threshold", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.#", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.path", "/"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.port", "443"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.scheme", "Http"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.inital_delay_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.period_seconds", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.sucess_threashold", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.success_threshold", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.timeout_seconds", "1"), ), }, @@ -651,8 +651,8 @@ resource "azurerm_container_group" "test" { exec = ["cat","/tmp/healthy"] inital_delay_seconds = 1 period_seconds = 1 - failure_threashold = 1 - sucess_threashold = 1 + failure_threshold = 1 + success_threshold = 1 timeout_seconds = 1 } @@ -664,8 +664,8 @@ resource "azurerm_container_group" "test" { } inital_delay_seconds = 1 period_seconds = 1 - failure_threashold = 1 - sucess_threashold = 1 + failure_threshold = 1 + success_threshold = 1 timeout_seconds = 1 } @@ -783,8 +783,8 @@ resource "azurerm_container_group" "test" { exec = ["cat","/tmp/healthy"] inital_delay_seconds = 1 period_seconds = 1 - failure_threashold = 1 - sucess_threashold = 1 + failure_threshold = 1 + success_threshold = 1 timeout_seconds = 1 } @@ -796,8 +796,8 @@ resource "azurerm_container_group" "test" { } inital_delay_seconds = 1 period_seconds = 1 - failure_threashold = 1 - sucess_threashold = 1 + failure_threshold = 1 + success_threshold = 1 timeout_seconds = 1 } diff --git a/website/docs/r/container_group.html.markdown b/website/docs/r/container_group.html.markdown index 9c67da982045..dc36bec4eefe 100644 --- a/website/docs/r/container_group.html.markdown +++ b/website/docs/r/container_group.html.markdown @@ -236,9 +236,9 @@ The `readiness_probe` block supports: * `period_seconds` - (Optional) How often (in seconds) to perform the probe. The default value is `10` and the minimum value is `1`. Changing this forces a new resource to be created. -* `failure_threashold` - (Optional) How many times to try the probe before restarting the container (liveness probe) or marking the container as unhealthy (readiness probe). The default value is `3` and the minimum value is `1`. Changing this forces a new resource to be created. +* `failure_threshold` - (Optional) How many times to try the probe before restarting the container (liveness probe) or marking the container as unhealthy (readiness probe). The default value is `3` and the minimum value is `1`. Changing this forces a new resource to be created. -* `sucess_threashold` - (Optional) Minimum consecutive successes for the probe to be considered successful after having failed. The default value is `1` and the minimum value is `1`. Changing this forces a new resource to be created. +* `success_threshold` - (Optional) Minimum consecutive successes for the probe to be considered successful after having failed. The default value is `1` and the minimum value is `1`. Changing this forces a new resource to be created. * `timeout_seconds` - (Optional) Number of seconds after which the probe times out. The default value is `1` and the minimum value is `1`. Changing this forces a new resource to be created. @@ -254,9 +254,9 @@ The `liveness_probe` block supports: * `period_seconds` - (Optional) How often (in seconds) to perform the probe. The default value is `10` and the minimum value is `1`. Changing this forces a new resource to be created. -* `failure_threashold` - (Optional) How many times to try the probe before restarting the container (liveness probe) or marking the container as unhealthy (readiness probe). The default value is `3` and the minimum value is `1`. Changing this forces a new resource to be created. +* `failure_threshold` - (Optional) How many times to try the probe before restarting the container (liveness probe) or marking the container as unhealthy (readiness probe). The default value is `3` and the minimum value is `1`. Changing this forces a new resource to be created. -* `sucess_threashold` - (Optional) Minimum consecutive successes for the probe to be considered successful after having failed. The default value is `1` and the minimum value is `1`. Changing this forces a new resource to be created. +* `success_threshold` - (Optional) Minimum consecutive successes for the probe to be considered successful after having failed. The default value is `1` and the minimum value is `1`. Changing this forces a new resource to be created. * `timeout_seconds` - (Optional) Number of seconds after which the probe times out. The default value is `1` and the minimum value is `1`. Changing this forces a new resource to be created. From 3e5b88a51829e459836f1fa7ed87cc536af22059 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 6 Apr 2019 09:56:39 +0200 Subject: [PATCH 13/15] r/container_group: `httpget` -> `http_get` --- azurerm/helpers/azure/container_group.go | 2 +- azurerm/resource_arm_container_group.go | 18 +++++++-------- azurerm/resource_arm_container_group_test.go | 24 ++++++++++---------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/azurerm/helpers/azure/container_group.go b/azurerm/helpers/azure/container_group.go index 34cae446d3f6..6013a9264419 100644 --- a/azurerm/helpers/azure/container_group.go +++ b/azurerm/helpers/azure/container_group.go @@ -24,7 +24,7 @@ func SchemaContainerGroupProbe() *schema.Schema { }, }, - "httpget": { + "http_get": { Type: schema.TypeList, Optional: true, ForceNew: true, diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index 826be064a0fc..0a084977b8ae 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -813,7 +813,7 @@ func expandContainerProbe(input interface{}) *containerinstance.ContainerProbe { probe.Exec = &exec } - httpRaw := probeConfig["httpget"].([]interface{}) + httpRaw := probeConfig["http_get"].([]interface{}) if len(httpRaw) > 0 { for _, httpget := range httpRaw { @@ -823,12 +823,11 @@ func expandContainerProbe(input interface{}) *containerinstance.ContainerProbe { port := x["port"].(int) scheme := x["scheme"].(string) - ContainerHTTPGet := containerinstance.ContainerHTTPGet{ + probe.HTTPGet = &containerinstance.ContainerHTTPGet{ Path: utils.String(path), Port: utils.Int32(int32(port)), Scheme: containerinstance.Scheme(scheme), } - probe.HTTPGet = &ContainerHTTPGet } } } @@ -1095,24 +1094,25 @@ func flattenContainerProbes(input *containerinstance.ContainerProbe) []interface output["exec"] = *v.Command } + httpGets := make([]interface{}, 0) if get := input.HTTPGet; get != nil { - httpget := make(map[string]interface{}) + httpGet := make(map[string]interface{}) if v := get.Path; v != nil { - httpget["path"] = *v + httpGet["path"] = *v } if v := get.Port; v != nil { - httpget["port"] = *v + httpGet["port"] = *v } if get.Scheme != "" { - httpget["scheme"] = get.Scheme + httpGet["scheme"] = get.Scheme } - output["httpget"] = []interface{}{httpget} - + httpGets = append(httpGets, httpGet) } + output["http_get"] = httpGets if v := input.FailureThreshold; v != nil { output["failure_threshold"] = *v diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index 20e47d14df44..85da227cc267 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -229,7 +229,7 @@ func TestAccAzureRMContainerGroup_linuxComplete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.#", "2"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.0", "cat"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.1", "/tmp/healthy"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.httpget.#", "0"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.http_get.#", "0"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.inital_delay_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.period_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.failure_threshold", "1"), @@ -237,10 +237,10 @@ func TestAccAzureRMContainerGroup_linuxComplete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.timeout_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.#", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.failure_threshold", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.path", "/"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.port", "443"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.scheme", "Http"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.#", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.path", "/"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.port", "443"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.scheme", "Http"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.inital_delay_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.period_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.success_threshold", "1"), @@ -331,7 +331,7 @@ func TestAccAzureRMContainerGroup_windowsComplete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.#", "2"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.0", "cat"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.1", "/tmp/healthy"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.httpget.#", "0"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.http_get.#", "0"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.inital_delay_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.period_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.failure_threshold", "1"), @@ -339,10 +339,10 @@ func TestAccAzureRMContainerGroup_windowsComplete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.timeout_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.#", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.failure_threshold", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.#", "1"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.path", "/"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.port", "443"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.httpget.0.scheme", "Http"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.#", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.path", "/"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.port", "443"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.scheme", "Http"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.inital_delay_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.period_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.success_threshold", "1"), @@ -657,7 +657,7 @@ resource "azurerm_container_group" "test" { } liveness_probe { - httpget { + http_get { path = "/" port = 443 scheme = "Http" @@ -789,7 +789,7 @@ resource "azurerm_container_group" "test" { } liveness_probe { - httpget { + http_get { path = "/" port = 443 scheme = "Http" From 11fb422a7c164bc6016b261dc0d087b310060e9d Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 6 Apr 2019 09:57:55 +0200 Subject: [PATCH 14/15] r/container_group: `inital` -> `initial` --- azurerm/helpers/azure/container_group.go | 2 +- azurerm/resource_arm_container_group.go | 4 ++-- azurerm/resource_arm_container_group_test.go | 16 ++++++++-------- website/docs/r/container_group.html.markdown | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/azurerm/helpers/azure/container_group.go b/azurerm/helpers/azure/container_group.go index 6013a9264419..ca59efbfc616 100644 --- a/azurerm/helpers/azure/container_group.go +++ b/azurerm/helpers/azure/container_group.go @@ -55,7 +55,7 @@ func SchemaContainerGroupProbe() *schema.Schema { }, }, - "inital_delay_seconds": { + "initial_delay_seconds": { Type: schema.TypeInt, Optional: true, ForceNew: true, diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index 0a084977b8ae..a2b3b1ce926e 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -785,7 +785,7 @@ func expandContainerProbe(input interface{}) *containerinstance.ContainerProbe { for _, p := range probeRaw { probeConfig := p.(map[string]interface{}) - if v := probeConfig["inital_delay_seconds"].(int); v > 0 { + if v := probeConfig["initial_delay_seconds"].(int); v > 0 { probe.InitialDelaySeconds = utils.Int32(int32(v)) } @@ -1119,7 +1119,7 @@ func flattenContainerProbes(input *containerinstance.ContainerProbe) []interface } if v := input.InitialDelaySeconds; v != nil { - output["inital_delay_seconds"] = *v + output["initial_delay_seconds"] = *v } if v := input.PeriodSeconds; v != nil { diff --git a/azurerm/resource_arm_container_group_test.go b/azurerm/resource_arm_container_group_test.go index 85da227cc267..4eb117868703 100644 --- a/azurerm/resource_arm_container_group_test.go +++ b/azurerm/resource_arm_container_group_test.go @@ -230,7 +230,7 @@ func TestAccAzureRMContainerGroup_linuxComplete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.0", "cat"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.1", "/tmp/healthy"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.http_get.#", "0"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.inital_delay_seconds", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.initial_delay_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.period_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.failure_threshold", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.success_threshold", "1"), @@ -241,7 +241,7 @@ func TestAccAzureRMContainerGroup_linuxComplete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.path", "/"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.port", "443"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.scheme", "Http"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.inital_delay_seconds", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.initial_delay_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.period_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.success_threshold", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.timeout_seconds", "1"), @@ -332,7 +332,7 @@ func TestAccAzureRMContainerGroup_windowsComplete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.0", "cat"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.exec.1", "/tmp/healthy"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.http_get.#", "0"), - resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.inital_delay_seconds", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.initial_delay_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.period_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.failure_threshold", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.readiness_probe.0.success_threshold", "1"), @@ -343,7 +343,7 @@ func TestAccAzureRMContainerGroup_windowsComplete(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.path", "/"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.port", "443"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.http_get.0.scheme", "Http"), - resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.inital_delay_seconds", "1"), + resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.initial_delay_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.period_seconds", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.success_threshold", "1"), resource.TestCheckResourceAttr(resourceName, "container.0.liveness_probe.0.timeout_seconds", "1"), @@ -649,7 +649,7 @@ resource "azurerm_container_group" "test" { readiness_probe { exec = ["cat","/tmp/healthy"] - inital_delay_seconds = 1 + initial_delay_seconds = 1 period_seconds = 1 failure_threshold = 1 success_threshold = 1 @@ -662,7 +662,7 @@ resource "azurerm_container_group" "test" { port = 443 scheme = "Http" } - inital_delay_seconds = 1 + initial_delay_seconds = 1 period_seconds = 1 failure_threshold = 1 success_threshold = 1 @@ -781,7 +781,7 @@ resource "azurerm_container_group" "test" { readiness_probe { exec = ["cat","/tmp/healthy"] - inital_delay_seconds = 1 + initial_delay_seconds = 1 period_seconds = 1 failure_threshold = 1 success_threshold = 1 @@ -794,7 +794,7 @@ resource "azurerm_container_group" "test" { port = 443 scheme = "Http" } - inital_delay_seconds = 1 + initial_delay_seconds = 1 period_seconds = 1 failure_threshold = 1 success_threshold = 1 diff --git a/website/docs/r/container_group.html.markdown b/website/docs/r/container_group.html.markdown index dc36bec4eefe..32b3a8157cc4 100644 --- a/website/docs/r/container_group.html.markdown +++ b/website/docs/r/container_group.html.markdown @@ -232,7 +232,7 @@ The `readiness_probe` block supports: * `httpget` - (Optional) The definition of the httpget for this container as documented in the `httpget` block below. Changing this forces a new resource to be created. -* `inital_delay_seconds` - (Optional) Number of seconds after the container has started before liveness or readiness probes are initiated. Changing this forces a new resource to be created. +* `initial_delay_seconds` - (Optional) Number of seconds after the container has started before liveness or readiness probes are initiated. Changing this forces a new resource to be created. * `period_seconds` - (Optional) How often (in seconds) to perform the probe. The default value is `10` and the minimum value is `1`. Changing this forces a new resource to be created. @@ -250,7 +250,7 @@ The `liveness_probe` block supports: * `httpget` - (Optional) The definition of the httpget for this container as documented in the `httpget` block below. Changing this forces a new resource to be created. -* `inital_delay_seconds` - (Optional) Number of seconds after the container has started before liveness or readiness probes are initiated. Changing this forces a new resource to be created. +* `initial_delay_seconds` - (Optional) Number of seconds after the container has started before liveness or readiness probes are initiated. Changing this forces a new resource to be created. * `period_seconds` - (Optional) How often (in seconds) to perform the probe. The default value is `10` and the minimum value is `1`. Changing this forces a new resource to be created. From 50b42c89181f6be879a50413a54dae78b8ff42d5 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 6 Apr 2019 10:09:01 +0200 Subject: [PATCH 15/15] r/container_group: ensuring the `liveness_probe` and `readiness_probe` blocks are always set --- azurerm/resource_arm_container_group.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/azurerm/resource_arm_container_group.go b/azurerm/resource_arm_container_group.go index a2b3b1ce926e..69fa0e810e60 100644 --- a/azurerm/resource_arm_container_group.go +++ b/azurerm/resource_arm_container_group.go @@ -979,13 +979,8 @@ func flattenContainerGroupContainers(d *schema.ResourceData, containers *[]conta containerConfig["volume"] = flattenContainerVolumes(container.VolumeMounts, containerGroupVolumes, containerVolumesConfig) } - if container.LivenessProbe != nil { - containerConfig["liveness_probe"] = flattenContainerProbes(container.LivenessProbe) - } - - if container.ReadinessProbe != nil { - containerConfig["readiness_probe"] = flattenContainerProbes(container.ReadinessProbe) - } + containerConfig["liveness_probe"] = flattenContainerProbes(container.LivenessProbe) + containerConfig["readiness_probe"] = flattenContainerProbes(container.ReadinessProbe) containerCfg = append(containerCfg, containerConfig) }