From de63e9dca5c132be6d6c019f11cae69083d63a75 Mon Sep 17 00:00:00 2001 From: Nikita Barichev <44852687+CheeseMite@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:33:32 +0100 Subject: [PATCH] =?UTF-8?q?azurerm=5Fcontainer=5Fapp=20=E2=80=93=20support?= =?UTF-8?q?=20for=20termination=5Fgrace=5Fperiod=5Fseconds=20(#28307)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add property termination_grace_period_seconds for container app * Add property to complete test * Fix terraform blocks * Container app resource: fix docs --- .../container_app_resource_test.go | 2 + .../containerapps/helpers/container_apps.go | 44 ++++++++++++------- website/docs/d/container_app.html.markdown | 2 + website/docs/r/container_app.html.markdown | 2 + 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/internal/services/containerapps/container_app_resource_test.go b/internal/services/containerapps/container_app_resource_test.go index 3c42c8f8a64f..d8ee1530fa8a 100644 --- a/internal/services/containerapps/container_app_resource_test.go +++ b/internal/services/containerapps/container_app_resource_test.go @@ -1387,6 +1387,8 @@ resource "azurerm_container_app" "test" { max_replicas = 3 revision_suffix = "%[3]s" + + termination_grace_period_seconds = 60 } ingress { diff --git a/internal/services/containerapps/helpers/container_apps.go b/internal/services/containerapps/helpers/container_apps.go index 8a99c54f347d..56755711d548 100644 --- a/internal/services/containerapps/helpers/container_apps.go +++ b/internal/services/containerapps/helpers/container_apps.go @@ -813,16 +813,17 @@ func ContainerAppEnvironmentDaprMetadataSchema() *pluginsdk.Schema { } type ContainerTemplate struct { - Containers []Container `tfschema:"container"` - InitContainers []BaseContainer `tfschema:"init_container"` - Suffix string `tfschema:"revision_suffix"` - MinReplicas int64 `tfschema:"min_replicas"` - MaxReplicas int64 `tfschema:"max_replicas"` - AzureQueueScaleRules []AzureQueueScaleRule `tfschema:"azure_queue_scale_rule"` - CustomScaleRules []CustomScaleRule `tfschema:"custom_scale_rule"` - HTTPScaleRules []HTTPScaleRule `tfschema:"http_scale_rule"` - TCPScaleRules []TCPScaleRule `tfschema:"tcp_scale_rule"` - Volumes []ContainerVolume `tfschema:"volume"` + Containers []Container `tfschema:"container"` + InitContainers []BaseContainer `tfschema:"init_container"` + Suffix string `tfschema:"revision_suffix"` + MinReplicas int64 `tfschema:"min_replicas"` + MaxReplicas int64 `tfschema:"max_replicas"` + AzureQueueScaleRules []AzureQueueScaleRule `tfschema:"azure_queue_scale_rule"` + CustomScaleRules []CustomScaleRule `tfschema:"custom_scale_rule"` + HTTPScaleRules []HTTPScaleRule `tfschema:"http_scale_rule"` + TCPScaleRules []TCPScaleRule `tfschema:"tcp_scale_rule"` + Volumes []ContainerVolume `tfschema:"volume"` + TerminationGracePeriod int64 `tfschema:"termination_grace_period_seconds"` } func ContainerTemplateSchema() *pluginsdk.Schema { @@ -868,6 +869,13 @@ func ContainerTemplateSchema() *pluginsdk.Schema { Computed: true, // Note: O+C This value is always present and non-zero but if not user specified, then the service will generate a value. Description: "The suffix for the revision. This value must be unique for the lifetime of the Resource. If omitted the service will use a hash function to create one.", }, + + "termination_grace_period_seconds": { + Type: pluginsdk.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(0, 600), + Description: "The time in seconds after the container is sent the termination signal before the process if forcibly killed.", + }, }, }, } @@ -921,9 +929,10 @@ func ExpandContainerAppTemplate(input []ContainerTemplate, metadata sdk.Resource config := input[0] template := &containerapps.Template{ - Containers: expandContainerAppContainers(config.Containers), - InitContainers: expandInitContainerAppContainers(config.InitContainers), - Volumes: expandContainerAppVolumes(config.Volumes), + Containers: expandContainerAppContainers(config.Containers), + InitContainers: expandInitContainerAppContainers(config.InitContainers), + Volumes: expandContainerAppVolumes(config.Volumes), + TerminationGracePeriodSeconds: pointer.To(config.TerminationGracePeriod), } if config.MaxReplicas != 0 { @@ -962,10 +971,11 @@ func FlattenContainerAppTemplate(input *containerapps.Template) []ContainerTempl return []ContainerTemplate{} } result := ContainerTemplate{ - Containers: flattenContainerAppContainers(input.Containers), - InitContainers: flattenInitContainerAppContainers(input.InitContainers), - Suffix: pointer.From(input.RevisionSuffix), - Volumes: flattenContainerAppVolumes(input.Volumes), + Containers: flattenContainerAppContainers(input.Containers), + InitContainers: flattenInitContainerAppContainers(input.InitContainers), + Suffix: pointer.From(input.RevisionSuffix), + TerminationGracePeriod: pointer.From(input.TerminationGracePeriodSeconds), + Volumes: flattenContainerAppVolumes(input.Volumes), } if scale := input.Scale; scale != nil { diff --git a/website/docs/d/container_app.html.markdown b/website/docs/d/container_app.html.markdown index e1ae9f0227c9..8ac04e0967f0 100644 --- a/website/docs/d/container_app.html.markdown +++ b/website/docs/d/container_app.html.markdown @@ -79,6 +79,8 @@ A `template` block supports the following: * `revision_suffix` - The suffix for the revision. This value must be unique for the lifetime of the Resource. If omitted the service will use a hash function to create one. +* `termination_grace_period_seconds` - The time in seconds after the container is sent the termination signal before the process if forcibly killed. + * `volume` - A `volume` block as detailed below. --- diff --git a/website/docs/r/container_app.html.markdown b/website/docs/r/container_app.html.markdown index 23a7ebc2ffcc..ae967dff9b21 100644 --- a/website/docs/r/container_app.html.markdown +++ b/website/docs/r/container_app.html.markdown @@ -124,6 +124,8 @@ A `template` block supports the following: * `revision_suffix` - (Optional) The suffix for the revision. This value must be unique for the lifetime of the Resource. If omitted the service will use a hash function to create one. +* `termination_grace_period_seconds` - (Optional) The time in seconds after the container is sent the termination signal before the process if forcibly killed. + * `volume` - (Optional) A `volume` block as detailed below. ---