0

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.

cumulus.ws
  • 31
  • 5

1 Answers1

-1

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

cumulus.ws
  • 31
  • 5
  • Please copy the answer here so other can benefit even if the link dies. – Mickle Foretic Aug 14 '22 at 20:00
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 14 '22 at 20:01
  • lol, i think stackoverflow will die long before reddit... by the time the same question had about 2000 reads on reddit, it was sitting on 11 here – cumulus.ws Sep 17 '22 at 08:16
  • https://www.reddit.com/r/Terraform/comments/wiihz1/comment/ijciaq8/?utm_source=share&utm_medium=web2x&context=3 for reference – Nigel Sheridan-Smith Mar 09 '23 at 01:14