Search code examples
terraformcdktf

cdktf help understanding docs, in specific, bucket parameters


I am just starting my journey with cdktf / typescript and looking to create an s3 backend. This part just focuses on bucket and dynamodb lock. I have the following code which I put together, through reading docs and also running a convert on a HCL file that already served this purpose.

import { Construct } from "constructs";
import { App, TerraformStack, TerraformOutput, RemoteBackend } from "cdktf";
import { AwsProvider, ec2, s3 } from "@cdktf/provider-aws";
import { DynamodbTable } from "@cdktf/provider-aws/lib/dynamodb";

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

    new AwsProvider(this, "AWS", {
      region: "eu-central-1",
    });

    // bucket goes here
    const bucket = new s3.S3Bucket(this, 'bucket', {
      bucket: "01234-cumulus.ws",
      // lifecylcle: deprecated
      lifecycle: {preventDestroy: true},
      //versioning: deprecated
      versioning: {enabled: true},
      // encryption: deprecated
      serverSideEncryptionConfiguration: { 
        rule: {
          applyServerSideEncryptionByDefault: {
            sseAlgorithm: "AES256"
          }
        }
      },
    });

    new s3.S3BucketAcl(this, 'bucket-acl', {
      bucket: bucket.bucket,
      acl: "private",
    });

    bucket.addOverride("lifecycle", [ {
      prevent_destroy: true,
    },]);

The thing is the paramaters I have used for the bucket are marked as deprecated. Even the cdktf convert function delivers these deprecated paramaters. I have looked at docs and have worked out the acl section in the non-deprecated form.

My plea, if anyone could provide code examples for serverSideEncryptionConfiguration, versioning, prevent_destroy, lifecycle. This would give me a great start and help me better to understand the documentation with these working examples.


Solution

  • garbage in > garbage out... I was using old deprecated terraform code... therefore cdktf convert was giving me old deprecated typescript code.