This repository has been archived by the owner on Mar 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
/
main.tf
163 lines (127 loc) · 4.39 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
terraform {
# This module is now only being tested with Terraform 1.0.x. However, to make upgrading easier, we are setting
# 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it
# forwards compatible with 1.0.x code.
required_version = ">= 0.12.26"
}
# ---------------------------------------------------------------------------------------------------------------------
# Create a Management Network for shared services
# ---------------------------------------------------------------------------------------------------------------------
module "management_network" {
# When using these modules in your own templates, you will need to use a Git URL with a ref attribute that pins you
# to a specific version of the modules, such as the following example:
# source = "github.com/gruntwork-io/terraform-google-network.git//modules/vpc-network?ref=v0.1.2"
source = "./modules/vpc-network"
name_prefix = var.name_prefix
project = var.project
region = var.region
}
# ---------------------------------------------------------------------------------------------------------------------
# Create instances to tag & test connectivity with
# ---------------------------------------------------------------------------------------------------------------------
data "google_compute_zones" "available" {
project = var.project
region = var.region
}
// This instance acts as an arbitrary internet address for testing purposes
resource "google_compute_instance" "default_network" {
name = "${var.name_prefix}-default-network"
machine_type = "n1-standard-1"
zone = data.google_compute_zones.available.names[0]
project = var.project
allow_stopping_for_update = true
boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
network_interface {
network = "default"
access_config {
// Ephemeral IP
}
}
}
resource "google_compute_instance" "public_with_ip" {
name = "${var.name_prefix}-public-with-ip"
machine_type = "n1-standard-1"
zone = data.google_compute_zones.available.names[0]
project = var.project
allow_stopping_for_update = true
tags = [module.management_network.public]
boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
network_interface {
subnetwork = module.management_network.public_subnetwork
access_config {
// Ephemeral IP
}
}
}
resource "google_compute_instance" "public_without_ip" {
name = "${var.name_prefix}-public-without-ip"
machine_type = "n1-standard-1"
zone = data.google_compute_zones.available.names[0]
project = var.project
allow_stopping_for_update = true
tags = [module.management_network.public]
boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
network_interface {
subnetwork = module.management_network.public_subnetwork
}
}
resource "google_compute_instance" "private_public" {
name = "${var.name_prefix}-private-public"
machine_type = "n1-standard-1"
zone = data.google_compute_zones.available.names[0]
project = var.project
allow_stopping_for_update = true
tags = [module.management_network.private]
boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
network_interface {
subnetwork = module.management_network.public_subnetwork
}
}
resource "google_compute_instance" "private" {
name = "${var.name_prefix}-private"
machine_type = "n1-standard-1"
zone = data.google_compute_zones.available.names[0]
project = var.project
allow_stopping_for_update = true
tags = [module.management_network.private]
boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
network_interface {
subnetwork = module.management_network.private_subnetwork
}
}
resource "google_compute_instance" "private_persistence" {
name = "${var.name_prefix}-private-persistence"
machine_type = "n1-standard-1"
zone = data.google_compute_zones.available.names[0]
project = var.project
allow_stopping_for_update = true
tags = [module.management_network.private_persistence]
boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
network_interface {
subnetwork = module.management_network.private_subnetwork
}
}