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()