Skip to content

Commit

Permalink
Add module + example mock
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Natarov authored and Vitaliy Natarov committed Jan 20, 2025
1 parent fb8566e commit 6f36a84
Show file tree
Hide file tree
Showing 34 changed files with 2,625 additions and 34 deletions.
3 changes: 3 additions & 0 deletions oracle_cloud/examples/core_peering_connections/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Work with CORE_PEERING_CONNECTIONS via terraform

A terraform module for making CORE_PEERING_CONNECTIONS.
30 changes: 30 additions & 0 deletions oracle_cloud/examples/core_peering_connections/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# MAINTAINER Vitaliy Natarov "vitaliy.natarov@yahoo.com"
#

terraform {
required_version = "~> 1.0"

required_providers {
oci = {
source = "oracle/oci"
version = "6.21.0"
}
}
}

provider "oci" {
fingerprint = var.provider_oci_fingerprint
private_key_path = var.provider_oci_private_key_path
region = var.provider_oci_region
tenancy_ocid = var.provider_oci_tenancy_ocid
user_ocid = var.provider_oci_user_ocid
alias = var.provider_oci_alias
}

module "core_vcn" {
source = "../../modules/core_peering_connections"

# enable

}
37 changes: 37 additions & 0 deletions oracle_cloud/examples/core_peering_connections/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# provider identity parameters
variable "provider_oci_fingerprint" {
type = string
description = "fingerprint of oci api private key"
default = ""
}

variable "provider_oci_private_key_path" {
type = string
description = "path to oci api private key used"
default = ""
}

variable "provider_oci_region" {
type = string
# List of regions: https://docs.cloud.oracle.com/iaas/Content/General/Concepts/regions.htm#ServiceAvailabilityAcrossRegions
description = "the oci region where resources will be created"
default = ""
}

variable "provider_oci_tenancy_ocid" {
type = string
description = "tenancy id where to create the sources"
default = ""
}

variable "provider_oci_user_ocid" {
type = string
description = "id of user that terraform will use to create the resources"
default = ""
}

