Added example for bastion

This commit is contained in:
Michele Cereda
2023-02-11 14:13:24 +01:00
parent 8196f366a7
commit 61fa168c72
3 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
terraform {
required_version = "1.2.9"
required_providers {
oci = {
source = "oracle/oci"
version = "4.107.0"
}
}
}
####################
# Networking
####################
# See https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_vcn
resource "oci_core_vcn" "bastion" {
compartment_id = var.compartment_id
cidr_blocks = var.vcn_cidr_blocks
}
# See https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_subnet
resource "oci_core_subnet" "bastion" {
compartment_id = var.compartment_id
vcn_id = oci_core_vcn.bastion.id
cidr_block = var.subnet_cidr_block
}
####################
# Bastion
####################
data "http" "local_ip_address" { url = "https://ifconfig.co" }
locals { local_ip_cidr = "${chomp(data.http.local_ip_address.response_body)}/32" }
# See:
# - https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/bastion_bastion
# - https://docs.oracle.com/en-us/iaas/api/#/en/bastion/20210331/Bastion/CreateBastion
resource "oci_bastion_bastion" "bastion" {
compartment_id = var.compartment_id
target_subnet_id = oci_core_subnet.bastion.id
bastion_type = "STANDARD" # locked
client_cidr_block_allow_list = [local.local_ip_cidr]
}

View File

@@ -0,0 +1,12 @@
####################
# Debug
####################
# output "local_ip_address" { value = data.http.local_ip_address }
# output "local_ip_cidr" { value = local.local_ip_cidr }
####################
# Bastion
####################
output "bastion" { value = oci_bastion_bastion.bastion }

View File

@@ -0,0 +1,22 @@
####################
# Oracle Cloud Account
####################
variable "compartment_id" {
type = string
}
####################
# Networking
####################
variable "vcn_cidr_blocks" {
type = list(string)
default = [
"10.0.0.0/16"
]
}
variable "subnet_cidr_block" {
type = string
default = "10.0.0.0/24"
}