Skip to content

Commit

Permalink
Terraform/OpenStack: Enable usage of an existing router
Browse files Browse the repository at this point in the history
  • Loading branch information
qvicksilver committed Apr 3, 2020
1 parent e732df5 commit 10dca78
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
10 changes: 10 additions & 0 deletions contrib/terraform/openstack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions contrib/terraform/openstack/kubespray.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
9 changes: 7 additions & 2 deletions contrib/terraform/openstack/modules/network/main.tf
Original file line number Diff line number Diff line change
@@ -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}"
Expand All @@ -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}"
}
6 changes: 3 additions & 3 deletions contrib/terraform/openstack/modules/network/outputs.tf
Original file line number Diff line number Diff line change
@@ -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)}"
}
2 changes: 2 additions & 0 deletions contrib/terraform/openstack/modules/network/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ variable "dns_nameservers" {
variable "subnet_cidr" {}

variable "use_neutron" {}

variable "router_id" {}
5 changes: 5 additions & 0 deletions contrib/terraform/openstack/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 10dca78

Please sign in to comment.