-
Notifications
You must be signed in to change notification settings - Fork 38
Add support for multi-node Data Guard deployments #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
bb855f2
bae7699
6d8b11a
a3fbd76
37981fe
b060ec6
45ffaed
0577949
effd179
4012f9b
5b2b7b9
754a123
e6ad6ec
29d51ca
4b5b1d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,70 +79,149 @@ locals { | |
additional_disks = concat(local.fs_disks, local.asm_disks) | ||
|
||
project_id = var.project_id | ||
|
||
is_multi_instance = ( | ||
var.zone1 != "" && var.zone2 != "" && var.subnetwork1 != "" && var.subnetwork2 != "" | ||
) | ||
|
||
instances = local.is_multi_instance ? { | ||
node1 = { | ||
name = "${var.instance_name}-1" | ||
zone = var.zone1 | ||
subnetwork = var.subnetwork1 | ||
} | ||
node2 = { | ||
name = "${var.instance_name}-2" | ||
zone = var.zone2 | ||
subnetwork = var.subnetwork2 | ||
} | ||
} : { | ||
default = { | ||
name = var.instance_name | ||
AlexBasinov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
zone = var.zone1 | ||
subnetwork = var.subnetwork1 | ||
} | ||
} | ||
} | ||
|
||
module "instance_template" { | ||
source = "terraform-google-modules/vm/google//modules/instance_template" | ||
version = "~> 13.0" | ||
|
||
name_prefix = format("%s-template", var.instance_name) | ||
region = var.region | ||
project_id = local.project_id | ||
network = coalesce(var.network, var.subnetwork) | ||
subnetwork = coalesce(var.subnetwork, var.network) | ||
subnetwork_project = local.project_id | ||
service_account = { | ||
email = var.vm_service_account | ||
scopes = ["https://www.googleapis.com/auth/cloud-platform"] | ||
|
||
data "google_compute_image" "os_image" { | ||
family = var.source_image_family | ||
project = var.source_image_project | ||
} | ||
|
||
resource "time_static" "template_suffix" {} | ||
|
||
locals { | ||
template_suffix = formatdate("YYYYMMDDhhmmss", time_static.template_suffix.rfc3339) | ||
} | ||
|
||
resource "google_compute_instance_template" "default" { | ||
name = "${var.instance_name}-${local.template_suffix}" | ||
project = var.project_id | ||
machine_type = var.machine_type | ||
|
||
network_interface { | ||
# gets overridden during instance creation | ||
network = "default" | ||
mfielding marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
disk { | ||
boot = true | ||
auto_delete = true | ||
source_image = data.google_compute_image.os_image.self_link | ||
disk_type = var.boot_disk_type | ||
disk_size_gb = var.boot_disk_size_gb | ||
} | ||
|
||
machine_type = var.machine_type | ||
source_image_family = var.source_image_family | ||
source_image_project = var.source_image_project | ||
disk_size_gb = var.boot_disk_size_gb | ||
disk_type = var.boot_disk_type | ||
auto_delete = true | ||
dynamic "disk" { | ||
for_each = local.additional_disks | ||
content { | ||
auto_delete = lookup(disk.value, "auto_delete", null) | ||
boot = lookup(disk.value, "boot", null) | ||
AlexBasinov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
device_name = lookup(disk.value, "device_name", null) | ||
mfielding marked this conversation as resolved.
Show resolved
Hide resolved
|
||
disk_size_gb = lookup(disk.value, "disk_size_gb", null) | ||
disk_type = lookup(disk.value, "disk_type", null) | ||
labels = lookup(disk.value, "disk_labels", null) | ||
} | ||
} | ||
|
||
service_account { | ||
email = var.vm_service_account | ||
scopes = ["cloud-platform"] | ||
} | ||
|
||
metadata = { | ||
metadata_startup_script = var.metadata_startup_script | ||
enable-oslogin = "TRUE" | ||
} | ||
|
||
additional_disks = local.additional_disks | ||
|
||
tags = var.network_tags | ||
} | ||
|
||
module "compute_instance" { | ||
source = "terraform-google-modules/vm/google//modules/compute_instance" | ||
version = "~> 13.0" | ||
|
||
region = var.region | ||
zone = var.zone | ||
network = coalesce(var.network, var.subnetwork) | ||
subnetwork = coalesce(var.subnetwork, var.network) | ||
subnetwork_project = local.project_id | ||
hostname = var.instance_name | ||
instance_template = module.instance_template.self_link | ||
deletion_protection = false | ||
|
||
access_config = var.assign_public_ip ? [{ | ||
nat_ip = null | ||
network_tier = "PREMIUM" | ||
}] : [] | ||
resource "google_compute_instance_from_template" "database_vm" { | ||
for_each = local.instances | ||
|
||
name = each.value.name | ||
zone = each.value.zone | ||
project = var.project_id | ||
source_instance_template = google_compute_instance_template.default.self_link | ||
|
||
network_interface { | ||
subnetwork = each.value.subnetwork | ||
|
||
dynamic "access_config" { | ||
for_each = var.assign_public_ip ? [1] : [] | ||
content {} | ||
} | ||
} | ||
|
||
} | ||
|
||
resource "random_id" "suffix" { | ||
byte_length = 4 | ||
} | ||
|
||
locals { | ||
oracle_nodes = [ | ||
AlexBasinov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
for vm in google_compute_instance_from_template.database_vm : { | ||
name = vm.name | ||
zone = vm.zone | ||
ip = vm.network_interface[0].network_ip | ||
} | ||
] | ||
} | ||
|
||
locals { | ||
common_flags = join(" ", compact([ | ||
length(local.asm_disk_config) > 0 ? "--ora-asm-disks-json '${jsonencode(local.asm_disk_config)}'" : "", | ||
length(local.data_mounts_config) > 0 ? "--ora-data-mounts-json '${jsonencode(local.data_mounts_config)}'" : "", | ||
"--swap-blk-device /dev/disk/by-id/google-swap", | ||
var.ora_swlib_bucket != "" ? "--ora-swlib-bucket ${var.ora_swlib_bucket}" : "", | ||
var.ora_version != "" ? "--ora-version ${var.ora_version}" : "", | ||
var.ora_backup_dest != "" ? "--backup-dest ${var.ora_backup_dest}" : "", | ||
var.ora_db_name != "" ? "--ora-db-name ${var.ora_db_name}" : "", | ||
var.ora_db_container != "" ? "--ora-db-container ${var.ora_db_container}" : "", | ||
var.ntp_pref != "" ? "--ntp-pref ${var.ntp_pref}" : "", | ||
var.ora_release != "" ? "--ora-release ${var.ora_release}" : "", | ||
var.ora_edition != "" ? "--ora-edition ${var.ora_edition}" : "", | ||
var.ora_listener_port != "" ? "--ora-listener-port ${var.ora_listener_port}" : "", | ||
var.ora_redo_log_size != "" ? "--ora-redo-log-size ${var.ora_redo_log_size}" : "", | ||
var.db_password_secret != "" ? "--db-password-secret ${var.db_password_secret}" : "", | ||
var.oracle_metrics_secret != "" ? "--oracle-metrics-secret ${var.oracle_metrics_secret}" : "", | ||
var.install_workload_agent ? "--install-workload-agent" : "", | ||
var.skip_database_config ? "--skip-database-config" : "", | ||
var.ora_pga_target_mb != "" ? "--ora-pga-target-mb ${var.ora_pga_target_mb}" : "", | ||
var.ora_sga_target_mb != "" ? "--ora-sga-target-mb ${var.ora_pga_target_mb}": "", | ||
var.data_guard_protection_mode != "" ? "--data-guard-protection-mode ${var.data_guard_protection_mode}": "" | ||
])) | ||
} | ||
|
||
resource "google_compute_instance" "control_node" { | ||
project = var.project_id | ||
name = "${var.control_node_name_prefix}-${random_id.suffix.hex}" | ||
machine_type = var.control_node_machine_type | ||
zone = var.zone | ||
|
||
zone = var.zone1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing spaces There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I marked this as resolved too soon. I just wanted to add some visual separation between the scheduling {} block and the basic parameter settings. |
||
scheduling { | ||
max_run_duration { | ||
seconds = 604800 | ||
|
@@ -157,8 +236,7 @@ resource "google_compute_instance" "control_node" { | |
} | ||
|
||
network_interface { | ||
network = coalesce(var.network, var.subnetwork) | ||
subnetwork = coalesce(var.subnetwork, var.network) | ||
subnetwork = var.subnetwork1 | ||
subnetwork_project = local.project_id | ||
|
||
dynamic "access_config" { | ||
|
@@ -174,28 +252,8 @@ resource "google_compute_instance" "control_node" { | |
|
||
metadata_startup_script = templatefile("${path.module}/scripts/setup.sh.tpl", { | ||
gcs_source = var.gcs_source | ||
instance_name = module.compute_instance.instances_details[0].name | ||
instance_zone = module.compute_instance.instances_details[0].zone | ||
ip_addr = module.compute_instance.instances_details[0].network_interface[0].network_ip | ||
asm_disk_config = jsonencode(local.asm_disk_config) | ||
data_mounts_config = jsonencode(local.data_mounts_config) | ||
swap_blk_device = "/dev/disk/by-id/google-swap" | ||
ora_swlib_bucket = var.ora_swlib_bucket | ||
ora_version = var.ora_version | ||
ora_backup_dest = var.ora_backup_dest | ||
ora_db_name = var.ora_db_name | ||
ora_db_container = var.ora_db_container | ||
ntp_pref = var.ntp_pref | ||
ora_release = var.ora_release | ||
ora_edition = var.ora_edition | ||
ora_listener_port = var.ora_listener_port | ||
ora_redo_log_size = var.ora_redo_log_size | ||
db_password_secret = var.db_password_secret | ||
install_workload_agent = var.install_workload_agent | ||
oracle_metrics_secret = var.oracle_metrics_secret | ||
skip_database_config = var.skip_database_config | ||
ora_pga_target_mb = var.ora_pga_target_mb | ||
ora_sga_target_mb = var.ora_sga_target_mb | ||
oracle_nodes_json = jsonencode(local.oracle_nodes) | ||
common_flags = local.common_flags | ||
deployment_name = var.deployment_name | ||
data_guard_protection_mode = var.data_guard_protection_mode | ||
}) | ||
|
@@ -204,7 +262,7 @@ resource "google_compute_instance" "control_node" { | |
enable-oslogin = "TRUE" | ||
} | ||
|
||
depends_on = [module.compute_instance] | ||
depends_on = [google_compute_instance_from_template.database_vm] | ||
} | ||
|
||
output "control_node_log_url" { | ||
|
Uh oh!
There was an error while loading. Please reload this page.