{"id":21660788,"url":"https://github.com/ahmadalibagheri/cdktf-typescript-aws-ec2","last_synced_at":"2026-03-15T08:12:05.327Z","repository":{"id":49405636,"uuid":"341267466","full_name":"ahmadalibagheri/cdktf-typescript-aws-ec2","owner":"ahmadalibagheri","description":"AWS ec2 and security configuration with typescript and cdktf","archived":false,"fork":false,"pushed_at":"2022-03-06T17:03:35.000Z","size":214,"stargazers_count":20,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T18:45:19.570Z","etag":null,"topics":["aws","cdktf","cdktf-template","terraform","typescript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahmadalibagheri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-22T16:40:35.000Z","updated_at":"2024-04-03T15:12:41.000Z","dependencies_parsed_at":"2022-08-28T00:11:43.297Z","dependency_job_id":null,"html_url":"https://github.com/ahmadalibagheri/cdktf-typescript-aws-ec2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmadalibagheri%2Fcdktf-typescript-aws-ec2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmadalibagheri%2Fcdktf-typescript-aws-ec2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmadalibagheri%2Fcdktf-typescript-aws-ec2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmadalibagheri%2Fcdktf-typescript-aws-ec2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmadalibagheri","download_url":"https://codeload.github.com/ahmadalibagheri/cdktf-typescript-aws-ec2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248492992,"owners_count":21113159,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","cdktf","cdktf-template","terraform","typescript"],"created_at":"2024-11-25T09:38:47.246Z","updated_at":"2026-03-15T08:12:05.300Z","avatar_url":"https://github.com/ahmadalibagheri.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Documentation\n\n* Explore the Terraform for Terraform [CLI](https://www.terraform.io/downloads.html) \u003e= v1.0+\n* Explore the Nodejs for npm [CLI](https://nodejs.org/en/) \u003e= v14+\n* Explore the Yarn for Yarn [CLI](https://classic.yarnpkg.com/en/docs/install#debian-stable) \u003e= v1.21 (optional - NPM will work as an alternative)\n* Explore the CDK for cdktf [CLI](https://github.com/hashicorp/terraform-cdk#build)\n\n\nAdd your AWS credentials as two environment variables, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, replacing AAAAAA with each respective values.\n```shell\n$ export AWS_ACCESS_KEY_ID=AAAAAA\n$ export AWS_SECRET_ACCESS_KEY=AAAAA\n```\n\n# typescript-aws-ec2\n\nA CDK for Terraform application in TypeScript for EC2 configuraiton.\n\n## Usage\n\nInstall project dependencies\n\n```shell\nyarn install\n```\n\nGenerate CDK for Terraform constructs for Terraform provides and modules used in the project.\n\n```bash\ncdktf get\n```\n\nYou can now edit the `main.ts` file if you want to modify any code.\n\n```typescript\nvim main.ts\nimport { Construct } from \"constructs\";\nimport { App, TerraformStack } from \"cdktf\";\nimport { AwsProvider, ec2 , vpc} from \"./.gen/providers/aws\";\n\nclass MyStack extends TerraformStack {\n  constructor(scope: Construct, id: string) {\n    super(scope, id);\n\n    new AwsProvider(this, \"aws\", {\n      region: \"us-east-1\",\n    });\n\n    const instancesg = new vpc.SecurityGroup(this, \"instancesg\", {\n      name: \"CDKtf-TypeScript-Demo-sg\",\n      description: \"Allows traffic to the instance.\",\n      ingress: [\n        {\n          protocol: \"tcp\",\n          fromPort: 80,\n          toPort: 80,\n          cidrBlocks: [\"0.0.0.0/0\"],\n        },\n        {\n          protocol: \"tcp\",\n          fromPort: 22,\n          toPort: 22,\n          cidrBlocks: [\"0.0.0.0/0\"],\n        },\n        {\n          protocol: \"tcp\",\n          fromPort: 443,\n          toPort: 443,\n          cidrBlocks: [\"0.0.0.0/0\"],\n        },\n      ],\n      egress: [\n        {\n          protocol: \"-1\",\n          fromPort: 0,\n          toPort: 0,\n          cidrBlocks: [\"0.0.0.0/0\"],\n        },\n      ],\n      tags: {\n        Name: this.node.tryGetContext(\"Name\"),\n        Team: this.node.tryGetContext(\"Team\"),\n        Company: this.node.tryGetContext(\"Company\"),\n      },\n    });\n\n    new ec2.Instance(this, \"compute\", {\n      ami: \"ami-03d315ad33b9d49c4\", //Ubuntu Server 20.04 LTS (HVM)\n      instanceType: \"t2.micro\",\n      keyName: \"DevOps\",     //You should create Keyname manually before running code\n      vpcSecurityGroupIds: [instancesg.id],\n      tags: {\n        Name: this.node.tryGetContext(\"Name\"),\n        Team: this.node.tryGetContext(\"Team\"),\n        Company: this.node.tryGetContext(\"Company\"),\n      },\n    });\n\n  }\n}\n\nconst app = new App({ context: { Name: \"CDKtf-TypeScript-Demo\" , Team: \"DevOps\", Company: \"Your company\"} });\nnew MyStack(app, \"typescript-aws\");\napp.synth();\n```\n\nCompile the TypeScript application\n\n```bash\ntsc\n```\nAt this step you can run code with two different way:\n\n# The first way:\n\nGenerate Terraform configuration\n\n```bash\ncdktf synth\n```\n\nThe above command will create a folder called `cdktf.out` that contains all Terraform JSON configuration that was generated.\n\nRun Terraform commands\n\n```bash\ncd cdktf.out\nterraform init\nterraform plan\nterraform apply\n```\n\n# The second way:\n\nRun cdktf commands\n\n```bash\ncdktf deploy\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmadalibagheri%2Fcdktf-typescript-aws-ec2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmadalibagheri%2Fcdktf-typescript-aws-ec2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmadalibagheri%2Fcdktf-typescript-aws-ec2/lists"}