cloud-foundation-fabric/modules/cloud-config-container/simple-nva/main.tf

133 lines
3.9 KiB
Terraform
Raw Normal View History

/**
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
locals {
_files = merge(
{
"/var/run/nva/ipprefix_by_netmask.sh" = {
content = file("${path.module}/files/ipprefix_by_netmask.sh")
owner = "root"
permissions = "0744"
}
"/var/run/nva/policy_based_routing.sh" = {
content = file("${path.module}/files/policy_based_routing.sh")
owner = "root"
permissions = "0744"
}
}, {
for path, attrs in var.files : path => {
content = attrs.content,
owner = attrs.owner,
permissions = attrs.permissions
}
},
try(var.frr_config != null, false) ? {
"/etc/frr/daemons" = {
content = templatefile("${path.module}/files/frr/daemons", local._frr_daemons_enabled)
owner = "root"
permissions = "0744"
}
"/etc/frr/frr.conf" = {
# content can either be the path to the config file or the config string
content = try(file(var.frr_config.config_file), var.frr_config.config_file)
owner = "root"
permissions = "0744"
}
"/etc/systemd/system/frr.service" = {
content = file("${path.module}/files/frr/frr.service")
owner = "root"
permissions = "0644"
}
"/var/lib/docker/daemon.json" = {
content = <<EOF
{
"live-restore": true,
"storage-driver": "overlay2",
"log-opts": {
"max-size": "1024m"
}
}
EOF
owner = "root"
permissions = "0644"
}
} : {}
)
2023-03-27 00:54:01 -07:00
_frr_daemons = {
2023-03-27 02:42:17 -07:00
"zebra" : []
"bgpd" : ["179"]
"ospfd" : []
"ospf6d" : []
"ripd" : ["520"]
"ripngd" : ["521"]
"isisd" : []
"pimd" : []
"ldpd" : ["646"]
"nhrpd" : []
2023-03-27 00:54:01 -07:00
"eigrpd" : []
2023-03-27 02:42:17 -07:00
"babeld" : []
"sharpd" : []
"staticd" : []
"pbrd" : []
"bfdd" : ["3784"]
"fabricd" : []
2023-03-27 00:54:01 -07:00
}
_frr_daemons_enabled = try(
{
2023-03-27 00:54:01 -07:00
for daemon in keys(local._frr_daemons) :
"${daemon}_enabled" => contains(var.frr_config.daemons_enabled, daemon) ? "yes" : "no"
}, {})
2023-03-27 00:54:01 -07:00
_frr_required_ports = try(
[
for daemon, ports in local._frr_daemons : contains(var.frr_config.daemons_enabled, daemon) ? ports : []
2023-03-27 02:42:17 -07:00
], [])
2023-03-27 00:54:01 -07:00
_local_firewall_ports = concat(var.optional_firewall_open_ports, flatten(local._frr_required_ports))
_network_interfaces = [
for index, interface in var.network_interfaces : {
name = "eth${index}"
number = index
routes = interface.routes
enable_masquerading = interface.enable_masquerading != null ? interface.enable_masquerading : false
non_masq_cidrs = interface.non_masq_cidrs != null ? interface.non_masq_cidrs : []
}
]
_optional_run_cmds = (
try(var.frr_config != null, false)
? concat(["systemctl start frr"], var.optional_run_cmds)
: var.optional_run_cmds
)
_template = (
var.cloud_config == null
? "${path.module}/cloud-config.yaml"
: var.cloud_config
)
cloud_config = templatefile(local._template, {
enable_health_checks = var.enable_health_checks
files = local._files
2023-03-27 00:54:01 -07:00
firewall_open_ports = local._local_firewall_ports
network_interfaces = local._network_interfaces
optional_run_cmds = local._optional_run_cmds
})
}