hashicorp / terraform-provider-kubernetes-alpha

A Terraform provider for Kubernetes that uses dynamic resource types and server-side apply. Supports all Kubernetes resources.
https://registry.terraform.io/providers/hashicorp/kubernetes-alpha/latest
Mozilla Public License 2.0
490 stars 63 forks source link

Error after upgrade from 0.4.1 to 0.5.0: failed to encode refreshed data for module as JSON #254

Open dzhlobo opened 3 years ago

dzhlobo commented 3 years ago

Terraform, Provider, Kubernetes versions

Terraform version: 1.0.1 (it seems terraform -v shows wrong data, since I use Terraform Cloud and I set terraform version to 1.0.3)
Provider version: 0.5.0
Kubernetes version: 1.21.2

Affected Resource(s)

kubernetes_manifest

Terraform Configuration Files

resource "kubernetes_manifest" "cert-issuer-letsencrypt" {
  provider = kubernetes-alpha

  manifest = {
    apiVersion = "cert-manager.io/v1"
    kind       = "Issuer"
    metadata = {
      name      = "letsencrypt"
      namespace = var.app_namespace
    }
    spec = {
      acme = {
        server = "https://acme-v02.api.letsencrypt.org/directory"
        email  = var.email
        privateKeySecretRef = {
          name = "letsencrypt-issuer-key"
        }
        solvers = [{
          http01 = {
            ingress = {
              class = "nginx"
            }
          }
        }]
      }
    }
  }
}

Debug Output

kubectl describe issuers/letsencrypt
Metadata:                                                                                               
  Creation Timestamp:  2021-04-25T00:07:52Z                                                             
  Generation:          1                                                                                
  Managed Fields:                                                                                       
    API Version:  cert-manager.io/v1                                                                    
    Fields Type:  FieldsV1                                                                              
    fieldsV1:                                                                                           
      f:spec:                                                                                           
        f:acme:                                                                                         
          f:email:                                                                                      
          f:privateKeySecretRef:                                                                        
            f:name:                                                                                     
          f:server:                                                                                     
          f:solvers:                                                                                    
    Manager:      Terraform                                                                             
    Operation:    Apply                                                                                 
    Time:         2021-04-25T00:07:52Z                                                                                                                                                                          
    API Version:  cert-manager.io/v1                                                                                                                                                                            
    Fields Type:  FieldsV1                                                                                                                                                                                      
    fieldsV1:                                                                                                                                                                                                   
      f:status:                                                                                                                                                                                                 
        .:                                                                                                                                                                                                      
        f:acme:                                                                                                                                                                                                 
          .:                                                                                                                                                                                                    
          f:lastRegisteredEmail:                                                                                                                                                                                
          f:uri:                                                                                                                                                                                                
        f:conditions:                                                                                                                                                                                           
    Manager:         controller                                                                                                                                                                                     Operation:       Update                                                                                                                                                                                         Time:            2021-04-25T00:07:53Z                                                               
  Resource Version:  42462                                                                              
  UID:               daa6a6df-73ac-4e2c-bb25-400c319d6951                                               

Panic Output

Steps to Reproduce

  1. Create Issuer CRD (cert-manager 1.4.1) with kubernetes-alpha 0.4.1
  2. Upgrade kubernetes-alpha to 0.5.0
  3. Run terraform apply

Expected Behavior

Terraform fetches fields it previously didn't know about and updates state.

Actual Behavior

Terraform doesn't see CRD's fields in Kubernetes and can't update them in the state and fails at the end of terraform apply execution:

Terraform detected the following changes made outside of Terraform since the
last "terraform apply":                                                                                 

  # module.kubernetes.module.cluster.kubernetes_manifest.cert-issuer-letsencrypt has been changed
  ~ resource "kubernetes_manifest" "cert-issuer-letsencrypt" {                                          
      ~ object   = {                                                                                    
          ~ metadata   = {                                                                              
              - annotations                = null -> null
              - clusterName                = null -> null
              - creationTimestamp          = null -> null                                               
              - deletionGracePeriodSeconds = null -> null
              - deletionTimestamp          = null -> null                                               
              - finalizers                 = null -> null                                               
              - generateName               = null -> null
              - generation                 = null -> null                                               
              - labels                     = null -> null                    
              - managedFields              = null -> null               
              - ownerReferences            = null -> null                                               
              - resourceVersion            = null -> null
              - selfLink                   = null -> null                    
              - uid                        = null -> null
                # (2 unchanged elements hidden)                                                         
            }                                                                                                                                                                                                   
            # (3 unchanged elements hidden)                                                                                                                                                                             }                                                                                                                                                                                                               # (1 unchanged attribute hidden)                                                                
    }                                     
Failed running command "cd '/terraform' && envdir /env terraform show -json /terraform/terraform.tfplan" (exit 1)
Output: Failed to marshal plan to json: error in marshalResourceDrift: 
failed to encode refreshed data for module.kubernetes.module.cluster.kubernetes_manifest.cert-issuer-letsencrypt as JSON: 
attribute "object": attribute "metadata": 
attributes "annotations", "clusterName", "creationTimestamp", "deletionGracePeriodSeconds", "deletionTimestamp", "finalizers", "generateName", "generation", "labels", "managedFields", "ownerReferences", "resourceVersion", "selfLink", and "uid" are required

Important Factoids

References

Community Note