-
Notifications
You must be signed in to change notification settings - Fork 550
/
Copy pathmain.tf
185 lines (156 loc) · 4.95 KB
/
main.tf
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/**
* Copyright 2018 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
locals {
subnet_01 = "${var.network_name}-subnet-01"
subnet_02 = "${var.network_name}-subnet-02"
}
/******************************************
Host Project Creation
*****************************************/
module "host-project" {
source = "../../"
random_project_id = true
name = var.host_project_name
org_id = var.organization_id
folder_id = var.folder_id
billing_account = var.billing_account
enable_shared_vpc_host_project = true
default_network_tier = var.default_network_tier
}
/******************************************
Network Creation
*****************************************/
module "vpc" {
source = "terraform-google-modules/network/google"
version = "~> 2.5.0"
project_id = module.host-project.project_id
network_name = var.network_name
delete_default_internet_gateway_routes = true
subnets = [
{
subnet_name = local.subnet_01
subnet_ip = "10.10.10.0/24"
subnet_region = "us-west1"
},
{
subnet_name = local.subnet_02
subnet_ip = "10.10.20.0/24"
subnet_region = "us-west1"
subnet_private_access = true
subnet_flow_logs = true
},
]
secondary_ranges = {
(local.subnet_01) = [
{
range_name = "${local.subnet_01}-01"
ip_cidr_range = "192.168.64.0/24"
},
{
range_name = "${local.subnet_01}-02"
ip_cidr_range = "192.168.65.0/24"
},
]
(local.subnet_02) = [
{
range_name = "${local.subnet_02}-01"
ip_cidr_range = "192.168.66.0/24"
},
]
}
}
/******************************************
Service Project Creation
*****************************************/
module "service-project" {
source = "../../modules/svpc_service_project"
name = var.service_project_name
random_project_id = false
org_id = var.organization_id
folder_id = var.folder_id
billing_account = var.billing_account
shared_vpc = module.host-project.project_id
shared_vpc_subnets = module.vpc.subnets_self_links
activate_apis = [
"compute.googleapis.com",
"container.googleapis.com",
"dataproc.googleapis.com",
"dataflow.googleapis.com",
]
disable_services_on_destroy = false
}
/******************************************
Second Service Project Creation
*****************************************/
module "service-project-b" {
source = "../../modules/svpc_service_project"
name = "b-${var.service_project_name}"
random_project_id = false
org_id = var.organization_id
folder_id = var.folder_id
billing_account = var.billing_account
shared_vpc = module.host-project.project_id
activate_apis = [
"compute.googleapis.com",
"container.googleapis.com",
"dataproc.googleapis.com",
]
activate_api_identities = [{
api = "healthcare.googleapis.com"
roles = [
"roles/healthcare.serviceAgent",
"roles/bigquery.jobUser",
]
}]
disable_services_on_destroy = false
}
/******************************************
Third Service Project Creation
To test the grant_services_network_role
*****************************************/
module "service-project-c" {
source = "../../modules/svpc_service_project"
name = "c-${var.service_project_name}"
random_project_id = false
org_id = var.organization_id
folder_id = var.folder_id
billing_account = var.billing_account
shared_vpc = module.host-project.project_id
activate_apis = [
"compute.googleapis.com",
"container.googleapis.com",
"dataproc.googleapis.com",
]
activate_api_identities = [{
api = "healthcare.googleapis.com"
roles = [
"roles/healthcare.serviceAgent",
"roles/bigquery.jobUser",
]
}]
disable_services_on_destroy = false
grant_services_network_role = false
}
/******************************************
Example dependency on service-project
*****************************************/
resource "google_compute_address" "example_address" {
project = module.service-project.project_id
region = "us-west1"
subnetwork = module.vpc.subnets_self_links[0]
name = "test-address"
address_type = "INTERNAL"
}