From 5855a1f963f79a787f7956f085c1a5110935fc45 Mon Sep 17 00:00:00 2001 From: Nikita Barichev Date: Tue, 17 Dec 2024 06:58:55 +0100 Subject: [PATCH 1/4] Add property termination_grace_period_seconds for container app --- .../containerapps/helpers/container_apps.go | 44 ++++++++++++------- website/docs/d/container_app.html.markdown | 2 + 2 files changed, 29 insertions(+), 17 deletions(-) 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. --- From 53dd18a0bd2dc173cfaa1d4bab6e7b1b135e9faf Mon Sep 17 00:00:00 2001 From: Nikita Barichev Date: Tue, 17 Dec 2024 07:28:01 +0100 Subject: [PATCH 2/4] Add property to complete test --- internal/services/containerapps/container_app_resource_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/services/containerapps/container_app_resource_test.go b/internal/services/containerapps/container_app_resource_test.go index 3c42c8f8a64f..39672bb70a8b 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 { From 40451cc7025e1d168c5a2411dd910cd85db0ac69 Mon Sep 17 00:00:00 2001 From: Nikita Barichev Date: Mon, 23 Dec 2024 17:36:32 +0100 Subject: [PATCH 3/4] Fix terraform blocks --- internal/services/containerapps/container_app_resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/containerapps/container_app_resource_test.go b/internal/services/containerapps/container_app_resource_test.go index 39672bb70a8b..d8ee1530fa8a 100644 --- a/internal/services/containerapps/container_app_resource_test.go +++ b/internal/services/containerapps/container_app_resource_test.go @@ -1387,7 +1387,7 @@ resource "azurerm_container_app" "test" { max_replicas = 3 revision_suffix = "%[3]s" - + termination_grace_period_seconds = 60 } From 2fdcb4d1ac69965be360f99b7db2e829537d1266 Mon Sep 17 00:00:00 2001 From: Nikita Barichev Date: Tue, 14 Jan 2025 23:02:55 +0100 Subject: [PATCH 4/4] Container app resource: fix docs --- website/docs/r/container_app.html.markdown | 2 ++ 1 file changed, 2 insertions(+) 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. ---