hashicorp / terraform-provider-kubernetes

Terraform Kubernetes provider
https://www.terraform.io/docs/providers/kubernetes/
Mozilla Public License 2.0
1.58k stars 968 forks source link

Add equivalent of `kubectl rollout restart` #2304

Open foosinn opened 11 months ago

foosinn commented 11 months ago

Description

This would allow terraform to restart deployments. Especially useful after deploying other things

Potential Terraform Configuration

resource "kubernetes_rollout_restart" "restart_applciation" {
  apiVersion = "apps/v1"
  kind = "Deployment"

  metadata = {
    "name": "nginx"
    "namespace": "myapp"
  }

  restart_on_create = true  # default value
  restart_on_destroy = true  # default value
}

References

This would provide a much cleaner alternative to https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/blob/master/modules/acm/creds.tf#L85-L99, that also respects current context and network settings.

Community Note

jrhouston commented 11 months ago

The way kubectl rollout restart works is by patching the deployment template with the kubectl.kubernetes.io/restartedAt annotation. Rather than adding a new resource for this, you could use the kubernetes_annotations resource to do the same thing:

resource "time_static" "restarted_at" {}

resource "kubernetes_annotations" "example" {
  api_version = "apps/v1"
  kind        = "Deployment"
  metadata {
    name = "nginx-deployment"
  }
  template_annotations = {
    "kubectl.kubernetes.io/restartedAt" = time_static.restarted_at.rfc3339
  }
}