Created
February 8, 2021 22:03
-
-
Save kondor6c/b6905e76fbdc2c70dcb0d95d2c43d9a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "google_compute_subnetwork" "specified_subnetwork" { | |
name = "${var.subnet_name}-${local.subnet_number}" | |
} | |
data "google_compute_default_service_account" "default" { | |
} | |
data "google_compute_network" "specified_network" { | |
name = var.network_name | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module "bastion_bundle" { | |
source = "../../../modules/bundled_compute" | |
project_id = var.project_id | |
project_name = "example" | |
project_space = "simple" # common/shared | |
project_stage = basename(abspath("../")) | |
project_environment = "uc1" | |
scaling_class = "n2-standard-2" | |
network_name = "common-main" | |
shell_bootstrap_location = "../../../terraform/gcp/templates/example.sh" | |
extra_disks = [ | |
{ extra_disk_size="100", extra_disk_type="pd-ssd" } | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
locals { | |
local_ssd_types = [ "n2", "n2d", "n1", "c2", "m2", "a2" ] | |
host_disk = tolist([ | |
for d in split("-", var.scaling_class) : | |
{ | |
disk_size_gb = "375", | |
boot = "false", | |
auto_delete = "false", | |
disk_type = "local-ssd", | |
type = "SCRATCH" | |
} if contains(local.local_ssd_types, d) ]) | |
disks = tolist([ | |
for i in var.extra_disks: { | |
disk_size_gb = i.extra_disk_size, | |
disk_type = i.extra_disk_type, | |
auto_delete = "true", | |
boot = "false", | |
type = "PERSISTENT" | |
} | |
]) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module "example_machine" { | |
source = "terraform-google-modules/vm/google//modules/instance_template" | |
name_prefix = var.project_name | |
project_id = var.project_id | |
machine_type = var.scaling_class | |
source_image_family = var.image_family | |
source_image_project = var.image_project | |
disk_size_gb = var.boot_size | |
preemptible = var.preempt | |
network = data.google_compute_network.specified_network.name | |
subnetwork = data.google_compute_subnetwork.specified_subnetwork.name | |
tags = concat([var.project_name], var.tags) | |
labels = var.labels | |
metadata = merge(var.metadata, {"VmDnsSetting" = "ZonalPreferred", "user-data" = data.template_cloudinit_config.cinit.rendered } ) | |
startup_script = data.template_file.provider_bootstrap_script.rendered | |
auto_delete = true | |
additional_disks = concat(local.disks, local.host_disk) | |
service_account = { | |
email = data.google_compute_default_service_account.default.email | |
scopes = ["storage-ro", "logging-write", "monitoring-write", "service-management", "compute-rw"] | |
} | |
} | |
module "example_mig" { | |
depends_on = [ null_resource.delay ] | |
source = "terraform-google-modules/vm/google//modules/mig" | |
project_id = var.project_id | |
region = var.region | |
min_replicas = var.scaling_min | |
max_replicas = var.scaling_max | |
target_size = var.scaling_desired | |
target_pools = [ google_compute_target_pool.service.self_link ] | |
stateful_disks = tolist([ | |
for i in range(length(var.extra_disks)) : | |
{ device_name = format("persistent-disk-%d", i), delete_rule="NEVER" } | |
]) | |
hostname = "${var.project_space}-${var.project_name}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "region" { | |
type = string | |
description = "google region" | |
default = "us-central1" | |
} | |
variable "project_id" { | |
type = string | |
description = "google project id to use" | |
} | |
variable "project_name" { | |
type = string | |
description = "this will be the primary name, should be unique to the project space" | |
} | |
variable "project_space" { | |
type = string | |
description = "this will be *prepended* before most assets created, this might be the larger scope that the resources belong to" | |
} | |
variable "project_stage" { | |
type = string | |
description = "dev/prod/qa/test/demo/sales" | |
} | |
variable "project_environment" { | |
type = string | |
} | |
variable "preempt" { | |
type = bool | |
default = true | |
description = "possibly preemptively shutdown the machine, but run at a much lower cost" | |
} | |
variable "cloud_policy_permissions" { | |
description = "the size of the stateful disk to keep around" | |
type = list(string) | |
default = [ | |
"https://www.googleapis.com/auth/compute.readonly", | |
"https://www.googleapis.com/auth/monitoring.write", | |
"https://www.googleapis.com/auth/logging.write", | |
"https://www.googleapis.com/auth/devstorage.read_only", | |
] | |
} | |
variable "boot_size" { | |
description = "The size of the boot disk, larger sizes = higher performance and cost" | |
default = 20 | |
type = number | |
} | |
variable "extra_disks" { | |
description = "the gigbyte size and api type" | |
type = list(object({ | |
extra_disk_size = string | |
extra_disk_type = string | |
})) | |
default = [] | |
} | |
variable "subnet_name" { | |
description = "the name of the subnet to search" | |
default = "private" | |
type = string | |
} | |
variable "subnet_num" { | |
description = "the number after the name of the subnet to be used" | |
default = 1 | |
type = number | |
} | |
variable "scaling_class" { | |
# https://cloud.google.com/compute/docs/machine-types#predefined_machine_types | |
description = "the api sizing type" | |
default = "f1-micro" | |
type = string | |
} | |
variable "metadata" { | |
description = "google metadata, default is to merge in vmdns name" | |
type = map(string) | |
default = {} | |
} | |
variable "image_family" { | |
type = string | |
default = "centos-8" | |
description = "the name of the network that will be searched for" | |
} | |
variable "image_project" { | |
default = "centos-cloud" | |
type = string | |
description = "the name of the network that will be searched for" | |
} | |
variable "network_name" { | |
type = string | |
description = "the name of the network that will be searched for" | |
} | |
variable "scaling_max" { | |
default = 8 | |
type = number | |
} | |
variable "scaling_min" { | |
default = 0 | |
type = number | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment