Skip to content

Commit

Permalink
azurerm_container_app – support for termination_grace_period_seconds (h…
Browse files Browse the repository at this point in the history
…ashicorp#28307)

* Add property termination_grace_period_seconds for container app

* Add property to complete test

* Fix terraform blocks

* Container app resource: fix docs
  • Loading branch information
CheeseMite authored and NotTheEvilOne committed Jan 20, 2025
1 parent b764977 commit de63e9d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,8 @@ resource "azurerm_container_app" "test" {
max_replicas = 3
revision_suffix = "%[3]s"
termination_grace_period_seconds = 60
}
ingress {
Expand Down
44 changes: 27 additions & 17 deletions internal/services/containerapps/helpers/container_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.",
},
},
},
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/container_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/container_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---
Expand Down

0 comments on commit de63e9d

Please sign in to comment.