Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recreate kubernetes_manifest resource when manifest.metadata.name changed #1518

Closed
Vlad1mir-D opened this issue Nov 30, 2021 · 3 comments
Closed

Comments

@Vlad1mir-D
Copy link

Vlad1mir-D commented Nov 30, 2021

Terraform Version, Provider Version and Kubernetes Version

Terraform version: 1.0.3
Kubernetes provider version: 2.6.1
Kubernetes version: v1.20.10-gke.1600

Affected Resource(s)

  • kubernetes_manifest

Terraform Configuration Files

terraform {
  experiments = [module_variable_optional_attrs]
}

variable "kubernetes_manifests" {
  description = "A list of Kubernetes manifests."
  type = list(object({
     manifest        = string
     field_manager = optional(object({
      name            = string
      force_conflicts = bool
    }))
  }))
}

resource "kubernetes_manifest" "this" {
  for_each = { for key, value in var.kubernetes_manifests : key => value }

  manifest        = yamldecode(each.value.manifest)

  dynamic "field_manager" {
    for_each = each.value.field_manager != null ? [each.value.field_manager] : []
    content {
      name            = field_manager.value.name
      force_conflicts = field_manager.value.force_conflicts
    }
  }
}

Debug Output

https://gist.github.com/Vlad1mir-D/c39b0031cc6cbad7492e2916554bf646

Steps to Reproduce

  1. Alter manifest.metadata.name for kubernetes_manifest resource
  2. terraform apply

Expected Behavior

Terraform will perform the following actions:

  # kubernetes_manifest.this["0"] must be replaced
-/+ resource "kubernetes_manifest" "this" {
      ~ manifest = {
          ~ metadata   = {
              ~ name      = "redis-infra-prod-monitoring-node-redis-sentry-4" -> "redis-infra-prod-monitoring-node-redis-sentry-5" # forces replacement

Actual Behavior

Terraform will perform the following actions:

  # kubernetes_manifest.this["0"] will be updated in-place
  ~ resource "kubernetes_manifest" "this" {
      ~ manifest = {
          ~ metadata   = {
              ~ name      = "redis-infra-prod-monitoring-node-redis-sentry-4" -> "redis-infra-prod-monitoring-node-redis-sentry-5"

which leads to the creation of an additional resource with the new name and complete removal of an original resource from the Terraform state but not K8s (it will be completely ignored after terraform apply as it never exists).

Important Factoids

References

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@Vlad1mir-D Vlad1mir-D added the bug label Nov 30, 2021
@Vlad1mir-D Vlad1mir-D changed the title Recreate kubernetes_manifest resource when manifest.metadata.name changed Recreate kubernetes_manifest resource when manifest.metadata.name changed Nov 30, 2021
@BojanZelic
Copy link

Seeing the same behavior if metadata.namespace changes aswell. Which makes sense as it's also an unmutable resource.

@jbg
Copy link

jbg commented Mar 23, 2022

A generic way to force recreation when certain attributes are changed (with immutable attributes in metadata included by default) would be useful. Custom resources often have immutable attributes too, and currently if you want to change them you have to taint the resource to get the provider to recreate it.

@github-actions
Copy link

Marking this issue as stale due to inactivity. If this issue receives no comments in the next 30 days it will automatically be closed. If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. This helps our maintainers find and focus on the active issues. Maintainers may also remove the stale label at their discretion. Thank you!

@github-actions github-actions bot added the stale label Mar 24, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants