Last active
March 12, 2020 12:34
-
-
Save skorfmann/d70337b2d5089884aa40e5467e89217b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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