-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
232 lines (186 loc) · 8.49 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
terraform {
backend "gcs" {
bucket = "terraform-state-bucket-94439"
}
required_providers {
google = {
source = "hashicorp/google"
// https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/getting_started
version = "5.33.0"
}
}
}
variable "region" {
type = string
default = "us-west1"
}
locals {
zone = "${var.region}-a"
}
variable "project_id" {
type = string
default = "firewall-426619"
}
# TODO: make these configurable stored as vars
provider "google" {
// credentials = file("<PATH_TO_YOUR_SERVICE_ACCOUNT_KEY>.json")
project = var.project_id
}
// ssh keys to access VM
variable "ssh_public_keys" {
type = list(string)
default = [
"firewall:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDCuF4IYOJjN65jbw4gbyjpmrwuuUNkTWJ4PiMXW4rgiq2iwpgdaxz6UCq3LtOpG0+lYuLFhDiuSCA9DRQsktGStt9+jJDvjVD3RJZpBJedusZNQJ1RnC8/jje8KQjjbFOJXcBxyLP96jzi112lh/qUCjk8cMgiUg3xGQq/esY7125oiZFV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svVrAUL86Z4Kszcs7kUKXGgUkKOhVSiCkXEUAXzmq6SdsgYkpgps7PAoi5E1DzIv5DmLSlJV047wNTlF9xnR9p+/Z3IbrQ3LSaRLDVBt3mFTBVVpkEobXveBd+7dVM5HTRqb9Ktitn+lS66tCp3bodzmL9lTP5Hw== test",
]
}
# test delete bucket
# resource "google_storage_bucket" "test-bucket" {
# name = "test-bucket-9777"
# location = "us-west2"
# }
data "google_service_account" "virtual_machine_sa" {
# NOTE: must match what is defined in admin terraform
account_id = "virtual-machine-sa"
}
# resource "google_pubsub_topic" "test_infra" {
# name = "test-infra-topic"
# labels = {
# test = "infra"
# }
# message_retention_duration = "86600s"
# }
# resource "google_compute_address" "static_ip" {
# name = "firewall"
# region = var.region
# }
# resource "google_compute_address" "static_ip_replica" {
# name = "firewall-replica"
# region = var.region
# }
# test delete vm
# resource "google_compute_instance" "e2_micro" {
# name = "e2-micro-instance"
# machine_type = "e2-micro"
# # see: https://cloud.google.com/free/docs/free-cloud-features#always-free-usage-limits
# zone = local.zone
# /*
# Fixes (which wasn't encountered in this repo, only in iac repo 🤔):
# ╷
# │ Error: Changing the machine_type, min_cpu_platform, service_account, enable_display, shielded_instance_config, scheduling.node_affinities or network_interface.[#d].(network/subnetwork/subnetwork_project) or advanced_machine_features on a started instance requires stopping it. To acknowledge this, please set allow_stopping_for_update = true in your config. You can also stop it by setting desired_status = "TERMINATED", but the instance will not be restarted after the update.
# │
# │ with google_compute_instance.e2_micro,
# │ on main.tf line 51, in resource "google_compute_instance" "e2_micro":
# │ 51: resource "google_compute_instance" "e2_micro" {
# │
# ╵
# */
# allow_stopping_for_update = true
# boot_disk {
# initialize_params {
# image = "debian-cloud/debian-11"
# }
# }
# metadata_startup_script = <<EOF
# #!/bin/bash
# # installation directions here: https://docs.docker.com/engine/install/debian/
# # Add Docker's official GPG key:
# sudo apt-get update
# sudo apt-get install -y ca-certificates curl
# sudo install -m 0755 -d /etc/apt/keyrings
# sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
# sudo chmod a+r /etc/apt/keyrings/docker.asc
# # Add the repository to Apt sources:
# echo \
# "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
# $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
# sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# sudo apt-get update
# # To install the latest version, run:
# sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# # Verify that the installation is successful by running the hello-world image:
# sudo docker run hello-world
# # allow firewall user to run docker commands
# sudo groupadd docker
# sudo usermod -aG docker firewall
# EOF
# network_interface {
# network = "default"
# access_config {
# nat_ip = google_compute_address.static_ip.address
# }
# }
# metadata = {
# username = "firewall"
# ssh-keys = join(" \n", var.ssh_public_keys)
# }
# service_account {
# email = data.google_service_account.virtual_machine_sa.email
# scopes = ["https://www.googleapis.com/auth/cloud-platform"]
# }
# tags = ["testnet", "sequencer"]
# }
# output "static_ip_address" {
# value = google_compute_address.static_ip.address
# }
# resource "google_compute_instance" "e2_micro_replica" {
# name = "e2-micro-instance-replica"
# machine_type = "e2-micro"
# # see: https://cloud.google.com/free/docs/free-cloud-features#always-free-usage-limits
# zone = local.zone
# /*
# Fixes (which wasn't encountered in this repo, only in iac repo 🤔):
# ╷
# │ Error: Changing the machine_type, min_cpu_platform, service_account, enable_display, shielded_instance_config, scheduling.node_affinities or network_interface.[#d].(network/subnetwork/subnetwork_project) or advanced_machine_features on a started instance requires stopping it. To acknowledge this, please set allow_stopping_for_update = true in your config. You can also stop it by setting desired_status = "TERMINATED", but the instance will not be restarted after the update.
# │
# │ with google_compute_instance.e2_micro,
# │ on main.tf line 51, in resource "google_compute_instance" "e2_micro":
# │ 51: resource "google_compute_instance" "e2_micro" {
# │
# ╵
# */
# allow_stopping_for_update = true
# boot_disk {
# initialize_params {
# image = "debian-cloud/debian-11"
# }
# }
# metadata_startup_script = <<EOF
# #!/bin/bash
# # installation directions here: https://docs.docker.com/engine/install/debian/
# # Add Docker's official GPG key:
# sudo apt-get update
# sudo apt-get install -y ca-certificates curl
# sudo install -m 0755 -d /etc/apt/keyrings
# sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
# sudo chmod a+r /etc/apt/keyrings/docker.asc
# # Add the repository to Apt sources:
# echo \
# "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
# $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
# sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# sudo apt-get update
# # To install the latest version, run:
# sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# # Verify that the installation is successful by running the hello-world image:
# sudo docker run hello-world
# # allow firewall user to run docker commands
# sudo groupadd docker
# sudo usermod -aG docker firewall
# EOF
# network_interface {
# network = "default"
# access_config {
# nat_ip = google_compute_address.static_ip_replica.address
# }
# }
# metadata = {
# username = "firewall"
# ssh-keys = join(" \n", var.ssh_public_keys)
# }
# # service_account {
# # email = data.google_service_account.virtual_machine_sa.email
# # scopes = ["https://www.googleapis.com/auth/cloud-platform"]
# # }
# tags = ["testnet", "replica"]
# }