kbst / terraform-provider-kustomization

Terraform provider for Kustomize
https://www.kubestack.com
Apache License 2.0
267 stars 53 forks source link

`terraform apply` show diff of empty annotations #208

Closed gnuletik closed 1 year ago

gnuletik commented 2 years ago

When running terraform apply, each of the resources without annotations show a diff from an empty annotations to null.

  # kustomization_resource.p1["apps/Deployment/my-namespace/my-deployment"] will be updated in-place
  ~ resource "kustomization_resource" "p1" {
        id       = "f9db08d4-34e8-4693-94a0-d3efd4487ca3"
      ~ manifest = jsonencode(
          ~ {
              ~ metadata   = {
                  - annotations = {} -> null
                    name        = "my-deployment"
                    # (2 unchanged elements hidden)
                }
                # (3 unchanged elements hidden)
            }
        )
    }

Setting commonAnnotations: {} inside kustomization.yml give the same result.

I currently set an annotation to avoid this but I'm wondering if the terrafirn provider should ignore this change?

Thanks!

pst commented 2 years ago

How does the manifest that generates this diff look like?

gnuletik commented 2 years ago

I removed other resources to only keep the API:

kustomization.yml

namespace: my-app
commonLabels:
  app.kubernetes.io/part-of: my-app

resources:
  - api.yml

api.yml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-api
  namespace: default
  labels:
    app: my-app-api
    app.kubernetes.io/name: my-app-api
    app.kubernetes.io/part-of: my-app
spec:
  replicas: 2
  minReadySeconds: 5
  strategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app: my-app-api
  template:
    metadata:
      labels:
        app: my-app-api
        app.kubernetes.io/name: my-app-api
        app.kubernetes.io/part-of: my-app
      annotations:
        some-annotation: 'content'
    spec:
      serviceAccountName: something
      terminationGracePeriodSeconds: 10
      imagePullSecrets:
        - name: dockerhub
      containers:
      - name: my-app-api
        image: company/my-app/api
        resources:
          requests:
            memory: 500Mi
            cpu: 0.1
          limits:
            memory: 500Mi
            cpu: 0.2
        env:
          - name: ENV
            valueFrom:
              configMapKeyRef:
                name: my-app
                key: env
        ports:
          - containerPort: 8000
            name: http
        livenessProbe:
          httpGet:
            path: /health
            port: http
          timeoutSeconds: 3
        startupProbe:
          httpGet:
            path: /health
            port: http
          timeoutSeconds: 3
          periodSeconds: 5
          failureThreshold: 15
---
apiVersion: v1
kind: Service
metadata:
  name: my-app-api
  namespace: default
  labels:
    app: my-app-api-svc
    app.kubernetes.io/name: my-app-api-svc
    app.kubernetes.io/part-of: my-app
spec:
  selector:
    app: my-app-api
  ports:
    - protocol: TCP
      port: 80
      targetPort: http
pst commented 1 year ago

I can not reproduce this. Repeatedly applying the resources based on the provided manifests does not show any diffs.