-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.ts
145 lines (126 loc) · 5.63 KB
/
main.ts
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { Construct } from 'constructs';
import { App, TerraformStack, S3Backend } from 'cdktf';
import { AwsProvider, DataAwsAvailabilityZones } from './.gen/providers/aws';
import { AwsVpc,
AwsIam,
AwsEksGroups,
// AwsSecure
} from './lib/aws';
// import { AzurermProvider, ResourceGroup } from './.gen/providers/azurerm';
// import { AzureNetwork, AzureAksGroups } from './lib/azure';
const config = require('config');
const stackName = config.get('StackName');
const tags = config.get('Tags');
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
class AwsInfra extends TerraformStack {
constructor(scope: Construct, name: string ) {
super(scope, name);
new S3Backend(this, {
region: config.get('Backend.Region'),
bucket: config.get('Backend.Bucket'),
key: "cdktf-samples/terraform.aws-infra.tfstate"
});
const awsProvider = new AwsProvider(this, 'aws', {
region: config.get('Providers.Aws.Regions')[0],
});
const azs = new DataAwsAvailabilityZones(this, 'azs', {
provider: awsProvider,
state: 'available',
});
new AwsIam(this, 'awsIam', {
name: stackName,
region: config.get('Providers.Aws.Regions')[0],
});
new AwsVpc(this, 'awsVpc', {
name: stackName,
region: config.get('Providers.Aws.Regions')[0],
cidr: config.get('Providers.Aws.Vpc.cidr'),
azs,
privateSubnets: config.get('Providers.Aws.Vpc.privateSubnets'),
publicSubnets: config.get('Providers.Aws.Vpc.publicSubnets'),
isolatedSubnets: config.get('Providers.Aws.Vpc.isolatedSubnets'),
enableNatGateway: config.get('Providers.Aws.Vpc.enableNatGateway'),
eksClusterName: config.get('Providers.Aws.Eks.name'),
tags,
});
// new AzureAksGroups(this, 'azureAksGroups', {
// name: stackName,
// region: config.get('Providers.Azure.Regions')[0],
// resourceGroup,
// clusterName: config.get('Providers.Azure.Aks.name'),
// version: config.get('Providers.Azure.Aks.version'),
// instanceType: config.get('Providers.Azure.Aks.instanceType')[0],
// instanceCount: config.get('Providers.Azure.Aks.instanceCount'),
// dnsPrefix: config.get('Providers.Azure.Aks.dnsPrefix'),
// azureNetwork: azureNetwork.azureNetwork,
// azurePrivateSubnetIds: azureNetwork.azurePrivateSubnetIds,
// tags,
// });
///////////////////////////////////////////////////////////////////
////////////////// Deployments ///////////////////////
// new AwsEksDeployment(this, 'awsEksDeployment', {
// name: stackName,
// region: config.get('Providers.Aws.Regions')[0],
// sourceRepoName: config.get('Providers.Aws.Eks.Deployment.sourceRepoName'),
// sourceRepoBranch: config.get('Providers.Aws.Eks.Deployment.sourceRepoBranch'),
// buildProjectName: config.get('Providers.Aws.Eks.Deployment.buildProjectName'),
// environmentType: config.get('Providers.Aws.Eks.instanceCount'),
// tags,
// });
}
}
class AwsEks extends TerraformStack {
constructor(scope: Construct, name: string ) {
super(scope, name);
new S3Backend(this, {
region: config.get('Backend.Region'),
bucket: config.get('Backend.Bucket'),
key: "cdktf-samples/terraform.aws-eks.tfstate"
});
new AwsProvider(this, 'aws', {
region: config.get('Providers.Aws.Regions')[0],
});
new AwsEksGroups(this, 'awsEksGroups', {
name: stackName,
clusterName: config.get('Providers.Aws.Eks.name'),
version: config.get('Providers.Aws.Eks.version'),
instanceType: config.get('Providers.Aws.Eks.instanceType')[0],
instanceCount: config.get('Providers.Aws.Eks.instanceCount'),
subnetIds: ['subnet-0cf9b89829411f5ab', 'subnet-036de13322627718d'],
vpc: 'vpc-07b267eed8bc13b60',
environmentType: config.get('Providers.Aws.Eks.instanceCount'),
tags,
});
}
}
class AzureInfra extends TerraformStack {
constructor(scope: Construct, name: string ) {
super(scope, name);
// new AzurermProvider(this, 'azure', {
// features: [{}]
// });
// const resourceGroup = new ResourceGroup(this, 'resource_group', {
// location: config.get('Providers.Azure.Regions')[0],
// name: stackName,
// });
// const azureNetwork = new AzureNetwork(this, 'azureNetwork', {
// name: stackName,
// region: config.get('Providers.Azure.Regions')[0],
// resourceGroup,
// cidr: config.get('Providers.Azure.Network.cidr'),
// azNames: azs.names,
// privateSubnets: config.get('Providers.Azure.Network.privateSubnets'),
// publicSubnets: config.get('Providers.Azure.Network.publicSubnets'),
// infraSubnets: config.get('Providers.Azure.Network.infraSubnets'),
// natSubnets: config.get('Providers.Azure.Network.natSubnets'),
// enableNatGateway: config.get('Providers.Azure.Network.enableNatGateway'),
// tags,
// });
}
}
const app = new App();
new AwsInfra(app, 'aws-infra');
new AwsEks(app, 'aws-eks');
new AzureInfra(app, 'azure-infra');
app.synth();