@@ -403,12 +403,31 @@ resource "oci_bastion_bastion" "bastion-service" {
403403 bastion_type = " STANDARD"
404404 compartment_id = var. compartment_ocid
405405 target_subnet_id = var. joomla_subnet_id
406- # target_subnet_id = var.bastion_subnet_id
407406 client_cidr_block_allow_list = [" 0.0.0.0/0" ]
408407 name = " BastionService4Joomla"
409408 max_session_ttl_in_seconds = 10800
410409}
411410
411+ data "oci_computeinstanceagent_instance_agent_plugins" "joomla_agent_plugin_bastion" {
412+ count = var. numberOfNodes > 1 && var. use_bastion_service ? 1 : 0
413+ compartment_id = var. compartment_ocid
414+ instanceagent_id = oci_core_instance. Joomla . id
415+ name = " Bastion"
416+ status = " RUNNING"
417+ }
418+
419+ resource "time_sleep" "joomla_agent_checker" {
420+ depends_on = [oci_core_instance . Joomla ]
421+ count = var. numberOfNodes > 1 && var. use_bastion_service ? 1 : 0
422+ create_duration = " 60s"
423+
424+ triggers = {
425+ changed_time_stamp = length (data. oci_computeinstanceagent_instance_agent_plugins . joomla_agent_plugin_bastion ) != 0 ? 0 : timestamp ()
426+ instance_ocid = oci_core_instance.Joomla.id
427+ private_ip = oci_core_instance.Joomla.private_ip
428+ }
429+ }
430+
412431resource "oci_bastion_session" "ssh_via_bastion_service" {
413432 depends_on = [oci_core_instance . Joomla ]
414433 count = var. numberOfNodes > 1 && var. use_bastion_service ? 1 : 0
@@ -420,10 +439,10 @@ resource "oci_bastion_session" "ssh_via_bastion_service" {
420439
421440 target_resource_details {
422441 session_type = " MANAGED_SSH"
423- target_resource_id = oci_core_instance . Joomla . id
442+ target_resource_id = time_sleep . joomla_agent_checker [ count . index ] . triggers [ " instance_ocid " ]
424443 target_resource_operating_system_user_name = " opc"
425444 target_resource_port = 22
426- target_resource_private_ip_address = oci_core_instance . Joomla . private_ip
445+ target_resource_private_ip_address = time_sleep . joomla_agent_checker [ count . index ] . triggers [ " private_ip" ]
427446 }
428447
429448 display_name = " ssh_via_bastion_service_to_Joomla1"
@@ -801,6 +820,26 @@ resource "oci_core_instance" "Joomla_from_image" {
801820 }
802821}
803822
823+ data "oci_computeinstanceagent_instance_agent_plugins" "joomla2plus_agent_plugin_bastion" {
824+ count = var. numberOfNodes > 1 && var. use_bastion_service ? var. numberOfNodes - 1 : 0
825+ compartment_id = var. compartment_ocid
826+ instanceagent_id = oci_core_instance. Joomla_from_image [count . index ]. id
827+ name = " Bastion"
828+ status = " RUNNING"
829+ }
830+
831+ resource "time_sleep" "joomla2plus_agent_checker" {
832+ depends_on = [oci_core_instance . Joomla_from_image ]
833+ count = var. numberOfNodes > 1 && var. use_bastion_service ? var. numberOfNodes - 1 : 0
834+ create_duration = " 60s"
835+
836+ triggers = {
837+ changed_time_stamp = length (data. oci_computeinstanceagent_instance_agent_plugins . joomla2plus_agent_plugin_bastion ) != 0 ? 0 : timestamp ()
838+ instance_ocid = oci_core_instance.Joomla_from_image[count.index].id
839+ private_ip = oci_core_instance.Joomla_from_image[count.index].private_ip
840+ }
841+ }
842+
804843resource "oci_bastion_session" "ssh_via_bastion_service2plus" {
805844 depends_on = [oci_core_instance . Joomla ]
806845 count = var. numberOfNodes > 1 && var. use_bastion_service ? var. numberOfNodes - 1 : 0
@@ -812,10 +851,10 @@ resource "oci_bastion_session" "ssh_via_bastion_service2plus" {
812851
813852 target_resource_details {
814853 session_type = " MANAGED_SSH"
815- target_resource_id = oci_core_instance . Joomla_from_image [count . index ]. id
854+ target_resource_id = time_sleep . joomla2plus_agent_checker [count . index ]. triggers [ " instance_ocid " ]
816855 target_resource_operating_system_user_name = " opc"
817856 target_resource_port = 22
818- target_resource_private_ip_address = oci_core_instance . Joomla_from_image [count . index ]. private_ip
857+ target_resource_private_ip_address = time_sleep . joomla2plus_agent_checker [count . index ]. triggers [ " private_ip" ]
819858 }
820859
821860 display_name = " ssh_via_bastion_service_to_Joomla${ count . index + 2 } "
0 commit comments