user5580578
user5580578

Reputation: 1334

How can I test my terrafrom modules using cdktf?

I would like to integrate existing terraform modules into cdktf. A typescript TerraformModule is created with cdktf get. Can I reference and evaluate this in my unit tests (jtest)?

import { MyLocalModule1 } from "../.gen/modules/my-local-module1";

describe("My CDKTF Application", () => {

  describe("Unit testing using assertions", () => {
    it("should contain a resource", () => {
      expect(
        Testing.synthScope((scope) => {
          new MyStack(scope, "my-app");
        })
      ).toHaveResource(MyLocalModule1)
      
      expect(Testing.fullSynth(stack)).toBeValidTerraform()
    });
  });

The above code is not working, because type 'typeof MyLocalModule1' is not assignable to parameter of type 'TerraformConstructor'. The Property 'tfResourceType' is missing in type 'typeof MyLocalModule1' but required in type 'TerraformConstructor'.

cdktf get
npm run test

Upvotes: 1

Views: 337

Answers (1)

Daniel Schmidt
Daniel Schmidt

Reputation: 11921

No you can't. There is currently no matcher for it, toHaveResource is only working for Resources, toHaveDataSource is only working for data sources.

Upvotes: 1

Related Questions