Skip to content

Commit c58deeb

Browse files
committed
Support VM
1 parent ae9da60 commit c58deeb

File tree

9 files changed

+169
-5
lines changed

9 files changed

+169
-5
lines changed

terraform/main.tf

+16
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,19 @@ module "backend_elastic_search" {
3535

3636

3737
}
38+
39+
module "backend_pos_vm" {
40+
module_wide_prefix_scope = "${var.config_release_name}-vm"
41+
source = "./modules/posvm"
42+
43+
depends_on = [module.backend_elastic_search]
44+
45+
// Region and zone
46+
vm_default_zone = var.config_gcp_default_zone
47+
vm_pos_boot_image = var.config_vm_pos_boot_image
48+
vm_pos_boot_disk_size = var.config_vm_pos_boot_disk_size
49+
vm_pos_machine_type = var.config_vm_pos_machine_type
50+
gs_etl = var.config_gs_etl
51+
vm_elasticsearch_uri = module.backend_elastic_search.elasticsearch_vm_name
52+
53+
}

terraform/modules/elasticsearch/main.tf

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ resource "google_service_account" "gcp_service_acc_apis" {
1717

1818

1919
resource "google_compute_instance" "elasticsearch_etl" {
20-
name = "${var.module_wide_prefix_scope}-elastic-search-template-${random_string.random.result}"
20+
name = "${var.module_wide_prefix_scope}-elastic-search-server-${random_string.random.result}"
2121
machine_type = "custom-${var.vm_elastic_search_vcpus}-${var.vm_elastic_search_mem}"
2222
zone = var.vm_default_zone
2323
allow_stopping_for_update = true
@@ -31,16 +31,13 @@ name = "${var.module_wide_prefix_scope}-elastic-search-template-${random_string.
3131
}
3232
}
3333

34-
3534
network_interface {
3635
network = "default"
3736
access_config {
3837
network_tier = "PREMIUM"
3938
}
4039
}
4140

42-
43-
4441
metadata = {
4542
startup-script = templatefile(
4643
"${path.module}/scripts/elasticsearch_startup.sh",
+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
1+
output "elasticsearch_vm_name" {
2+
value = google_compute_instance.elasticsearch_etl.name
3+
}

terraform/modules/posvm/main.tf

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
resource "random_string" "random" {
2+
length = 8
3+
lower = true
4+
upper = false
5+
special = false
6+
keepers = {
7+
vm_pos_boot_disk_size = var.vm_pos_boot_disk_size
8+
}
9+
}
10+
11+
12+
resource "google_service_account" "gcp_service_acc_apis" {
13+
account_id = "${var.module_wide_prefix_scope}-svc-${random_string.random.result}"
14+
display_name = "${var.module_wide_prefix_scope}-GCP-service-account"
15+
}
16+
17+
18+
19+
resource "google_compute_instance" "pos_vm" {
20+
name = "${var.module_wide_prefix_scope}-support-vm-${random_string.random.result}"
21+
machine_type = var.vm_pos_machine_type
22+
zone = var.vm_default_zone
23+
allow_stopping_for_update = true
24+
can_ip_forward = true
25+
26+
boot_disk {
27+
initialize_params {
28+
image = "${var.vm_pos_boot_image}"
29+
type = "pd-ssd"
30+
size = "${var.vm_pos_boot_disk_size}"
31+
}
32+
}
33+
34+
35+
network_interface {
36+
network = "default"
37+
access_config {
38+
network_tier = "PREMIUM"
39+
}
40+
}
41+
42+
metadata = {
43+
startup-script = templatefile(
44+
"${path.module}/scripts/load_data.sh",
45+
{
46+
ELASTICSEARCH_URI = "${var.vm_elasticsearch_uri}"
47+
}
48+
)
49+
google-logging-enabled = true
50+
}
51+
52+
service_account {
53+
email = google_service_account.gcp_service_acc_apis.email
54+
scopes = [ "cloud-platform" ]
55+
}
56+
}

terraform/modules/posvm/outputs.tf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "pos_support_vm_name" {
2+
value = google_compute_instance.pos_vm.name
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# Startup script for Elastic Search VM Instance
3+
4+
echo "---> [LAUNCH] POS support VM"
5+
6+
sudo apt update && sudo apt -y install python3-pip
7+
sudo pip3 install elasticsearch-loader
8+
9+
10+
echo "test cinzia"
11+
echo $ELASTICSEARCH_URI
12+
13+
echo $$ELASTICSEARCH_URI
14+
echo $strin

terraform/modules/posvm/variables.tf

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// --- Module input parameters --- //
2+
// General deployment input parameters --- //
3+
variable "module_wide_prefix_scope" {
4+
description = "The prefix provided here will scope names for those resources created by this module, default 'otpdeves'"
5+
type = string
6+
default = "otdevpos"
7+
}
8+
9+
// --- ETL info --- //
10+
variable "gs_etl" {
11+
description = "Output of the ETL [root]. Eg. open-targets-data-releases/21.04/output"
12+
type = string
13+
}
14+
15+
// --- VM info --- //
16+
variable "vm_pos_boot_image" {
17+
description = "Boot image configuration for POS VM"
18+
type = string
19+
default = "debian-10"
20+
}
21+
22+
variable "vm_default_zone" {
23+
description = "Default zone when not specified in the module"
24+
type = string
25+
}
26+
27+
variable "vm_pos_boot_disk_size" {
28+
description = "POS VM boot disk size, default '500GB'"
29+
type = string
30+
default = 500
31+
}
32+
33+
variable "vm_pos_machine_type" {
34+
description = "Machine type for POS vm"
35+
type = string
36+
}
37+
38+
variable "vm_elasticsearch_uri" {
39+
description = "Elasticsearch Server"
40+
type = string
41+
}

terraform/outputs.tf

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
output "elasticsearch_vm_name" {
2+
value = module.backend_elastic_search.elasticsearch_vm_name
3+
}
4+
5+
output "pos_support_vm_name" {
6+
value = module.backend_pos_vm.pos_support_vm_name
7+
}

terraform/variables.tf

+28
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ variable "config_project_id" {
1919
type = string
2020
}
2121

22+
// --- ETL info --- //
23+
variable "config_gs_etl" {
24+
description = "Output of the ETL [root]. Eg. open-targets-data-releases/21.04/output"
25+
type = string
26+
}
27+
2228
// --- Elastic Search Configuration --- //
2329

2430
variable "config_vm_elastic_boot_image" {
@@ -47,3 +53,25 @@ variable "config_vm_elastic_search_boot_disk_size" {
4753
description = "Boot disk size to use for the deployed Elastic Search Instances"
4854
type = string
4955
}
56+
57+
58+
// --- POS VM Configuration --- //
59+
60+
variable "config_vm_pos_boot_image" {
61+
description = "Boot image configuration for POS VM"
62+
type = string
63+
default = "debian-10"
64+
}
65+
66+
67+
variable "config_vm_pos_boot_disk_size" {
68+
description = "POS VM boot disk size, default '500GB'"
69+
type = string
70+
default = 500
71+
}
72+
73+
variable "config_vm_pos_machine_type" {
74+
description = "Machine type for POS vm"
75+
type = string
76+
default = "projects/cos-cloud/global/images/family/debian-cloud"
77+
}

0 commit comments

Comments
 (0)