Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
cdktf-helpers
Advanced tools
Readme
Helpers for creating the stacks of cdktf
, inspired by class component of React.js
.
// main_stack.ts
export class MainStack extends CdktfStackComponent<Props, State> {
beforeCreateResources() {
// do something before creating resources
new AwsProvider(this, "AWS", {
region: "us-west-1",
});
const config = JSON.parse(fs.readFileSync("./config.json", "utf-8"));
// set value for later use
this.setState("instaceType", config.instanceType);
}
createResources() {
// you can get value from props
const ami = this.props.ami;
const ec2Instance = new Instance(this, "compute", {
ami,
instanceType: this.state.instanceType,
});
// set value for output
this.setOutput("ec2_instance", ec2Instance);
}
}
// main.ts
const app = new App();
CdktfComponentFactory.createComponent(app, MainStack.name, {
ami: "ami-01456a894f71116f2",
});
A CdktfStackComponent
comes with a pair of props
and state
to help you manage the data flow of your CDKTF stack.
To define a CDKTF component class, you need to extend CdktfStackComponent
:
import { CdktfStackComponent } from "cdktf-helpers";
type Props = { ami: string };
type State = { ec2Instance: Instance };
export class MainStack extends CdktfStackComponent<Props, State> {
beforeCreateResources() {
// do something before creating resources
}
createResources() {
// create resources here
}
afterCreateResources() {
// do something after creating resources
}
}
constructor()
type constructor = (
scope: Construct,
id: string,
props?: Record<string, any> & { stackName: string }
) => CdktfStackComponent;
beforeCreateResources()
It is invoked immediately after a component is initialised.
createResources()
It is invoked after beforeCreateResources
is executed.
You can create the resources in this method.
afterCreateResources()
It is invoked after createResource
is executed.
CdktfComponentFactory.createComponent
import { CdktfComponentFactory } from "cdktf-helpers";
import { App } from "cdktf";
import MainStack from "./main_stack.ts";
const app = new App();
CdktfComponentFactory.createComponent(app, MainStack.name, {
ami: "ami-01456a894f71116f2",
});
CdktfComponentFactory.createComponentAsync
Factory also provide async method, you can use it to create component asynchronously.
// With top level await
import { CdktfComponentFactory } from "cdktf-helpers";
import { App } from "cdktf";
import MainStack from "./main_stack.ts";
const app = new App();
await CdktfComponentFactory.createComponentAsync(app, MainStack.name, {
ami: "ami-01456a894f71116f2",
});
When an instance of the CDKTF component is generated by createComponent()
, these methods are called in the below order:
constructor()
beforeCreateResources()
createResource()
afterCreateResources()
setOutput
while creating resources, it will be called after all functions are executed.FAQs
Unknown package
The npm package cdktf-helpers receives a total of 0 weekly downloads. As such, cdktf-helpers popularity was classified as not popular.
We found that cdktf-helpers demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.