terraform-cdk
terraform-cdk copied to clipboard
Cdktf deploy command returns 137 error code while running from node js script
Expected Behavior
I have a script which has code to provision the stacks something like
async function execCommand(command: string): Promise<void> {
return new Promise((resolve, reject) => {
const childProcess = spawn(command, { shell: true });
childProcess.stdout?.on("data", (data: any) => {
process.stdout.write(data);
});
childProcess.stderr?.on("data", (data: any) => {
process.stderr.write(data);
});
childProcess.on("error", (error: ExecException) => {
console.error(`Error executing command '${command}': ${error.message}`);
reject(error);
});
childProcess.on("exit", (code: any) => {
if (code !== 0) {
reject(new Error(`Command '${command}' exited with code ${code}`));
} else {
resolve();
}
});
});
}`
async function provision(name: string) {
const app = new App();
new MyStack(app, name, name);
new PgBackend(app, {
connStr,
schemaName: "public",
skipSchemaCreation: true,
});
await app.synth();
await execCommand(`cdktf deploy ${name} --auto-approve`);
}
//to run the parrallel deployments i am using promise.all
Promise.all([provision("y"),provision("x")]).then(() => console.log("All provision functions completed successfully."));`
`mystack.ts=======>
import { Construct } from "constructs";
import { AwsProvider } from "@cdktf/provider-aws/lib/provider";
import { Instance } from "@cdktf/provider-aws/lib/instance";
import { TerraformOutput, TerraformStack } from "cdktf";
export class MyStack extends TerraformStack {
constructor(scope: Construct, name: string, workspace: string) {
super(scope, name);
// Define AWS provider
const awsProvider = new AwsProvider(this, "aws", {
region: "us-west-1",
});
// Define an EC2 instance resource
const ec2Instance = new Instance(this, workspace, {
ami: "ami-01456a894f71116f2",
instanceType: "t2.micro",
tags: {
Name: workspace, // Replace with the desired name
},
provider: awsProvider,
});
new TerraformOutput(this, "ec2-instance-id", {
value: ec2Instance.id,
});
}
}`
mystack is just one ec2 instance when i run this script it takes forever to complete and sometime returns the 137 error code
The reason i am writing this code is to test the parrallel deployments we have one configuration tool where we provisions the infra as per request(provision some ec2 instance for one client and s3 for other client) the cdktf deploy command is not streaming the logs back to node js process shell The script is just taking forever to finish(sometimes exits with 137 error code) is there something wrong the way i have used deploy command? or is it expected running script without the code of deploy works fine and completes immediately I want to build the app to run parrallel deployments/provisioning of resources on demand . is there a way for that with cdktf?
Actual Behavior
cdktf deploy command should execute and return no error while running it from node js script
Steps to Reproduce
create cdktf app with typescript template use aws provider run npx ts-node main.ts //to run the provisioning code
Versions
cdktf 0.20.3 language typescript
Providers
No response
Gist
No response
Possible Solutions
No response
Workarounds
No response
Anything Else?
No response
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
Exit code 137 hints towards an Out of Memory problem, could it be that your provisioning script takes up to much resources (together with cdktf)? I would suggest trying to split your provisioning and the cdktf application up to verify which one is the cause.
Hi there! 👋 We haven't heard from you in 15 days and would like to know if the problem has been resolved or if you still need help. If we don't hear from you before then, I'll auto-close this issue in 30 days.
I'm closing this issue because we haven't heard back in 45 days. ⌛️ If you still need help, feel free to comment or reopen the issue!
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.