variable "provider_oci_alias" {
type = string
description = "Set alias for provider"
default = ""
}
331 changes: 329 additions & 2 deletions oracle_cloud/examples/core_vcn/README.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions oracle_cloud/examples/core_vcn/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ provider "oci" {
module "core_vcn" {
source = "../../modules/core_vcn"

# enable

}
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions oracle_cloud/modules/core_peering_connections/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#-----------------------------------------------------------
# TMP
#-----------------------------------------------------------
123 changes: 123 additions & 0 deletions oracle_cloud/modules/core_peering_connections/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#-----------------------------------------------------------
# Global
#-----------------------------------------------------------
variable "name" {
description = "The name for resources"
default = "test"
}

variable "environment" {
description = "The environment for resources"
default = "dev"
}

variable "tags" {
description = "Add additional tags"
default = {}
}

#-----------------------------------------------------------
# core vcn
#-----------------------------------------------------------
variable "enable_core_vcn" {
description = "Enable core vcn usages"
default = false
}

variable "core_vcn_compartment_id" {
description = "(Required) (Updatable) The OCID of the compartment to contain the VCN."
default = null
}

variable "core_vcn_byoipv6cidr_details" {
description = "(Optional) The list of BYOIPv6 OCIDs and BYOIPv6 prefixes required to create a VCN that uses BYOIPv6 address ranges."
default = []
}

variable "core_vcn_display_name" {
description = "(Optional) (Updatable) A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information."
default = null
}

variable "core_vcn_cidr_blocks" {
description = "(Optional) (Updatable) The list of one or more IPv4 CIDR blocks for the VCN"
default = null
}

variable "core_vcn_dns_label" {
description = "(Optional) A DNS label for the VCN, used in conjunction with the VNIC's hostname and subnet's DNS label to form a fully qualified domain name (FQDN) for each VNIC within this subnet (for example, bminstance1.subnet123.vcn1.oraclevcn.com). Not required to be unique, but it's a best practice to set unique DNS labels for VCNs in your tenancy. Must be an alphanumeric string that begins with a letter. The value cannot be changed. You must set this value if you want instances to be able to use hostnames to resolve other instances in the VCN. Otherwise the Internet and VCN Resolver will not work."
default = null
}

variable "core_vcn_ipv6private_cidr_blocks" {
description = "(Optional) The list of one or more ULA or Private IPv6 CIDR blocks for the vcn"
default = null
}

variable "core_vcn_is_ipv6enabled" {
description = "(Optional) Whether IPv6 is enabled for the VCN. Default is false. If enabled, Oracle will assign the VCN a IPv6 /56 CIDR block. You may skip having Oracle allocate the VCN a IPv6 /56 CIDR block by setting isOracleGuaAllocationEnabled to false. For important details about IPv6 addressing in a VCN, see IPv6 Addresses. Example: true"
default = null
}

variable "core_vcn_is_oracle_gua_allocation_enabled" {
description = "(Optional) Specifies whether to skip Oracle allocated IPv6 GUA. By default, Oracle will allocate one GUA of /56 size for an IPv6 enabled VCN."
default = null
}

variable "core_vcn_security_attributes" {
description = "(Optional) (Updatable) Security Attributes for this resource. This is unique to ZPR, and helps identify which resources are allowed to be accessed by what permission controls. Example: {'Oracle-DataSecurity-ZPR.MaxEgressCount.value': '42', 'Oracle-DataSecurity-ZPR.MaxEgressCount.mode': 'audit'}"
default = null
}

variable "core_vcn_freeform_tags" {
description = "(Optional) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see Resource Tags."
default = {}
}

variable "core_vcn_timeouts" {
description = "The timeouts block allows you to specify timeouts for certain operations: * create - (Defaults to 20 minutes), when creating the Vcn * update - (Defaults to 20 minutes), when updating the Vcn * delete - (Defaults to 20 minutes), when destroying the Vcn"
default = {}
}

#-----------------------------------------------------------
# core private ip
#-----------------------------------------------------------
variable "enable_core_private_ip" {
description = "Enable core private ip usages"
default = false
}

variable "core_private_ip_display_name" {
description = "(Optional) (Updatable) A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information."
default = null
}

variable "core_private_ip_hostname_label" {
description = "(Optional) (Updatable) The hostname for the private IP. Used for DNS. The value is the hostname portion of the private IP's fully qualified domain name (FQDN) (for example, bminstance1 in FQDN bminstance1.subnet123.vcn1.oraclevcn.com). Must be unique across all VNICs in the subnet and comply with RFC 952 and RFC 1123."
default = null
}

variable "core_private_ip_ip_address" {
description = "(Optional) A private IP address of your choice. Must be an available IP address within the subnet's CIDR. If you don't specify a value, Oracle automatically assigns a private IP address from the subnet. Example: 10.0.3.3"
default = null
}

variable "core_private_ip_vlan_id" {
description = "(Optional) Use this attribute only with the Oracle Cloud VMware Solution. The OCID of the VLAN from which the private IP is to be drawn. The IP address, if supplied, must be valid for the given VLAN. See Vlan."
default = null
}

variable "core_private_ip_vnic_id" {
description = "(Optional) (Updatable) The OCID of the VNIC to assign the private IP to. The VNIC and private IP must be in the same subnet."
default = null
}

variable "core_private_ip_freeform_tags" {
description = "(Optional) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see Resource Tags"
default = {}
}

variable "core_private_ip_timeouts" {
description = "The timeouts block allows you to specify timeouts for certain operations: * create - (Defaults to 20 minutes), when creating the Private Ip * update - (Defaults to 20 minutes), when updating the Private Ip * delete - (Defaults to 20 minutes), when destroying the Private Ip"
default = {}
}
53 changes: 51 additions & 2 deletions oracle_cloud/modules/core_vcn/dhcp_options.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
#-----------------------------------------------------------
# dhcp_options
# core dhcp options
#-----------------------------------------------------------
resource "oci_core_dhcp_options" "core_dhcp_options" {
count = var.enable_core_dhcp_options ? 1 : 0

# https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_dhcp_options
# Required
compartment_id = var.core_dhcp_options_compartment_id

dynamic "options" {
iterator = options
for_each = var.core_dhcp_options_options

content {
type = lookup(options.value, "type", null)
server_type = lookup(options.value, "server_type", null)

# Ensure no more than 3 DNS servers are specified
custom_dns_servers = length(lookup(options.value, "custom_dns_servers", [])) > 3 ? (throw("Error: custom_dns_servers can have a maximum of 3 entries.")) : lookup(options.value, "custom_dns_servers", null)
search_domain_names = lookup(options.value, "search_domain_names", null)
}
}

vcn_id = var.core_dhcp_options_vcn_id != "" && !var.enable_core_vcn ? var.core_dhcp_options_vcn_id : (var.enable_core_vcn ? element(oci_core_vcn.core_vcn.*.id, 0) : null)

# Optional
display_name = var.core_dhcp_options_display_name != "" ? var.core_dhcp_options_display_name : "${lower(var.name)}-dhcp-options-${lower(var.environment)}"

defined_tags = merge(
{
Name = var.core_dhcp_options_display_name != "" ? var.core_dhcp_options_display_name : "${lower(var.name)}-dhcp-options-${lower(var.environment)}"
},
var.tags
)
freeform_tags = var.core_dhcp_options_freeform_tags

dynamic "timeouts" {
iterator = timeouts
for_each = length(keys(var.core_dhcp_options_timeouts)) > 0 ? [var.core_dhcp_options_timeouts] : []

content {
create = lookup(timeouts.value, "create", null)
update = lookup(timeouts.value, "update", null)
delete = lookup(timeouts.value, "delete", null)
}
}

lifecycle {
create_before_destroy = true
ignore_changes = []
}

depends_on = []
}
41 changes: 39 additions & 2 deletions oracle_cloud/modules/core_vcn/internet_gateway.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
#-----------------------------------------------------------
# internet_gateway
# core internet gateway
#-----------------------------------------------------------
resource "oci_core_internet_gateway" "core_internet_gateway" {
# TODO: Add it for private subnets
count = var.enable_core_internet_gateway ? 1 : 0

# https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_internet_gateway
# Required
compartment_id = var.core_internet_gateway_compartment_id
vcn_id = var.core_internet_gateway_vcn_id != "" && !var.enable_core_vcn ? var.core_internet_gateway_vcn_id : (var.enable_core_vcn ? element(oci_core_vcn.core_vcn.*.id, 0) : null)

# Optional
enabled = var.core_internet_gateway_enabled
display_name = var.core_internet_gateway_display_name != "" ? var.core_internet_gateway_display_name : "${lower(var.name)}-internet-gtw-${lower(var.environment)}"
route_table_id = var.core_internet_gateway_route_table_id != "" && !var.enable_core_route_table ? var.core_nat_gateway_route_table_id : (var.enable_core_route_table ? element(oci_core_route_table.core_route_table.*.id, 0) : null)

defined_tags = merge(
{
Name = var.core_internet_gateway_display_name != "" ? var.core_internet_gateway_display_name : "${lower(var.name)}-internet-gtw-${lower(var.environment)}"
},
var.tags
)
freeform_tags = var.core_internet_gateway_freeform_tags

dynamic "timeouts" {
iterator = timeouts
for_each = length(keys(var.core_internet_gateway_timeouts)) > 0 ? [var.core_internet_gateway_timeouts] : []

content {
create = lookup(timeouts.value, "create", null)
update = lookup(timeouts.value, "update", null)
delete = lookup(timeouts.value, "delete", null)
}
}

lifecycle {
create_before_destroy = true
ignore_changes = []
}

depends_on = []
}
40 changes: 38 additions & 2 deletions oracle_cloud/modules/core_vcn/ipv6.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
#-----------------------------------------------------------
# ipv6
# core ipv6
#-----------------------------------------------------------
resource "oci_core_ipv6" "core_ipv6" {
# TODO: Add multiple IPv6
count = var.enable_core_ipv6 ? 1 : 0

# https://registry.terraform.io/providers/oracle/oci/latest/docs/resources/core_ipv6
# Required
vnic_id = var.core_ipv6_vnic_id != "" && !var.enable_core_vnic_attachment ? var.core_ipv6_vnic_id : (var.enable_core_vnic_attachment ? element(oci_core_vnic_attachment.core_vnic_attachment.*.id, 0) : null)

# Optional
display_name = var.core_ipv6_display_name != "" ? var.core_ipv6_display_name : "${lower(var.name)}-ipv6-${lower(var.environment)}-${count.index + 1}"
ip_address = var.core_ipv6_ip_address
ipv6subnet_cidr = var.core_ipv6_ipv6subnet_cidr

defined_tags = merge(
{
Name = var.core_ipv6_display_name != "" ? var.core_ipv6_display_name : "${lower(var.name)}-ipv6-${lower(var.environment)}-${count.index + 1}"
},
var.tags
)
freeform_tags = var.core_ipv6_freeform_tags

dynamic "timeouts" {
iterator = timeouts
for_each = length(keys(var.core_ipv6_timeouts)) > 0 ? [var.core_ipv6_timeouts] : []

content {
create = lookup(timeouts.value, "create", null)
update = lookup(timeouts.value, "update", null)
delete = lookup(timeouts.value, "delete", null)
}
}

lifecycle {
create_before_destroy = true
ignore_changes = []
}

depends_on = []
}
Loading

0 comments on commit 6f36a84

Please sign in to comment.