hashicorp / terraform-provider-kubernetes

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

Provider prduced inconsistent result after apply #2547

Open xfirestyle2k opened 2 months ago

xfirestyle2k commented 2 months ago

I try to deploy a Postgres DB via Data Services Manager, it actually does work and the DB will be deployed, however, because of the error I receive, I think Terraform doesn't recognise it correctly and want to delete and recreate the DB after re-appling the terraform script

│ Error: Provider produced inconsistent result after apply │ │ When applying changes to kubernetes_manifest.terra-pg-cluster, provider "provider[\"registry.terraform.io/hashicorp/kubernetes\"]" produced an unexpected new value: │ .object.spec.version: was cty.StringVal("15.7"), but now cty.StringVal("15.7+vmware.v2.1.0-rc.40"). │ │ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Terraform Version, Provider Version and Kubernetes Version

➜ ~ terraform -v Terraform v1.9.2 on darwin_arm64 Kubernetes provider version: kubernetes v2.31.0

Affected Resource(s)

Terraform Configuration Files

terraform {
  required_providers {
    kubernetes = {
      source  = "hashicorp/kubernetes"
      version = ">= 2.0.0"
    }
  }
}

provider "kubernetes" {
  config_path = "dsm-admin.kubeconfig"
}

resource "kubernetes_manifest" "terra-pg-cluster" {
  manifest = {
    "apiVersion" = "databases.dataservices.vmware.com/v1alpha1"
    "kind" = "PostgresCluster"
    "metadata" = {
      "name" = "terra-pg-cluster"
      "namespace" = "default"
      "annotations" = {
        "dsm.vmware.com/owner" = "admin@vmware.com"
      }
      "labels": {
        "dsm.vmware.com/aria-automation-instance": "Instance"
        "dsm.vmware.com/created-in": "terraform"
        "dsm.vmware.com/aria-automation-project" = "Terraform-Test"
      }
    }
    "spec" = {
      "replicas" = 3
      "version" = "15.7"
      "storageSpace" = "30G"
      "vmClass" = {
        "name" = "small"
      }
      "infrastructurePolicy" = {
        "name" = "terraform-infra-policy"
      }
      "storagePolicyName" = "vSAN Default Storage Policy"
      "backupLocation" = {
        "name" = "local-backup"
      }
      "backupConfig" = {
        "backupRetentionDays" = 7
        "schedules" = [
          {
            "name" = "full-weekly"
            "type" = "full"
            "schedule" = "0 0 * * 0"
          },
          {
            "name" = "incremental-daily"
            "type" = "incremental"
            "schedule" = "0 0 * * *"
          }
        ]
      }
    }
  }

  wait {
    condition {
      type = "Ready"
      status = "True"
    }
  }
  timeouts {
    create = "20m"
    delete = "15m"
  }
}

terraform apply --> Terraform will perform the following actions:

kubernetes_manifest.terra-pg-cluster will be created

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve.

Enter a value: yes kubernetes_manifest.terra-pg-cluster: Creating... kubernetes_manifest.terra-pg-cluster: Still creating... [10s elapsed] kubernetes_manifest.terra-pg-cluster: Still creating... [20s elapsed] kubernetes_manifest.terra-pg-cluster: Still creating... [30s elapsed] kubernetes_manifest.terra-pg-cluster: Still creating... [40s elapsed] kubernetes_manifest.terra-pg-cluster: Still creating... [50s elapsed] kubernetes_manifest.terra-pg-cluster: Still creating... [1m0s elapsed]

Expected Behavior

What should have happened?

The Postgres Database will be deployed successfully, however I think based on the error Terraform expect the DB as fault and by re-apply the terraform script it wants to destroy the deployed DB and recreate.

Actual Behavior

➜ DSM_User terraform apply kubernetes_manifest.terra-pg-cluster: Refreshing state...

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: -/+ destroy and then create replacement

Terraform will perform the following actions:

kubernetes_manifest.terra-pg-cluster is tainted, so must be replaced

-/+ resource "kubernetes_manifest" "terra-pg-cluster" { ~ object = { ~ metadata = { ~ annotations = {

Plan: 1 to add, 0 to change, 1 to destroy.

Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve.

Enter a value: yes

Community Note

BBBmau commented 2 months ago

│ .object.spec.version: was cty.StringVal("15.7"), but now cty.StringVal("15.7+vmware.v2.1.0-rc.40"). Hi @xfirestyle2k you'll want to refer to our docs regarding computed_fields. This would solve your inconsistent result since the value comes from server side. https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/manifest#computed-fields

Apply this and let us know if this solved your issue. We can close this afterwards.