diff --git a/modules/mks/k8s-cluster-standalone/main.tf b/modules/mks/k8s-cluster-standalone/main.tf index 3a95076..d5e1ad8 100644 --- a/modules/mks/k8s-cluster-standalone/main.tf +++ b/modules/mks/k8s-cluster-standalone/main.tf @@ -2,6 +2,7 @@ module "nat" { source = "../../nat" subnet_cidr = var.nat_subnet_cidr router_name = "${var.cluster_name}-router" + no_gateway = var.no_gateway } module "kubernetes_cluster" { diff --git a/modules/mks/k8s-cluster-standalone/vars.tf b/modules/mks/k8s-cluster-standalone/vars.tf index 910f0eb..44c411b 100644 --- a/modules/mks/k8s-cluster-standalone/vars.tf +++ b/modules/mks/k8s-cluster-standalone/vars.tf @@ -160,3 +160,8 @@ variable "gpu_ng_taints" { })) default = [] } + +variable "no_gateway" { + type = string + default = false +} \ No newline at end of file diff --git a/modules/nat/main.tf b/modules/nat/main.tf index 23f5035..1ba7302 100644 --- a/modules/nat/main.tf +++ b/modules/nat/main.tf @@ -18,6 +18,7 @@ resource "openstack_networking_subnet_v2" "subnet_1" { cidr = var.subnet_cidr name = var.subnet_cidr enable_dhcp = var.enable_dhcp + no_gateway = var.no_gateway } resource "openstack_networking_router_interface_v2" "router_interface_1" { diff --git a/modules/nat/vars.tf b/modules/nat/vars.tf index 0f848de..eed41e6 100644 --- a/modules/nat/vars.tf +++ b/modules/nat/vars.tf @@ -36,3 +36,8 @@ variable "enable_dhcp" { type = bool default = false } + +variable "no_gateway" { + default = true + description = "(Optional) Do not set a gateway IP on this subnet. Changing this removes or adds a default gateway IP of the existing subnet." +} diff --git a/modules/network/main.tf b/modules/network/main.tf new file mode 100644 index 0000000..ba9246a --- /dev/null +++ b/modules/network/main.tf @@ -0,0 +1,11 @@ +resource "openstack_networking_network_v2" "network_1" { + name = var.network_name +} + +resource "openstack_networking_subnet_v2" "subnet_1" { + network_id = openstack_networking_network_v2.network_1.id + name = var.subnet_cidr + cidr = var.subnet_cidr + enable_dhcp = var.enable_dhcp + no_gateway = var.no_gateway +} \ No newline at end of file diff --git a/modules/network/outputs.tf b/modules/network/outputs.tf new file mode 100644 index 0000000..3187e7f --- /dev/null +++ b/modules/network/outputs.tf @@ -0,0 +1,7 @@ +output "network_id" { + value = openstack_networking_network_v2.network_1.id +} + +output "subnet_id" { + value = openstack_networking_subnet_v2.subnet_1.id +} diff --git a/modules/network/vars.tf b/modules/network/vars.tf new file mode 100644 index 0000000..c4a1da0 --- /dev/null +++ b/modules/network/vars.tf @@ -0,0 +1,15 @@ +variable "network_name" { + default = "network_1" +} + +variable "subnet_cidr" { + default = "192.168.0.0/24" +} + +variable "enable_dhcp" { + default = false +} + +variable "no_gateway" { + default = true +} \ No newline at end of file diff --git a/modules/network/versions.tf b/modules/network/versions.tf new file mode 100644 index 0000000..6b12975 --- /dev/null +++ b/modules/network/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_providers { + openstack = { + source = "terraform-provider-openstack/openstack" + version = "1.53.0" + } + } + required_version = ">= 1.5.0" +} diff --git a/modules/vm/main.tf b/modules/vm/main.tf index ce8d34f..1d55e94 100644 --- a/modules/vm/main.tf +++ b/modules/vm/main.tf @@ -27,6 +27,21 @@ module "nat" { router_name = var.router_name network_name = var.network_name enable_dhcp = var.enable_dhcp + no_gateway = var.no_gateway +} + +module "network_1" { + source = "../network" + + subnet_cidr = var.local_network_1_subnet_cidr + network_name = var.local_network_1_name +} + +module "network_2" { + source = "../network" + + subnet_cidr = var.local_network_2_subnet_cidr + network_name = var.local_network_2_name } resource "openstack_networking_port_v2" "port_1" { @@ -38,6 +53,24 @@ resource "openstack_networking_port_v2" "port_1" { } } +resource "openstack_networking_port_v2" "port_2" { + name = "${var.vm_name}-eth1" + network_id = module.network_1.network_id + + fixed_ip { + subnet_id = module.network_1.subnet_id + } +} + +resource "openstack_networking_port_v2" "port_3" { + name = "${var.vm_name}-eth2" + network_id = module.network_2.network_id + + fixed_ip { + subnet_id = module.network_2.subnet_id + } +} + resource "openstack_compute_instance_v2" "instance_1" { name = var.vm_name @@ -48,6 +81,10 @@ resource "openstack_compute_instance_v2" "instance_1" { port = openstack_networking_port_v2.port_1.id } + network { + port = openstack_networking_port_v2.port_2.id + } + dynamic "block_device" { for_each = module.volume content { @@ -68,3 +105,8 @@ resource "openstack_compute_instance_v2" "instance_1" { ] } } + +resource "openstack_compute_interface_attach_v2" "port_3_attach" { + instance_id = openstack_compute_instance_v2.instance_1.id + port_id = openstack_networking_port_v2.port_3.id +} diff --git a/modules/vm/outputs.tf b/modules/vm/outputs.tf index 44696f8..23439fe 100644 --- a/modules/vm/outputs.tf +++ b/modules/vm/outputs.tf @@ -8,4 +8,4 @@ output "nat_sub_id" { output "vm_port_id" { value = openstack_networking_port_v2.port_1.id -} +} \ No newline at end of file diff --git a/modules/vm/vars.tf b/modules/vm/vars.tf index 76e1e08..818d093 100644 --- a/modules/vm/vars.tf +++ b/modules/vm/vars.tf @@ -65,7 +65,7 @@ variable "dns_nameservers" { } variable "subnet_cidr" { - description = "Subnet CIRD to be created" + description = "Subnet CIDR to be created" type = string default = "192.168.0.0/24" } @@ -82,8 +82,37 @@ variable "network_name" { default = "network_1" } +variable "local_network_1_name" { + description = "Local network name to be created" + type = string + default = "local_network_1" +} + +variable "local_network_2_name" { + description = "Local network name to be created" + type = string + default = "local_network_2" +} + +variable "local_network_1_subnet_cidr" { + description = "Subnet CIDR to be created" + type = string + default = "192.168.1.0/24" +} + +variable "local_network_2_subnet_cidr" { + description = "Subnet CIDR to be created" + type = string + default = "192.168.2.0/24" +} + variable "enable_dhcp" { description = "DHCP enable flag" type = bool default = false } + +variable "no_gateway" { + type = string + default = false +} \ No newline at end of file