forked from pierront/but3-iac
Bonus
This commit is contained in:
@@ -51,4 +51,5 @@ module "compute" {
|
|||||||
database_subnet_id = module.network.subnet_ids["database"]
|
database_subnet_id = module.network.subnet_ids["database"]
|
||||||
ssh_pub_key = var.ssh_pub_key
|
ssh_pub_key = var.ssh_pub_key
|
||||||
service_account_email = module.iam.service_account_email
|
service_account_email = module.iam.service_account_email
|
||||||
|
instance_count = var.compute_instance_count
|
||||||
}
|
}
|
||||||
@@ -26,4 +26,10 @@ variable "instance_type" {
|
|||||||
type = string
|
type = string
|
||||||
description = "Type of the VM instance"
|
description = "Type of the VM instance"
|
||||||
default = "e2-small"
|
default = "e2-small"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "compute_instance_count" {
|
||||||
|
type = number
|
||||||
|
description = "Number of VM instances to create"
|
||||||
|
default = 2
|
||||||
}
|
}
|
||||||
@@ -96,4 +96,50 @@ resource "google_compute_instance" "database" {
|
|||||||
email = var.service_account_email
|
email = var.service_account_email
|
||||||
scopes = ["userinfo-email", "compute-ro"]
|
scopes = ["userinfo-email", "compute-ro"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resource "google_compute_instance_template" "frontend_template" {
|
||||||
|
name = "${var.project_id}-frontend-template"
|
||||||
|
project = var.project_id
|
||||||
|
machine_type = var.instance_type
|
||||||
|
|
||||||
|
tags = ["frontend", "ssh"]
|
||||||
|
labels = merge({ tier = "frontend" }, var.labels)
|
||||||
|
|
||||||
|
metadata = {
|
||||||
|
enable-oslogin = "TRUE"
|
||||||
|
ssh-keys = var.ssh_pub_key
|
||||||
|
custom-value = "custom-metadata"
|
||||||
|
}
|
||||||
|
|
||||||
|
disk {
|
||||||
|
auto_delete = true
|
||||||
|
boot = true
|
||||||
|
source_image = "debian-cloud/debian-11"
|
||||||
|
}
|
||||||
|
|
||||||
|
network_interface {
|
||||||
|
network = var.network_id
|
||||||
|
subnetwork = var.frontend_subnet_id
|
||||||
|
access_config {}
|
||||||
|
}
|
||||||
|
|
||||||
|
service_account {
|
||||||
|
email = var.service_account_email
|
||||||
|
scopes = ["userinfo-email", "compute-ro"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
resource "google_compute_region_instance_group_manager" "frontend_mig" {
|
||||||
|
name = "${var.project_id}-frontend-mig"
|
||||||
|
project = var.project_id
|
||||||
|
region = var.region
|
||||||
|
base_instance_name = "frontend"
|
||||||
|
|
||||||
|
version {
|
||||||
|
instance_template = google_compute_instance_template.frontend_template.self_link
|
||||||
|
}
|
||||||
|
|
||||||
|
target_size = var.instance_count
|
||||||
|
}
|
||||||
|
|||||||
@@ -53,4 +53,9 @@ variable "service_account_email" {
|
|||||||
variable "labels" {
|
variable "labels" {
|
||||||
type = map(string)
|
type = map(string)
|
||||||
default = {}
|
default = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "instance_count" {
|
||||||
|
type = number
|
||||||
|
description = "Number of VM instances to create"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user