Skip to content

Commit

Permalink
Merge pull request #5 from oracle-devrel/develop2
Browse files Browse the repository at this point in the history
Added bastion agent checker
  • Loading branch information
nugoncal authored May 26, 2022
2 parents fad7266 + 6c425e2 commit 19c6d3e
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
## Copyright (c) 2022 Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl

terraform {
required_version = ">= 1.0"
required_providers {
oci = {
source = "oracle/oci"
}
}
}

provider "oci" {
tenancy_ocid = var.tenancy_ocid
region = var.region
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
## Copyright (c) 2022 Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl

terraform {
required_version = ">= 1.0"
required_providers {
oci = {
source = "oracle/oci"
}
}
}

provider "oci" {
tenancy_ocid = var.tenancy_ocid
region = var.region
Expand Down
9 changes: 9 additions & 0 deletions examples/joomla-ha-mds-use-existing-network/provider.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
## Copyright (c) 2022 Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl

terraform {
required_version = ">= 1.0"
required_providers {
oci = {
source = "oracle/oci"
}
}
}

provider "oci" {
tenancy_ocid = var.tenancy_ocid
region = var.region
Expand Down
9 changes: 9 additions & 0 deletions examples/joomla-single-mds-use-existing-network/provider.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
## Copyright (c) 2022 Oracle and/or its affiliates.
## All rights reserved. The Universal Permissive License (UPL), Version 1.0 as shown at http://oss.oracle.com/licenses/upl

terraform {
required_version = ">= 1.0"
required_providers {
oci = {
source = "oracle/oci"
}
}
}

provider "oci" {
tenancy_ocid = var.tenancy_ocid
region = var.region
Expand Down
49 changes: 44 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,31 @@ resource "oci_bastion_bastion" "bastion-service" {
bastion_type = "STANDARD"
compartment_id = var.compartment_ocid
target_subnet_id = var.joomla_subnet_id
#target_subnet_id = var.bastion_subnet_id
client_cidr_block_allow_list = ["0.0.0.0/0"]
name = "BastionService4Joomla"
max_session_ttl_in_seconds = 10800
}

data "oci_computeinstanceagent_instance_agent_plugins" "joomla_agent_plugin_bastion" {
count = var.numberOfNodes > 1 && var.use_bastion_service ? 1 : 0
compartment_id = var.compartment_ocid
instanceagent_id = oci_core_instance.Joomla.id
name = "Bastion"
status = "RUNNING"
}

resource "time_sleep" "joomla_agent_checker" {
depends_on = [oci_core_instance.Joomla]
count = var.numberOfNodes > 1 && var.use_bastion_service ? 1 : 0
create_duration = "60s"

triggers = {
changed_time_stamp = length(data.oci_computeinstanceagent_instance_agent_plugins.joomla_agent_plugin_bastion) != 0 ? 0 : timestamp()
instance_ocid = oci_core_instance.Joomla.id
private_ip = oci_core_instance.Joomla.private_ip
}
}

resource "oci_bastion_session" "ssh_via_bastion_service" {
depends_on = [oci_core_instance.Joomla]
count = var.numberOfNodes > 1 && var.use_bastion_service ? 1 : 0
Expand All @@ -420,10 +439,10 @@ resource "oci_bastion_session" "ssh_via_bastion_service" {

target_resource_details {
session_type = "MANAGED_SSH"
target_resource_id = oci_core_instance.Joomla.id
target_resource_id = time_sleep.joomla_agent_checker[count.index].triggers["instance_ocid"]
target_resource_operating_system_user_name = "opc"
target_resource_port = 22
target_resource_private_ip_address = oci_core_instance.Joomla.private_ip
target_resource_private_ip_address = time_sleep.joomla_agent_checker[count.index].triggers["private_ip"]
}

display_name = "ssh_via_bastion_service_to_Joomla1"
Expand Down Expand Up @@ -801,6 +820,26 @@ resource "oci_core_instance" "Joomla_from_image" {
}
}

data "oci_computeinstanceagent_instance_agent_plugins" "joomla2plus_agent_plugin_bastion" {
count = var.numberOfNodes > 1 && var.use_bastion_service ? var.numberOfNodes - 1 : 0
compartment_id = var.compartment_ocid
instanceagent_id = oci_core_instance.Joomla_from_image[count.index].id
name = "Bastion"
status = "RUNNING"
}

resource "time_sleep" "joomla2plus_agent_checker" {
depends_on = [oci_core_instance.Joomla_from_image]
count = var.numberOfNodes > 1 && var.use_bastion_service ? var.numberOfNodes - 1 : 0
create_duration = "60s"

triggers = {
changed_time_stamp = length(data.oci_computeinstanceagent_instance_agent_plugins.joomla2plus_agent_plugin_bastion) != 0 ? 0 : timestamp()
instance_ocid = oci_core_instance.Joomla_from_image[count.index].id
private_ip = oci_core_instance.Joomla_from_image[count.index].private_ip
}
}

resource "oci_bastion_session" "ssh_via_bastion_service2plus" {
depends_on = [oci_core_instance.Joomla]
count = var.numberOfNodes > 1 && var.use_bastion_service ? var.numberOfNodes - 1 : 0
Expand All @@ -812,10 +851,10 @@ resource "oci_bastion_session" "ssh_via_bastion_service2plus" {

target_resource_details {
session_type = "MANAGED_SSH"
target_resource_id = oci_core_instance.Joomla_from_image[count.index].id
target_resource_id = time_sleep.joomla2plus_agent_checker[count.index].triggers["instance_ocid"]
target_resource_operating_system_user_name = "opc"
target_resource_port = 22
target_resource_private_ip_address = oci_core_instance.Joomla_from_image[count.index].private_ip
target_resource_private_ip_address = time_sleep.joomla2plus_agent_checker[count.index].triggers["private_ip"]
}

display_name = "ssh_via_bastion_service_to_Joomla${count.index + 2}"
Expand Down

0 comments on commit 19c6d3e

Please sign in to comment.