Skip to content

Instantly share code, notes, and snippets.

@skorfmann
Last active March 12, 2020 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skorfmann/d70337b2d5089884aa40e5467e89217b to your computer and use it in GitHub Desktop.
Save skorfmann/d70337b2d5089884aa40e5467e89217b to your computer and use it in GitHub Desktop.
import { Construct, Tag } from '@aws-cdk/core';
import { App, Stack } from '../../../packages/@terrastack/core';
import { AwsProvider, AwsS3Bucket, AwsIamPolicy } from '../.generated/aws';
import { PolicyDocument, PolicyStatement, AnyPrincipal, Effect } from "@aws-cdk/aws-iam"
const app = new App();
class MyBucketStack extends Stack {
constructor(scope: Construct, ns: string) {
super(scope, ns);
// Generated from Terraform Provider JSON Schema
new AwsProvider(this, 'aws', {
region: 'eu-central-1'
})
// Generated from Terraform Provider JSON Schema
const bucket = new AwsS3Bucket(this, 'hello', {
bucket: 'world'
});
// Note: This is a CDK resource, which is perfectly usable in Terrastack - See https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iam.PolicyDocument.html
const bucketPolicyDocument = new PolicyDocument({
statements: [
new PolicyStatement({
effect: Effect.ALLOW,
principals: [new AnyPrincipal()],
actions: [
"s3:Get*"
],
// Note: This generates a valid Terraform reference
resources: [bucket.arn]
})
]
})
// Generated from Terraform Provider JSON Schema
new AwsIamPolicy(this, "helloPolicy", {
name: "hello-bucket",
policy: JSON.stringify(bucketPolicyDocument.toJSON())
})
}
}
const stack = new MyBucketStack(app, 'my-s3-bucket-stack');
// Note: This a CDK which works here as well - https://docs.aws.amazon.com/cdk/latest/guide/tagging.html
Tag.add(stack, 'StackType', 'Terraform');
// Generate Terraform JSON
app.synth();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment