Terraform/OpenStack: Enable usage of an existing router (#5890)
This commit is contained in:
parent
e732df56a1
commit
0d2990510e
6 changed files with 28 additions and 5 deletions
|
@ -38,6 +38,16 @@ hosts where that makes sense. You have the option of creating bastion hosts
|
||||||
inside the private subnet to access the nodes there. Alternatively, a node with
|
inside the private subnet to access the nodes there. Alternatively, a node with
|
||||||
a floating IP can be used as a jump host to nodes without.
|
a floating IP can be used as a jump host to nodes without.
|
||||||
|
|
||||||
|
#### Using an existing router
|
||||||
|
It is possible to use an existing router instead of creating one. To use an
|
||||||
|
existing router set the router\_id variable to the uuid of the router you wish
|
||||||
|
to use.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
```
|
||||||
|
router_id = "00c542e7-6f46-4535-ae95-984c7f0391a3"
|
||||||
|
```
|
||||||
|
|
||||||
### Kubernetes Nodes
|
### Kubernetes Nodes
|
||||||
You can create many different kubernetes topologies by setting the number of
|
You can create many different kubernetes topologies by setting the number of
|
||||||
different classes of hosts. For each class there are options for allocating
|
different classes of hosts. For each class there are options for allocating
|
||||||
|
|
|
@ -12,6 +12,7 @@ module "network" {
|
||||||
dns_nameservers = "${var.dns_nameservers}"
|
dns_nameservers = "${var.dns_nameservers}"
|
||||||
network_dns_domain = "${var.network_dns_domain}"
|
network_dns_domain = "${var.network_dns_domain}"
|
||||||
use_neutron = "${var.use_neutron}"
|
use_neutron = "${var.use_neutron}"
|
||||||
|
router_id = "${var.router_id}"
|
||||||
}
|
}
|
||||||
|
|
||||||
module "ips" {
|
module "ips" {
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
resource "openstack_networking_router_v2" "k8s" {
|
resource "openstack_networking_router_v2" "k8s" {
|
||||||
name = "${var.cluster_name}-router"
|
name = "${var.cluster_name}-router"
|
||||||
count = "${var.use_neutron}"
|
count = "${var.use_neutron}" == 1 && "${var.router_id}" == null ? 1 : 0
|
||||||
admin_state_up = "true"
|
admin_state_up = "true"
|
||||||
external_network_id = "${var.external_net}"
|
external_network_id = "${var.external_net}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data "openstack_networking_router_v2" "k8s" {
|
||||||
|
router_id = "${var.router_id}"
|
||||||
|
count = "${var.use_neutron}" == 1 && "${var.router_id}" != null ? 1 : 0
|
||||||
|
}
|
||||||
|
|
||||||
resource "openstack_networking_network_v2" "k8s" {
|
resource "openstack_networking_network_v2" "k8s" {
|
||||||
name = "${var.network_name}"
|
name = "${var.network_name}"
|
||||||
count = "${var.use_neutron}"
|
count = "${var.use_neutron}"
|
||||||
|
@ -23,6 +28,6 @@ resource "openstack_networking_subnet_v2" "k8s" {
|
||||||
|
|
||||||
resource "openstack_networking_router_interface_v2" "k8s" {
|
resource "openstack_networking_router_interface_v2" "k8s" {
|
||||||
count = "${var.use_neutron}"
|
count = "${var.use_neutron}"
|
||||||
router_id = "${openstack_networking_router_v2.k8s[count.index].id}"
|
router_id = "%{if openstack_networking_router_v2.k8s != []}${openstack_networking_router_v2.k8s[count.index].id} %{else}${var.router_id} %{endif}"
|
||||||
subnet_id = "${openstack_networking_subnet_v2.k8s[count.index].id}"
|
subnet_id = "${openstack_networking_subnet_v2.k8s[count.index].id}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
output "router_id" {
|
output "router_id" {
|
||||||
value = "${element(concat(openstack_networking_router_v2.k8s.*.id, list("")), 0)}"
|
value = "%{if var.use_neutron == 1} ${var.router_id == null ? element(concat(openstack_networking_router_v2.k8s.*.id, [""]), 0) : var.router_id} %{else} %{endif}"
|
||||||
}
|
}
|
||||||
|
|
||||||
output "router_internal_port_id" {
|
output "router_internal_port_id" {
|
||||||
value = "${element(concat(openstack_networking_router_interface_v2.k8s.*.id, list("")), 0)}"
|
value = "${element(concat(openstack_networking_router_interface_v2.k8s.*.id, [""]), 0)}"
|
||||||
}
|
}
|
||||||
|
|
||||||
output "subnet_id" {
|
output "subnet_id" {
|
||||||
value = "${element(concat(openstack_networking_subnet_v2.k8s.*.id, list("")), 0)}"
|
value = "${element(concat(openstack_networking_subnet_v2.k8s.*.id, [""]), 0)}"
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,3 +13,5 @@ variable "dns_nameservers" {
|
||||||
variable "subnet_cidr" {}
|
variable "subnet_cidr" {}
|
||||||
|
|
||||||
variable "use_neutron" {}
|
variable "use_neutron" {}
|
||||||
|
|
||||||
|
variable "router_id" {}
|
||||||
|
|
|
@ -220,3 +220,8 @@ variable "use_access_ip" {
|
||||||
variable "use_server_groups" {
|
variable "use_server_groups" {
|
||||||
default = false
|
default = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "router_id" {
|
||||||
|
description = "uuid of an externally defined router to use"
|
||||||
|
default = null
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue