Skip to content

Commit 50cbceb

Browse files
authored
Merge pull request #3 from oracle-devrel/bastion-agent-checker
Bastion Agent Checker
2 parents 9496cf5 + 3d70646 commit 50cbceb

File tree

5 files changed

+80
-5
lines changed

5 files changed

+80
-5
lines changed

examples/drupal-ha-mds-use-existing-network-and-injected-bastion-host/provider.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
## Copyright (c) 2022 Oracle and/or its affiliates.
22
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
33

4+
terraform {
5+
required_version = ">= 1.0"
6+
required_providers {
7+
oci = {
8+
source = "oracle/oci"
9+
}
10+
}
11+
}
12+
413
provider "oci" {
514
tenancy_ocid = var.tenancy_ocid
615
region = var.region

examples/drupal-ha-mds-use-existing-network-and-injected-bastion-service/provider.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
## Copyright (c) 2022 Oracle and/or its affiliates.
22
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
33

4+
terraform {
5+
required_version = ">= 1.0"
6+
required_providers {
7+
oci = {
8+
source = "oracle/oci"
9+
}
10+
}
11+
}
12+
413
provider "oci" {
514
tenancy_ocid = var.tenancy_ocid
615
region = var.region

examples/drupal-ha-mds-use-existing-network/provider.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
## Copyright (c) 2022 Oracle and/or its affiliates.
22
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
33

4+
terraform {
5+
required_version = ">= 1.0"
6+
required_providers {
7+
oci = {
8+
source = "oracle/oci"
9+
}
10+
}
11+
}
12+
413
provider "oci" {
514
tenancy_ocid = var.tenancy_ocid
615
region = var.region

examples/drupal-single-mds-use-existing-network/provider.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
## Copyright (c) 2022 Oracle and/or its affiliates.
22
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl
33

4+
terraform {
5+
required_version = ">= 1.0"
6+
required_providers {
7+
oci = {
8+
source = "oracle/oci"
9+
}
10+
}
11+
}
12+
413
provider "oci" {
514
tenancy_ocid = var.tenancy_ocid
615
region = var.region

main.tf

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,31 @@ resource "oci_bastion_bastion" "bastion-service" {
401401
bastion_type = "STANDARD"
402402
compartment_id = var.compartment_ocid
403403
target_subnet_id = var.drupal_subnet_id
404-
#target_subnet_id = var.bastion_subnet_id
405404
client_cidr_block_allow_list = ["0.0.0.0/0"]
406405
name = "BastionService4drupal"
407406
max_session_ttl_in_seconds = 10800
408407
}
409408

409+
data "oci_computeinstanceagent_instance_agent_plugins" "drupal_agent_plugin_bastion" {
410+
count = var.numberOfNodes > 1 && var.use_bastion_service ? 1 : 0
411+
compartment_id = var.compartment_ocid
412+
instanceagent_id = oci_core_instance.drupal.id
413+
name = "Bastion"
414+
status = "RUNNING"
415+
}
416+
417+
resource "time_sleep" "drupal_agent_checker" {
418+
depends_on = [oci_core_instance.drupal]
419+
count = var.numberOfNodes > 1 && var.use_bastion_service ? 1 : 0
420+
create_duration = "60s"
421+
422+
triggers = {
423+
changed_time_stamp = length(data.oci_computeinstanceagent_instance_agent_plugins.drupal_agent_plugin_bastion) != 0 ? 0 : timestamp()
424+
instance_ocid = oci_core_instance.drupal.id
425+
private_ip = oci_core_instance.drupal.private_ip
426+
}
427+
}
428+
410429
resource "oci_bastion_session" "ssh_via_bastion_service" {
411430
depends_on = [oci_core_instance.drupal]
412431
count = var.numberOfNodes > 1 && var.use_bastion_service ? 1 : 0
@@ -418,10 +437,10 @@ resource "oci_bastion_session" "ssh_via_bastion_service" {
418437

419438
target_resource_details {
420439
session_type = "MANAGED_SSH"
421-
target_resource_id = oci_core_instance.drupal.id
440+
target_resource_id = time_sleep.drupal_agent_checker[count.index].triggers["instance_ocid"]
422441
target_resource_operating_system_user_name = "opc"
423442
target_resource_port = 22
424-
target_resource_private_ip_address = oci_core_instance.drupal.private_ip
443+
target_resource_private_ip_address = time_sleep.drupal_agent_checker[count.index].triggers["private_ip"]
425444
}
426445

427446
display_name = "ssh_via_bastion_service_to_drupal1"
@@ -896,6 +915,26 @@ resource "oci_core_instance" "drupal_from_image" {
896915
}
897916
}
898917

918+
data "oci_computeinstanceagent_instance_agent_plugins" "drupal2plus_agent_plugin_bastion" {
919+
count = var.numberOfNodes > 1 && var.use_bastion_service ? var.numberOfNodes - 1 : 0
920+
compartment_id = var.compartment_ocid
921+
instanceagent_id = oci_core_instance.drupal_from_image[count.index].id
922+
name = "Bastion"
923+
status = "RUNNING"
924+
}
925+
926+
resource "time_sleep" "drupal2plus_agent_checker" {
927+
depends_on = [oci_core_instance.drupal_from_image]
928+
count = var.numberOfNodes > 1 && var.use_bastion_service ? var.numberOfNodes - 1 : 0
929+
create_duration = "60s"
930+
931+
triggers = {
932+
changed_time_stamp = length(data.oci_computeinstanceagent_instance_agent_plugins.drupal2plus_agent_plugin_bastion) != 0 ? 0 : timestamp()
933+
instance_ocid = oci_core_instance.drupal_from_image[count.index].id
934+
private_ip = oci_core_instance.drupal_from_image[count.index].private_ip
935+
}
936+
}
937+
899938
resource "oci_bastion_session" "ssh_via_bastion_service2plus" {
900939
depends_on = [oci_core_instance.drupal]
901940
count = var.numberOfNodes > 1 && var.use_bastion_service ? var.numberOfNodes - 1 : 0
@@ -907,10 +946,10 @@ resource "oci_bastion_session" "ssh_via_bastion_service2plus" {
907946

908947
target_resource_details {
909948
session_type = "MANAGED_SSH"
910-
target_resource_id = oci_core_instance.drupal_from_image[count.index].id
949+
target_resource_id = time_sleep.drupal2plus_agent_checker[count.index].triggers["instance_ocid"]
911950
target_resource_operating_system_user_name = "opc"
912951
target_resource_port = 22
913-
target_resource_private_ip_address = oci_core_instance.drupal_from_image[count.index].private_ip
952+
target_resource_private_ip_address = time_sleep.drupal2plus_agent_checker[count.index].triggers["private_ip"]
914953
}
915954

916955
display_name = "ssh_via_bastion_service_to_drupal${count.index + 2}"

0 commit comments

Comments
 (0)