jrhouston / tfk8s

A tool for converting Kubernetes YAML manifests to Terraform HCL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

metadata.generation is not stripped out

dmitrytokarev opened this issue · comments

I created Istio serviceentry with kubectl.
Then exported configuration into .tf file:
kubectl get serviceentries external-service -n namespace -o yaml | tfk8s --strip -o sample.tf

This worked and generated tf resource:

resource "kubernetes_manifest" "serviceentry_external_service" {
  manifest = {
    "apiVersion" = "networking.istio.io/v1beta1"
    "kind" = "ServiceEntry"
    "metadata" = {
      "generation" = 1  ############## NOTICE THIS LINE #########################
      "name" = "external-service"
      "namespace" = "namespace"
    }
    "spec" = {
      "endpoints" = [
        {
          "address" = "172.0.0.1"
        },
      ]
      "hosts" = [
        "my.domain.net",
      ]
      "location" = "MESH_EXTERNAL"
      "ports" = [
        {
          "name" = "service"
          "number" = 9999
          "protocol" = "TLS"
        },
      ]
      "resolution" = "STATIC"
    }
  }
}

Terraform plan worked fine.
But when I ran terraform I got this error:

tf apply tf.plan
kubernetes_manifest.serviceentry_external_service: Creating...
╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to kubernetes_manifest.serviceentry_external_service, provider
│ "provider[\"registry.terraform.io/hashicorp/kubernetes\"]" produced an unexpected new value: .object.metadata.generation: was
│ cty.NumberIntVal(1), but now null.
│ 
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.
k version --short
Client Version: v1.22.6
Server Version: v1.22.6

tfk8s -V
0.1.8

tf version
Terraform v1.3.6
on darwin_amd64
+ provider registry.terraform.io/hashicorp/kubernetes v2.16.1

FWIT I manually removed metadata.generation and terraform apply worked fine.