How can I test my terrafrom modules using cdktf?

262 views Asked by At

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
1

There are 1 answers

0
Daniel Schmidt On BEST ANSWER

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