Create instance after an async API call in single function in TS

I am trying to call a function inside a class. in that function first i am calling an API to get some data with “await” and then using that data i am calling TF class to create an EC2 instance but it is not working. TF is saying no change in stack. however if i remove await from that first API it is working fine but i am getting that data on time because it takes time to get the data but program is not stopping for that. Anyone can help to solve this ?

class sample extends Resource {
  constructor(scope: Construct, id: string) {
    super(scope, id);
  }

  dummy = () => {
    console.log("hello");
    return;
  }

  createInfra = async() => {
    const response = await this.dummy();
    console.log(response);
    new AwsProvider(this, 'aws', {
      region: 'us-west-1',
    })

    const instance = new EC2.Instance(this, 'compute', {
      ami: 'default-ami',
      instanceType: 't2.micro'
    })

    new TerraformOutput(this, 'public_ip', {
      value: instance.publicIp,
    })
  }
}
class MyStack extends TerraformStack {
  constructor(scope: Construct, id: string) {
    super(scope, id)
    new sample(this, "test").createInfra();
  }
}

const app = new App()
new MyStack(app, 'typescript-aws')
app.synth()

This is currently not supported, neither asynchronous code nor side-effects can be made. To solve this you would need to call the API before running cdktf, generating for example a file as an artifact that you can then use via fs.readFileSync or similar APIs to provision the infrastructure with.

We are planning to make this a better supported use-case, e.g. via lifecycle hooks: Lifecycle Hooks · Issue #682 · hashicorp/terraform-cdk · GitHub