Skip to content

kubernetes_manifest imported resources are recreated not updated #1712

@samiamoura

Description

@samiamoura

Terraform Version, Provider Version and Kubernetes Version

Terraform version: 1.1.9
Kubernetes provider version: 2.11.0
Kubernetes version: 1.22.5

Affected Resource(s)

  • kubernetes_manifest

Terraform Configuration Files

resource "kubernetes_manifest" "serviceaccount_default" {
  manifest = {
    "apiVersion" = "v1"
    "imagePullSecrets" = [
      {
        "name" = "default-dockercfg-k5mph"
      },
    ]
    "kind" = "ServiceAccount"
    "metadata" = {
      "name" = "default"
      "namespace" = "default"
    }
    "secrets" = [
      {
        "name" = "default-token-hrxnz"
      },
      {
        "name" = "default-dockercfg-k5mph"
      },
    ]
  }
}

Steps to Reproduce

  1. Create Terraform manifest file sa-default.tf:
resource "kubernetes_manifest" "serviceaccount_default" {
  manifest = {
    "apiVersion" = "v1"
    "imagePullSecrets" = [
      {
        "name" = "default-dockercfg-k5mph"
      },
    ]
    "kind" = "ServiceAccount"
    "metadata" = {
      "name" = "default"
      "namespace" = "default"
    }
    "secrets" = [
      {
        "name" = "default-token-hrxnz"
      },
      {
        "name" = "default-dockercfg-k5mph"
      },
    ]
  }
}
  1. Import terraform resource kubernetes_manifest.serviceaccount_default:
terraform import kubernetes_manifest.serviceaccount_default "apiVersion=v1,kind=ServiceAccount,name=default,namespace=default"
  1. Terraform plan/apply:
terraform plan 

or

terraform apply 

Expected Behavior

What should have happened?
Terrafom should update in-place resource.

Actual Behavior

When importing a kubernetes resource with terraform import command and then executing terraform apply, the kubernetes will be replaced (delete and recreate) instead of updated.

terraform plan :
Capture d’écran 2022-05-08 à 03 16 12

terraform apply:
Capture d’écran 2022-05-08 à 20 16 21

We can see apiVersion, Kind and Name are added despite the fact that the fields have not been modified and have the same name which causes to the creation of the object and not the update

It seems the normal behavior for all terraform resources from #1593 issue. Recreation is the default behavior when apiVersion, Kind or Name changed. When importing a kubernetes manifest resource with this command terraform import kubernetes_manifest.secret_sample "apiVersion=v1,kind=Secret,namespace=default,name=sample" the fields apiVersion, Kind or Name are systematically added despite the fact that they do not change.

Important Factoids

  • Downgrading to v2.8.0 of the provider results in the correct expected behavior.

  • Importing resource with provider version >2.8.0 results re-creation of the resource

  • Importing resource with provider version <=2.8.0 works as expected - resource is updated in-place

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions