split redis module into redis and sentinel

parent 38f207a0
......@@ -269,24 +269,29 @@ module "redis" {
}
module "redis-cache" {
bootstrap_version = 3
chef_run_list = "\"role[gprd-base-db-redis-server-cache]\""
data_disk_size = 100
data_disk_type = "pd-ssd"
chef_provision = "${var.chef_provision}"
chef_run_list = "${var.empty_chef_run_list}"
dns_zone_name = "${var.dns_zone_name}"
environment = "${var.environment}"
ip_cidr_range = "${var.subnetworks["redis-cache"]}"
machine_type = "${var.machine_types["redis-cache"]}"
name = "redis-cache"
node_count = "${var.node_count["redis-cache"]}"
project = "${var.project}"
public_ports = "${var.public_ports["redis-cache"]}"
region = "${var.region}"
source = "../../modules/google/generic-stor"
tier = "db"
vpc = "${module.network.self_link}"
bootstrap_version = 3
chef_provision = "${var.chef_provision}"
dns_zone_name = "${var.dns_zone_name}"
environment = "${var.environment}"
ip_cidr_range = "${var.subnetworks["redis-cache"]}"
name = "redis-cache"
project = "${var.project}"
public_ports = "${var.public_ports["redis-cache"]}"
region = "${var.region}"
redis_chef_run_list = "\"role[gprd-base-db-redis-server-cache]\""
redis_count = "${var.node_count["redis-cache"]}"
redis_data_disk_size = 100
redis_data_disk_type = "pd-ssd"
redis_machine_type = "${var.machine_types["redis-cache"]}"
sentinel_chef_run_list = "\"role[gprd-base-db-redis-sentinel-cache]\""
sentinel_count = "${var.node_count["redis-cache-sentinel"]}"
sentinel_data_disk_size = 100
sentinel_data_disk_type = "pd-ssd"
sentinel_machine_type = "${var.machine_types["redis-cache-sentinel"]}"
source = "../../modules/google/generic-stor-redis"
tier = "db"
vpc = "${module.network.self_link}"
}
##################################
......
......@@ -183,6 +183,7 @@ variable "machine_types" {
"pgb" = "n1-standard-4"
"redis" = "n1-highmem-2"
"redis-cache" = "n1-highmem-16"
"redis-cache-sentinel" = "n1-standard-1"
"registry" = "n1-standard-2"
"runner" = "n1-standard-2"
"sidekiq-asap" = "n1-standard-8"
......@@ -219,6 +220,7 @@ variable "node_count" {
"pgb" = 1
"redis" = 3
"redis-cache" = 3
"redis-cache-sentinel" = 3
"registry" = 2
"runner" = 1
"share" = 1
......
data "google_compute_zones" "available" {
region = "${var.region}"
status = "UP"
}
resource "google_compute_firewall" "public" {
count = "${length(var.public_ports) > 0 ? 1 : 0}"
name = "${format("%v-%v", var.name, var.environment)}"
network = "${var.vpc}"
allow {
protocol = "tcp"
ports = ["${var.public_ports}"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["${var.name}"]
}
output "instances_self_link" {
value = "${google_compute_instance.instance_with_attached_disk.*.self_link}"
}
resource "google_compute_address" "static-ip-address" {
count = "${var.redis_count}"
name = "${format("%v-%02d-%v-%v-static-ip", var.name, count.index + 1 + 100, var.tier, var.environment)}"
address_type = "INTERNAL"
address = "${replace(var.ip_cidr_range, "/\\d+\\/\\d+$/", count.index + 1 + 100)}"
subnetwork = "${google_compute_subnetwork.subnetwork.self_link}"
}
resource "google_compute_disk" "data_disk" {
project = "${var.project}"
count = "${var.redis_count}"
name = "${format("%v-%02d-%v-%v-data", var.name, count.index + 1, var.tier, var.environment)}"
zone = "${var.zone != "" ? var.zone : data.google_compute_zones.available.names[(count.index + 1) % length(data.google_compute_zones.available.names)]}"
size = "${var.redis_data_disk_size}"
type = "${var.redis_data_disk_type}"
labels {
environment = "${var.environment}"
pet_name = "${var.name}"
do_snapshots = "true"
}
}
resource "google_compute_instance" "instance_with_attached_disk" {
count = "${var.redis_count}"
name = "${format("%v-%02d-%v-%v", var.name, count.index + 1, var.tier, var.environment)}"
machine_type = "${var.redis_machine_type}"
metadata = {
"CHEF_URL" = "${var.chef_provision.["server_url"]}"
"CHEF_VERSION" = "${var.chef_provision.["version"]}"
"CHEF_NODE_NAME" = "${format("%v-%02d.%v.%v.%v", var.name, count.index + 1, var.tier, var.environment, var.dns_zone_name)}"
"CHEF_ENVIRONMENT" = "${var.environment}"
"CHEF_RUN_LIST" = "${var.redis_chef_run_list}"
"CHEF_DNS_ZONE_NAME" = "${var.dns_zone_name}"
"CHEF_PROJECT" = "${var.project}"
"GL_PERSISTENT_DISK_PATH" = "${var.persistent_disk_path}"
"GL_FORMAT_DATA_DISK" = "${var.format_data_disk}"
"block-project-ssh-keys" = "${var.block_project_ssh_keys}"
"enable-oslogin" = "${var.enable_oslogin}"
"shutdown-script" = "${file("${path.module}/../../../scripts/google/teardown-v1.sh")}"
}
metadata_startup_script = "${file("${path.module}/../../../scripts/google/bootstrap-v${var.bootstrap_version}.sh")}"
project = "${var.project}"
zone = "${var.zone != "" ? var.zone : data.google_compute_zones.available.names[(count.index + 1) % length(data.google_compute_zones.available.names)]}"
service_account {
// this should be the instance under which the instance should be running, rather than the one creating it...
email = "[email protected]"
// all the defaults plus cloudkms to access kms
scopes = [
"https://www.googleapis.com/auth/cloud.useraccounts.readonly",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring.write",
"https://www.googleapis.com/auth/pubsub",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/servicecontrol",
"https://www.googleapis.com/auth/trace.append",
"https://www.googleapis.com/auth/cloudkms",
"https://www.googleapis.com/auth/compute.readonly",
]
}
scheduling {
preemptible = "${var.preemptible}"
}
boot_disk {
auto_delete = true
initialize_params {
image = "${var.os_boot_image}"
size = "${var.os_disk_size}"
type = "${var.os_disk_type}"
}
}
attached_disk {
source = "${google_compute_disk.data_disk.*.self_link[count.index]}"
}
network_interface {
subnetwork = "${google_compute_subnetwork.subnetwork.name}"
address = "${google_compute_address.static-ip-address.*.address[count.index]}"
access_config = {}
}
labels {
environment = "${var.environment}"
pet_name = "${var.name}"
}
tags = [
"${var.name}",
"${var.environment}",
]
provisioner "local-exec" {
when = "destroy"
command = "knife node delete ${format("%v-%02d.%v.%v.%v", var.name, count.index + 1, var.tier, var.environment, var.dns_zone_name)} -y; knife client delete ${format("%v-%02d.%v.%v.%v", var.name, count.index + 1, var.tier, var.environment, var.dns_zone_name)} -y; exit 0"
}
}
resource "google_compute_address" "sentinel-static-ip-address" {
count = "${var.sentinel_count}"
name = "${format("%v-sentinel-%02d-%v-%v-static-ip", var.name, count.index + 1 + 120, var.tier, var.environment)}"
address_type = "INTERNAL"
address = "${replace(var.ip_cidr_range, "/\\d+\\/\\d+$/", count.index + 1 + 120)}"
subnetwork = "${google_compute_subnetwork.subnetwork.self_link}"
}
resource "google_compute_disk" "sentinel_data_disk" {
project = "${var.project}"
count = "${var.sentinel_count}"
name = "${format("%v-sentinel-%02d-%v-%v-data", var.name, count.index + 1, var.tier, var.environment)}"
zone = "${var.zone != "" ? var.zone : data.google_compute_zones.available.names[(count.index + 1) % length(data.google_compute_zones.available.names)]}"
size = "${var.sentinel_data_disk_size}"
type = "${var.sentinel_data_disk_type}"
labels {
environment = "${var.environment}"
pet_name = "${var.name}"
do_snapshots = "true"
}
}
resource "google_compute_instance" "sentinel_instance_with_attached_disk" {
count = "${var.sentinel_count}"
name = "${format("%v-sentinel-%02d-%v-%v", var.name, count.index + 1, var.tier, var.environment)}"
machine_type = "${var.sentinel_machine_type}"
metadata = {
"CHEF_URL" = "${var.chef_provision.["server_url"]}"
"CHEF_VERSION" = "${var.chef_provision.["version"]}"
"CHEF_NODE_NAME" = "${format("%v-sentinel-%02d.%v.%v.%v", var.name, count.index + 1, var.tier, var.environment, var.dns_zone_name)}"
"CHEF_ENVIRONMENT" = "${var.environment}"
"CHEF_RUN_LIST" = "${var.sentinel_chef_run_list}"
"CHEF_DNS_ZONE_NAME" = "${var.dns_zone_name}"
"CHEF_PROJECT" = "${var.project}"
"GL_PERSISTENT_DISK_PATH" = "${var.persistent_disk_path}"
"GL_FORMAT_DATA_DISK" = "${var.format_data_disk}"
"block-project-ssh-keys" = "${var.block_project_ssh_keys}"
"enable-oslogin" = "${var.enable_oslogin}"
"shutdown-script" = "${file("${path.module}/../../../scripts/google/teardown-v1.sh")}"
}
metadata_startup_script = "${file("${path.module}/../../../scripts/google/bootstrap-v${var.bootstrap_version}.sh")}"
project = "${var.project}"
zone = "${var.zone != "" ? var.zone : data.google_compute_zones.available.names[(count.index + 1) % length(data.google_compute_zones.available.names)]}"
service_account {
// this should be the instance under which the instance should be running, rather than the one creating it...
email = "[email protected]"
// all the defaults plus cloudkms to access kms
scopes = [
"https://www.googleapis.com/auth/cloud.useraccounts.readonly",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/monitoring.write",
"https://www.googleapis.com/auth/pubsub",
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/servicecontrol",
"https://www.googleapis.com/auth/trace.append",
"https://www.googleapis.com/auth/cloudkms",
"https://www.googleapis.com/auth/compute.readonly",
]
}
scheduling {
preemptible = "${var.preemptible}"
}
boot_disk {
auto_delete = true
initialize_params {
image = "${var.os_boot_image}"
size = "${var.os_disk_size}"
type = "${var.os_disk_type}"
}
}
attached_disk {
source = "${google_compute_disk.data_disk.*.self_link[count.index]}"
}
network_interface {
subnetwork = "${google_compute_subnetwork.subnetwork.name}"
address = "${google_compute_address.static-ip-address.*.address[count.index]}"
access_config = {}
}
labels {
environment = "${var.environment}"
pet_name = "${var.name}"
}
tags = [
"${var.name}",
"${var.environment}",
]
provisioner "local-exec" {
when = "destroy"
command = "knife node delete ${format("%v-sentinel-%02d.%v.%v.%v", var.name, count.index + 1, var.tier, var.environment, var.dns_zone_name)} -y; knife client delete ${format("%v-sentinel-%02d.%v.%v.%v", var.name, count.index + 1, var.tier, var.environment, var.dns_zone_name)} -y; exit 0"
}
}
resource "google_compute_subnetwork" "subnetwork" {
count = "${signum(var.redis_count + var.sentinel_count) > 0 ? 1 : 0}"
name = "${format("%v-%v", var.name, var.environment)}"
network = "${var.vpc}"
project = "${var.project}"
region = "${var.region}"
ip_cidr_range = "${var.ip_cidr_range}"
private_ip_google_access = true
}
variable "block_project_ssh_keys" {
type = "string"
description = "Whether to block project level SSH keys"
default = "TRUE"
}
variable "bootstrap_version" {
description = "version of the bootstrap script"
default = 1
}
variable "persistent_disk_path" {
type = "string"
description = "default location for disk mount"
default = "/var/opt/gitlab"
}
variable "chef_provision" {
type = "map"
description = "Configuration details for chef server"
}
variable "dns_zone_name" {
type = "string"
description = "The GCP name of the DNS zone to use for this environment"
}
variable "enable_oslogin" {
type = "string"
description = "Whether to enable OS Login GCP feature"
# Note: setting this to TRUE breaks chef!
# https://gitlab.com/gitlab-com/gitlab-com-infrastructure/merge_requests/297#note_66690562
default = "FALSE"
}
variable "environment" {
type = "string"
description = "The environment name"
}
variable "format_data_disk" {
type = "string"
description = "Force formatting of the persistent disk."
default = "false"
}
variable "ip_cidr_range" {
type = "string"
description = "The IP range"
}
variable "name" {
type = "string"
description = "The pet name"
}
variable "os_boot_image" {
type = "string"
description = "The OS image to boot"
default = "ubuntu-os-cloud/ubuntu-1604-xenial-v20180122"
}
variable "os_disk_size" {
type = "string"
description = "The OS disk size in GiB"
default = 20
}
variable "os_disk_type" {
type = "string"
description = "The OS disk type"
default = "pd-standard"
}
variable "preemptible" {
type = "string"
description = "Use preemptible instances for this pet"
default = "false"
}
variable "project" {
type = "string"
description = "The project name"
}
variable "public_ports" {
type = "list"
description = "The list of ports that should be publicly reachable"
default = []
}
variable "redis_chef_run_list" {
type = "string"
description = "run_list for the redis node in chef"
}
variable "redis_count" {
type = "string"
description = "The redis nodes count"
}
variable "redis_data_disk_size" {
type = "string"
description = "The size of the redis data disk"
default = 20
}
variable "redis_data_disk_type" {
type = "string"
description = "The type of the redis data disk"
default = "pd-standard"
}
variable "redis_machine_type" {
type = "string"
description = "The redis machine size"
}
variable "region" {
type = "string"
description = "The target region"
}
variable "sentinel_chef_run_list" {
type = "string"
description = "run_list for the sentinel node in chef"
}
variable "sentinel_count" {
type = "string"
description = "The redis sentinel nodes count"
}
variable "sentinel_data_disk_size" {
type = "string"
description = "The size of the sentinel data disk"
default = 20
}
variable "sentinel_data_disk_type" {
type = "string"
description = "The type of the sentinel data disk"
default = "pd-standard"
}
variable "sentinel_machine_type" {
type = "string"
description = "The sentinel machine size"
}
variable "tier" {
type = "string"
description = "The tier for this service"
}
variable "vpc" {
type = "string"
description = "The target network"
}
variable "zone" {
type = "string"
default = ""
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment