-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
74 lines (65 loc) · 2.16 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
import { ArchiveProvider } from '@cdktf/provider-archive/lib/provider'
import { GoogleProvider } from '@cdktf/provider-google/lib/provider'
import { StorageBucket } from '@cdktf/provider-google/lib/storage-bucket'
import { App, GcsBackend, TerraformHclModule, TerraformStack } from 'cdktf'
import { Construct } from 'constructs'
import config from './config'
import { HelloWorldResources } from './lib/hello-world'
export interface Environment {
envName: string
projectId: string
projectNumber: string
systemName: string
defaultRegion: string
}
export class CdktfGcfSampleStack extends TerraformStack {
constructor(scope: Construct, id: string) {
super(scope, id)
const env: Environment = {
envName: config.ENV_NAME,
projectId: config.PROJECT_ID,
projectNumber: config.PROJECT_NUMBER,
systemName: 'cdktf-gcf-sample',
defaultRegion: 'asia-northeast1',
}
new GoogleProvider(this, 'google-provider', {
project: env.projectId,
region: env.defaultRegion,
})
new ArchiveProvider(this, 'archive-provider')
new GcsBackend(this, {
bucket: config.TF_STATE_BUCKET,
})
const enableApis = new TerraformHclModule(this, 'enable-apis', {
source:
'terraform-google-modules/project-factory/google//modules/project_services',
variables: {
disable_services_on_destroy: true,
project_id: env.projectId,
enable_apis: true,
activate_apis: [
'artifactregistry.googleapis.com',
'cloudbuild.googleapis.com',
'cloudfunctions.googleapis.com',
'logging.googleapis.com',
'pubsub.googleapis.com',
'run.googleapis.com',
],
},
})
// Cloud Functions Uploads Bucket
const gcfUploadsBucket = new StorageBucket(this, 'gcf-uploads-bucket', {
name: `gcf-v2-uploads-${env.projectNumber}-${env.defaultRegion}`,
location: env.defaultRegion,
uniformBucketLevelAccess: true,
})
new HelloWorldResources(this, 'hello-world', {
env,
gcfUploadsBucket,
dependsOn: [enableApis],
})
}
}
const app = new App()
new CdktfGcfSampleStack(app, 'cdktf-gcf-sample')
app.synth()