Terraform/OpenStack: Enable usage of an existing router (#5890)

This commit is contained in:
qvicksilver 2020-04-06 11:41:46 +02:00 committed by GitHub
parent e732df56a1
commit 0d2990510e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 5 deletions

View file

@ -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
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
You can create many different kubernetes topologies by setting the number of
different classes of hosts. For each class there are options for allocating

View file

@ -12,6 +12,7 @@ module "network" {
dns_nameservers = "${var.dns_nameservers}"
network_dns_domain = "${var.network_dns_domain}"
use_neutron = "${var.use_neutron}"
router_id = "${var.router_id}"
}
module "ips" {

View file

@ -1,10 +1,15 @@
resource "openstack_networking_router_v2" "k8s" {
name = "${var.cluster_name}-router"
count = "${var.use_neutron}"
count = "${var.use_neutron}" == 1 && "${var.router_id}" == null ? 1 : 0
admin_state_up = "true"
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" {
name = "${var.network_name}"
count = "${var.use_neutron}"
@ -23,6 +28,6 @@ resource "openstack_networking_subnet_v2" "k8s" {
resource "openstack_networking_router_interface_v2" "k8s" {
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}"
}

View file

@ -1,11 +1,11 @@
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" {
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" {
value = "${element(concat(openstack_networking_subnet_v2.k8s.*.id, list("")), 0)}"
value = "${element(concat(openstack_networking_subnet_v2.k8s.*.id, [""]), 0)}"
}

View file

@ -13,3 +13,5 @@ variable "dns_nameservers" {
variable "subnet_cidr" {}
variable "use_neutron" {}
variable "router_id" {}

View file

@ -220,3 +220,8 @@ variable "use_access_ip" {
variable "use_server_groups" {
default = false
}
variable "router_id" {
description = "uuid of an externally defined router to use"
default = null
}