GithubHelp home page GithubHelp logo

ahmadalibagheri / cdktf-typescript-aws-s3bucket Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 1.0 208 KB

AWS S3bucket configuration with typescript and cdktf

TypeScript 21.91% JavaScript 78.09%
terraform aws typescript cdktf s3-bucket

cdktf-typescript-aws-s3bucket's Introduction

Documentation

  • Explore the Terraform for Terraform CLI >= v1.0+
  • Explore the Nodejs for npm CLI >= v14+
  • Explore the Yarn for Yarn CLI >= v1.21 (optional - NPM will work as an alternative)
  • Explore the CDK for cdktf CLI

Add your AWS credentials as two environment variables, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, replacing AAAAAA with each respective values.

$ export AWS_ACCESS_KEY_ID=AAAAAA
$ export AWS_SECRET_ACCESS_KEY=AAAAA

typescript-aws-s3bucket

A CDK for Terraform application in TypeScript for VPC configuraiton.

Usage

Install project dependencies

yarn install

Generate CDK for Terraform constructs for Terraform provides and modules used in the project.

cdktf get

You can now edit the main.ts file if you want to modify any code.

vim main.ts
import { Construct } from 'constructs';
import { App, TerraformOutput, TerraformStack } from 'cdktf';
import { AwsProvider, s3 } from './.gen/providers/aws';

class MyStack extends TerraformStack {
  constructor(scope: Construct, name: string) {
    super(scope, name);

    new AwsProvider(this, 'aws', {
      region: 'us-east-1',
    });

    const BUCKET_NAME = 'cdktf-typescript-demo-us-east-1';

    const bucket = new s3.S3Bucket(this, 'aws_s3_bucket', {
      bucket: BUCKET_NAME,
      lifecycleRule: [
        { enabled: true, id: 'abort-multipart', prefix: '/', abortIncompleteMultipartUploadDays: 7 },
        { enabled: true, transition: [{ days: 30, storageClass: 'STANDARD_IA' }] },
        { enabled: true, noncurrentVersionTransition: [{ days: 30, storageClass: 'STANDARD_IA' }] },
        { enabled: false, transition: [{ days: 90, storageClass: 'ONEZONE_IA' }] },
        { enabled: false, noncurrentVersionTransition: [{ days: 90, storageClass: 'ONEZONE_IA' }] },
        { enabled: false, transition: [{ days: 365, storageClass: 'GLACIER' }] },
        { enabled: false, noncurrentVersionTransition: [{ days: 365, storageClass: 'ONEZONE_IA' }] },
      ],
      tags: {
        Team: 'Devops',
        Company: 'Your compnay',
      },
      policy: `{
        "Version": "2012-10-17",
        "Statement": [
          {
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [
              "s3:GetObject"
            ],
            "Resource": [
              "arn:aws:s3:::${BUCKET_NAME}/*"
            ]
          }
        ]
      }`,
    });

    new TerraformOutput(this, 'S3 id', {
      value: bucket.id,
    });

    new TerraformOutput(this, 'S3 arn', {
      value: bucket.arn,
    });
  }
}

const app = new App();
new MyStack(app, 'aws-s3');
app.synth();

Compile the TypeScript application

tsc

At this step you can run code with two different way:

The first way:

Generate Terraform configuration

cdktf synth

The above command will create a folder called cdktf.out that contains all Terraform JSON configuration that was generated.

Run Terraform commands

cd cdktf.out
terraform init
terraform plan
terraform apply

The second way:

Run cdktf commands

cdktf deploy

cdktf-typescript-aws-s3bucket's People

Contributors

ahmadalibagheri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.