-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
main.tf
134 lines (124 loc) · 4.35 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
/**
* Copyright 2019 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.
*/
# [START vpc_shared_vpc_host_project_enable]
resource "google_compute_shared_vpc_host_project" "host" {
project = var.project # Replace this with your host project ID in quotes
}
# [END vpc_shared_vpc_host_project_enable]
# [START vpc_shared_vpc_service_project_attach]
resource "google_compute_shared_vpc_service_project" "service1" {
host_project = google_compute_shared_vpc_host_project.host.project
service_project = var.service_project # Replace this with your service project ID in quotes
}
# [END vpc_shared_vpc_service_project_attach]
# [START compute_shared_data_network]
data "google_compute_network" "network" {
name = "my-network-123"
project = var.project
}
# [END compute_shared_data_network]
# [START compute_shared_data_subnet]
data "google_compute_subnetwork" "subnet" {
name = "my-subnet-123"
project = var.project
region = "us-central1"
}
# [END compute_shared_data_subnet]
# [START compute_shared_internal_ip_create]
resource "google_compute_address" "internal" {
project = var.service_project
region = "us-central1"
name = "int-ip"
address_type = "INTERNAL"
address = "10.0.0.8"
subnetwork = data.google_compute_subnetwork.subnet.self_link
}
# [END compute_shared_internal_ip_create]
# [START compute_shared_instance_with_reserved_ip_create]
resource "google_compute_instance" "reserved_ip" {
project = var.service_project
zone = "us-central1-a"
name = "reserved-ip-instance"
machine_type = "e2-medium"
boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
network_interface {
subnetwork = data.google_compute_subnetwork.subnet.self_link
network_ip = google_compute_address.internal.address
}
}
# [END compute_shared_instance_with_reserved_ip_create]
# [START compute_shared_instance_with_ephemeral_ip_create]
resource "google_compute_instance" "ephemeral_ip" {
project = var.service_project
zone = "us-central1-a"
name = "my-vm"
machine_type = "e2-medium"
boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
network_interface {
subnetwork = data.google_compute_subnetwork.subnet.self_link
}
}
# [END compute_shared_instance_with_ephemeral_ip_create]
# [START compute_shared_instance_template_create]
resource "google_compute_instance_template" "default" {
project = var.service_project
name = "appserver-template"
description = "This template is used to create app server instances."
machine_type = "n1-standard-1"
disk {
source_image = "debian-cloud/debian-9"
}
network_interface {
subnetwork = data.google_compute_subnetwork.subnet.self_link
}
}
# [END compute_shared_instance_template_create]
resource "google_compute_region_health_check" "default" {
name = "l4-ilb-hc"
region = "europe-west1"
http_health_check {
port = "80"
}
}
resource "google_compute_region_backend_service" "default" {
name = "l4-ilb-backend-subnet"
region = "europe-west1"
protocol = "TCP"
load_balancing_scheme = "INTERNAL"
health_checks = [google_compute_region_health_check.default.id]
}
# [START compute_shared_forwarding_rule_l4_ilb]
resource "google_compute_forwarding_rule" "default" {
project = var.service_project
name = "l4-ilb-forwarding-rule"
backend_service = google_compute_region_backend_service.default.id
region = "europe-west1"
ip_protocol = "TCP"
load_balancing_scheme = "INTERNAL"
all_ports = true
allow_global_access = true
network = data.google_compute_network.network.self_link
subnetwork = data.google_compute_subnetwork.subnet.self_link
}
# [END compute_shared_forwarding_rule_l4_ilb]