{"id":21660793,"url":"https://github.com/ahmadalibagheri/cdktf-typescript-aws-kms","last_synced_at":"2025-04-11T22:42:59.861Z","repository":{"id":49405658,"uuid":"342623288","full_name":"ahmadalibagheri/cdktf-typescript-aws-kms","owner":"ahmadalibagheri","description":"AWS kms key configuration with typescript and cdktf ","archived":false,"fork":false,"pushed_at":"2022-03-08T08:29:09.000Z","size":150,"stargazers_count":18,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T18:45:18.264Z","etag":null,"topics":["aws","aws-kms","cdktf","cdktf-template","kms","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-26T15:48:46.000Z","updated_at":"2023-03-05T08:56:54.000Z","dependencies_parsed_at":"2022-08-29T02:12:43.369Z","dependency_job_id":null,"html_url":"https://github.com/ahmadalibagheri/cdktf-typescript-aws-kms","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-kms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmadalibagheri%2Fcdktf-typescript-aws-kms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmadalibagheri%2Fcdktf-typescript-aws-kms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmadalibagheri%2Fcdktf-typescript-aws-kms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmadalibagheri","download_url":"https://codeload.github.com/ahmadalibagheri/cdktf-typescript-aws-kms/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248492993,"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","aws-kms","cdktf","cdktf-template","kms","terraform","typescript"],"created_at":"2024-11-25T09:38:49.126Z","updated_at":"2025-04-11T22:42:59.828Z","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-kms\n\nA CDK for Terraform application in TypeScript for kms 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, TerraformOutput } from \"cdktf\";\nimport {\n  AwsProvider,\n  datasources,\n  kms\n} from \"./.gen/providers/aws/\";\n\nclass MyStack extends TerraformStack {\n  constructor(scope: Construct, name: string) {\n    super(scope, name);\n\n    let ENV: string = \"Devops\";\n    let COMPANY: string = \"yourCompany\";\n\n    new AwsProvider(this, \"Aws_provider\", {\n      region: \"us-east-1\",\n    });\n\n    const awsAccountid = new datasources.DataAwsCallerIdentity(this, \"aws_id\", {});\n\n    const awskmsKey = new kms.KmsKey(this, \"Aws_kms\", {\n      description: \"Create KMS encryption for creating encryption on volume\",\n      enableKeyRotation: true,\n      policy: `{\n        \"Version\": \"2012-10-17\",\n        \"Statement\": [\n          {\n            \"Sid\": \"Enable IAM User Permissions\",\n            \"Effect\": \"Allow\",\n            \"Principal\": {\n              \"AWS\": \"arn:aws:iam::${awsAccountid.id}:root\"\n          },\n            \"Action\": [\n              \"kms:*\"\n            ],\n            \"Resource\": [\n              \"*\"\n            ]\n          },    {\n            \"Sid\": \"Allow autoscalling to use the key\",\n            \"Effect\": \"Allow\",\n            \"Principal\": {\n              \"AWS\": [\n                \"arn:aws:iam::${awsAccountid.id}:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling\"\n              ]\n            },\n            \"Action\": [\n                \"kms:Create*\",\n                \"kms:Describe*\",\n                \"kms:Enable*\",\n                \"kms:List*\",\n                \"kms:Put*\",\n                \"kms:Update*\",\n                \"kms:Revoke*\",\n                \"kms:Disable*\",\n                \"kms:Get*\",\n                \"kms:Delete*\",\n                \"kms:TagResource\",\n                \"kms:UntagResource\",\n                \"kms:ScheduleKeyDeletion\",\n                \"kms:CancelKeyDeletion\"\n            ],\n            \"Resource\": \"*\"\n          },{\n            \"Sid\": \"Allow use of the key\",\n            \"Effect\": \"Allow\",\n            \"Principal\": {\n                \"AWS\": [\n                \"arn:aws:iam::${awsAccountid.id}:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling\"\n                ]\n            },\n            \"Action\": [\n                \"kms:Encrypt\",\n                \"kms:Decrypt\",\n                \"kms:ReEncrypt*\",\n                \"kms:GenerateDataKey*\",\n                \"kms:DescribeKey\"\n            ],\n            \"Resource\": \"*\"\n            },        {\n              \"Sid\": \"Allow attachment of persistent resources\",\n              \"Effect\": \"Allow\",\n              \"Principal\": {\n                  \"AWS\": [\n              \"arn:aws:iam::${awsAccountid.id}:role/aws-service-role/autoscaling.amazonaws.com/AWSServiceRoleForAutoScaling\"\n              ]\n              },\n              \"Action\": [\n                  \"kms:CreateGrant\",\n                  \"kms:ListGrants\",\n                  \"kms:RevokeGrant\"\n              ],\n              \"Resource\": \"*\",\n              \"Condition\": {\n                  \"Bool\": {\n                      \"kms:GrantIsForAWSResource\": \"true\"\n                  }\n              }\n          }\n        ]\n      }`,\n      tags: {\n        Name: \"CDKtf-TypeScript-Demo-KMS-key\",\n        Team: `${ENV}`,\n        Company: `${COMPANY}`,\n      },\n    });\n\n    new kms.KmsAlias(this, \"Aws_kms_alies\", {\n      name: `alias/${ENV}`,\n      targetKeyId: awskmsKey.id,\n    });\n    \n    new TerraformOutput(this, \"Aws_Kms_id\", {\n      value: awskmsKey.id,\n    });\n  }\n}\n\nconst app = new App();\nnew MyStack(app, \"cdktf-typescript-aws-kms\");\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-kms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmadalibagheri%2Fcdktf-typescript-aws-kms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmadalibagheri%2Fcdktf-typescript-aws-kms/lists"}