-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.py
70 lines (56 loc) · 3.29 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
import os
from aws_cdk import core
from infrastructure_cdk.network_stack import NetworkStack
from infrastructure_cdk.instance_stack import InstanceStack
from infrastructure_cdk.database_stack import DatabaseStack
from infrastructure_cdk.ecs_stack import EcsStack
from infrastructure_cdk.lambda_stack import LambdaStack
from infrastructure_cdk.container_pipeline_stack import ContainerPipelineStack
import jsii
# As part of AWS CDK v2.0, the add_warning function will be deprecated
# in favor of the Annotations.of(construct) API.
# See https://github.com/aws/aws-cdk-rfcs/blob/master/text/0192-remove-constructs-compat.md#09-logging
@jsii.implements(core.IAspect)
class CheckTerminationProtection:
def visit(self, stack):
# See that we're dealing with a stack object
if isinstance(stack, core.Stack):
# Check if termination protection is enabled on the stack
if (not stack.termination_protection):
stack.node.add_warning('This stack does not have termination protection enabled.')
with open("./user_data/user_data.sh") as f:
user_data = f.read()
app = core.App()
NETWORK = NetworkStack(
app, "NetworkStack",
env=core.Environment(account = os.environ["CDK_DEFAULT_ACCOUNT"],
region = os.environ["CDK_DEFAULT_REGION"]))
CONTAINER_PIPELINE = ContainerPipelineStack(
app, "ContainerPipelineStack",
vpc=NETWORK.vpc,
env=core.Environment(account = os.environ["CDK_DEFAULT_ACCOUNT"],
region = os.environ["CDK_DEFAULT_REGION"]))
EC2_INSTANCES = InstanceStack(app,
"InstanceStack",
vpc=NETWORK.vpc,
user_data=user_data,
env=core.Environment(account = os.environ["CDK_DEFAULT_ACCOUNT"],
region = os.environ["CDK_DEFAULT_REGION"]))
ECS_STACK = EcsStack(app,
"EcsStack",
vpc=NETWORK.vpc,
env=core.Environment(account = os.environ["CDK_DEFAULT_ACCOUNT"],
region = os.environ["CDK_DEFAULT_REGION"]))
LAMBDA_STACK = LambdaStack(app,
"LambdaStack",
env=core.Environment(account = os.environ["CDK_DEFAULT_ACCOUNT"],
region = os.environ["CDK_DEFAULT_REGION"]))
DB_INSTANCES = DatabaseStack(app,
"DatabaseStack",
vpc=NETWORK.vpc,
backend_security_groups=EC2_INSTANCES.asg.connections.security_groups,
env=core.Environment(account = os.environ["CDK_DEFAULT_ACCOUNT"],
region = os.environ["CDK_DEFAULT_REGION"]))
app.node.apply_aspect(CheckTerminationProtection())
app.synth()