Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cdktf: synth --hcl fails to render object correctly #3529

Closed
1 task
elruwen opened this issue Feb 29, 2024 · 1 comment · Fixed by #3536
Closed
1 task

cdktf: synth --hcl fails to render object correctly #3529

elruwen opened this issue Feb 29, 2024 · 1 comment · Fixed by #3536
Labels
bug Something isn't working confirmed independently reproduced by an engineer on the team new Un-triaged issue

Comments

@elruwen
Copy link

elruwen commented Feb 29, 2024

Expected Behavior

I got a little cdktf example program:

import {Construct} from "constructs";
import {App, TerraformStack} from "cdktf";
import {KubernetesProvider} from "@cdktf/provider-kubernetes/lib/provider";
import {Manifest} from "@cdktf/provider-kubernetes/lib/manifest";

class MyStack extends TerraformStack {
    constructor(scope: Construct, id: string) {
        super(scope, id);

        new KubernetesProvider(this, "k8sprovider", {})

        new Manifest(this, "knative-service", {
            manifest: {
                apiVersion: "serving.knative.dev/v1",
                kind: "Service",
                metadata: {
                    name: "ruwen-app",
                    namespace: "ruwen-ns",
                    labels: {
                        "networking.knative.dev/visibility": "cluster-local",
                        "app": "ruwen-app"
                    }
                },
            }
        })
    }
}

const app = new App();
new MyStack(app, "cdktf");
app.synth();

When running synth with json, the generated terraform code looks correct. I would expect the --hcl version also is able to render metadata as a nested structure.

Actual Behavior

Json result:

{
  "//": {
    "metadata": {
      "backend": "local",
      "stackName": "cdktf",
      "version": "0.20.4"
    },
    "outputs": {
    }
  },
  "provider": {
    "kubernetes": [
      {
      }
    ]
  },
  "resource": {
    "kubernetes_manifest": {
      "knative-service": {
        "//": {
          "metadata": {
            "path": "cdktf/knative-service",
            "uniqueId": "knative-service"
          }
        },
        "manifest": {
          "apiVersion": "serving.knative.dev/v1",
          "kind": "Service",
          "metadata": {
            "labels": {
              "app": "ruwen-app",
              "networking.knative.dev/visibility": "cluster-local"
            },
            "name": "ruwen-app",
            "namespace": "ruwen-ns"
          }
        }
      }
    }
  },
  "terraform": {
    "backend": {
      "local": {
        "path": "/home/ruwen/src/local/cdktf/terraform.cdktf.tfstate"
      }
    },
    "required_providers": {
      "kubernetes": {
        "source": "kubernetes",
        "version": "2.25.2"
      }
    }
  }
}

HCL version - spot the [Object object] rendering

terraform {
  required_providers {
    kubernetes = {
      version = "2.25.2"
      source  = "kubernetes"
    }
  }
  backend "local" {
    path = "/home/ruwen/src/local/cdktf/terraform.cdktf.tfstate"
  }


}

provider "kubernetes" {
}
resource "kubernetes_manifest" "knative-service" {
  manifest = {
    apiVersion = "serving.knative.dev/v1"
    kind       = "Service"
    metadata   = [object Object]
  }
}

Steps to Reproduce

Example file:

import {Construct} from "constructs";
import {App, TerraformStack} from "cdktf";
import {KubernetesProvider} from "@cdktf/provider-kubernetes/lib/provider";
import {Manifest} from "@cdktf/provider-kubernetes/lib/manifest";

class MyStack extends TerraformStack {
    constructor(scope: Construct, id: string) {
        super(scope, id);

        new KubernetesProvider(this, "k8sprovider", {})

        new Manifest(this, "knative-service", {
            manifest: {
                apiVersion: "serving.knative.dev/v1",
                kind: "Service",
                metadata: {
                    name: "ruwen-app",
                    namespace: "ruwen-ns",
                    labels: {
                        "networking.knative.dev/visibility": "cluster-local",
                        "app": "ruwen-app"
                    }
                },
            }
        })
    }
}

const app = new App();
new MyStack(app, "cdktf");
app.synth();

Run cdktf synth --hcl

Versions

cdktf debug
language: typescript
cdktf-cli: 0.20.4
node: v18.15.0
cdktf: 0.20.4
constructs: 10.3.0
jsii: null
terraform: 1.7.2
arch: x64
os: linux 6.1.0-17-amd64
providers
@cdktf/provider-aws (PREBUILT)
terraform provider version: 5.33.0
prebuilt provider version: 19.2.0
cdktf version: ^0.20.0
@cdktf/provider-kubernetes (PREBUILT)
terraform provider version: 2.25.2
prebuilt provider version: 11.0.0
cdktf version: ^0.20.0
@cdktf/provider-local (PREBUILT)
terraform provider version: 2.4.1
prebuilt provider version: 10.0.0
cdktf version: ^0.20.0

Providers

┌───────────────┬──────────────────┬─────────┬────────────┬────────────────────────────┬─────────────────┐
│ Provider Name │ Provider Version │ CDKTF │ Constraint │ Package Name │ Package Version │
├───────────────┼──────────────────┼─────────┼────────────┼────────────────────────────┼─────────────────┤
│ aws │ 5.33.0 │ ^0.20.0 │ │ @cdktf/provider-aws │ 19.2.0 │
├───────────────┼──────────────────┼─────────┼────────────┼────────────────────────────┼─────────────────┤
│ kubernetes │ 2.25.2 │ ^0.20.0 │ │ @cdktf/provider-kubernetes │ 11.0.0 │
├───────────────┼──────────────────┼─────────┼────────────┼────────────────────────────┼─────────────────┤
│ local │ 2.4.1 │ ^0.20.0 │ │ @cdktf/provider-local │ 10.0.0 │
└───────────────┴──────────────────┴─────────┴────────────┴────────────────────────────┴─────────────────┘

Gist

No response

Possible Solutions

No response

Workarounds

Don't use hcl

Anything Else?

I think the manifest resource is a special one, since it allows inside manifest anything.

References

No response

Help Wanted

  • I'm interested in contributing a fix myself

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
@elruwen elruwen added bug Something isn't working new Un-triaged issue labels Feb 29, 2024
@DanielMSchmidt DanielMSchmidt added the confirmed independently reproduced by an engineer on the team label Mar 4, 2024
DanielMSchmidt added a commit that referenced this issue Mar 4, 2024
ansgarm pushed a commit that referenced this issue Mar 4, 2024
Copy link
Contributor

github-actions bot commented Apr 4, 2024

I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working confirmed independently reproduced by an engineer on the team new Un-triaged issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants