Skip to content

Commit

Permalink
Add configuration option for maas-region to setup TLS Termination on …
Browse files Browse the repository at this point in the history
…it's end. Change agent-service to agent_service to comply with underscore convention
  • Loading branch information
wyattrees committed Aug 28, 2024
1 parent 5f430d0 commit 854a095
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions anvil-python/anvil/commands/haproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
AddMachineUnitsStep,
DeployMachineApplicationStep,
)
from sunbeam.utils import get_local_ip_by_default_route

from anvil.jobs.manifest import Manifest
from anvil.jobs.steps import RemoveMachineUnitStep
Expand Down Expand Up @@ -71,6 +70,7 @@ def validate_key_file(filepath: str | None) -> None:
except PermissionError:
raise ValueError(f"Permission denied when trying to read {filepath}")


def validate_virtual_ip(value: str) -> str:
"""We allow passing an empty IP for virtual_ip"""
if value == "":
Expand Down Expand Up @@ -229,7 +229,7 @@ def get_tls_services_yaml(self) -> str:
- http-request redirect scheme https unless { ssl_fc }
server_options: maxconn 100 cookie S{i} check
crts: [DEFAULT]
- service_name: agent-service
- service_name: agent_service
service_host: 0.0.0.0
service_port: 80
service_options:
Expand Down
10 changes: 9 additions & 1 deletion anvil-python/anvil/commands/maas_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

from sunbeam.clusterd.client import Client
from sunbeam.commands.terraform import TerraformInitStep
from sunbeam.jobs import questions
from sunbeam.jobs.common import BaseStep
from sunbeam.jobs.juju import JujuHelper
from sunbeam.jobs.steps import (
AddMachineUnitsStep,
DeployMachineApplicationStep,
)

from anvil.commands.haproxy import HAPROXY_CONFIG_KEY
from anvil.jobs.manifest import Manifest
from anvil.jobs.steps import RemoveMachineUnitStep

Expand Down Expand Up @@ -70,7 +72,13 @@ def extra_tfvars(self) -> dict[str, Any]:
if self.client.cluster.list_nodes_by_role("haproxy")
else False
)
return {"enable_haproxy": enable_haproxy}
variables: dict[str, Any] = {"enable_haproxy": enable_haproxy}
haproxy_vars: dict[str, Any] = questions.load_answers(
self.client, HAPROXY_CONFIG_KEY
)
if enable_haproxy and "ssl_cert" in haproxy_vars:
variables["tls_mode"] = "termination"
return variables


class AddMAASRegionUnitsStep(AddMachineUnitsStep):
Expand Down
9 changes: 8 additions & 1 deletion cloud/etc/deploy-maas-region/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ data "juju_model" "machine_model" {
name = var.machine_model
}

locals {
tls_mode = var.tls_mode != "" ? { tls_mode = var.tls_mode } : {}
}

resource "juju_application" "maas-region" {
name = "maas-region"
model = data.juju_model.machine_model.name
Expand All @@ -42,7 +46,10 @@ resource "juju_application" "maas-region" {
base = "ubuntu@22.04"
}

config = var.charm_maas_region_config
config = merge(
local.tls_mode,
var.charm_maas_region_config,
)
}

resource "juju_application" "pgbouncer" {
Expand Down
6 changes: 6 additions & 0 deletions cloud/etc/deploy-maas-region/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,9 @@ variable "max_connections_per_region" {
type = number
default = 50
}

variable "tls_mode" {
description = "TLS Mode for MAAS Region charm ('', 'termination', or 'passthrough')"
type = string
default = ""
}

0 comments on commit 854a095

Please sign in to comment.