|
| 1 | +#==================================================== |
| 2 | +# Create VLAN and assign to OpenShift Worker Nodes |
| 3 | +#==================================================== |
| 4 | + |
| 5 | +terraform { |
| 6 | + required_providers { |
| 7 | + oci = { |
| 8 | + source = "oracle/oci" |
| 9 | + version = "~> 5.0" |
| 10 | + } |
| 11 | + } |
| 12 | +} |
| 13 | + |
| 14 | +provider "oci" { |
| 15 | +} |
| 16 | + |
| 17 | +#==================================================== |
| 18 | +# Define variables |
| 19 | +#==================================================== |
| 20 | +variable "OpenShiftNameSpace" { |
| 21 | + description = "The namespace for the OpenShift environment" |
| 22 | + type = string |
| 23 | + default = "---OCI Namespace that is being used for your OpenShift Cluster---" |
| 24 | +} |
| 25 | + |
| 26 | +variable "compartment_id" { |
| 27 | + description = "The compartment OCID in which to create resources" |
| 28 | + type = string |
| 29 | + default = "---OCID of the Compartment the OpenShift cluster is in---" |
| 30 | +} |
| 31 | + |
| 32 | +variable "vcn_id" { |
| 33 | + description = "The OCID of the VCN in which the VLAN (subnet) will be created" |
| 34 | + type = string |
| 35 | + default = "---OCID of the VCN your are using---" |
| 36 | +} |
| 37 | + |
| 38 | +variable "vlan_cidr" { |
| 39 | + description = "The CIDR block for the VLAN (subnet) to be created" |
| 40 | + type = string |
| 41 | + default = "10.0.101.0/24" # Change to CIDR range that is part of your VCN and is still available |
| 42 | +} |
| 43 | + |
| 44 | +variable "vlan_name" { |
| 45 | + description = "Name of the VLAN" |
| 46 | + type = string |
| 47 | + default = "EgressVLAN" |
| 48 | +} |
| 49 | + |
| 50 | +#==================================================== |
| 51 | +# Create VLAN in existing (specified) VCN |
| 52 | +#==================================================== |
| 53 | +resource "oci_core_vlan" "new_vlan" { |
| 54 | + compartment_id = var.compartment_id |
| 55 | + vcn_id = var.vcn_id |
| 56 | + cidr_block = var.vlan_cidr |
| 57 | + display_name = "vlan-${var.vlan_name}" |
| 58 | +} |
| 59 | + |
| 60 | +#==================================================== |
| 61 | +# DATA SOURCE: GET Openshift Worker Nodes based on tag |
| 62 | +#==================================================== |
| 63 | +data "oci_core_instances" "compute_instances" { |
| 64 | + compartment_id = var.compartment_id |
| 65 | + |
| 66 | + filter { |
| 67 | + # Use defined tag filtering syntax: defined_tags.<namespace>.<tag-key> |
| 68 | + name = "defined_tags.${var.OpenShiftNameSpace}.instance-role" |
| 69 | + values = ["compute"] |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +#==================================================== |
| 74 | +# LOCALS: Create list of Worker nodes instances |
| 75 | +#==================================================== |
| 76 | +locals { |
| 77 | + compute_instances = { |
| 78 | + for instance in data.oci_core_instances.compute_instances.instances : |
| 79 | + instance.id => instance |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +#==================================================== |
| 84 | +# Attach VLAN to each worker node |
| 85 | +#==================================================== |
| 86 | +resource "oci_core_vnic_attachment" "vlan_vnic" { |
| 87 | + for_each = local.compute_instances |
| 88 | + instance_id = each.key |
| 89 | + create_vnic_details{ |
| 90 | + display_name = "vlan-${var.vlan_name}" |
| 91 | + vlan_id = oci_core_vlan.new_vlan.id |
| 92 | + } |
| 93 | +} |
0 commit comments