From aeeef1ea5c43af2af85c1e95d8e32cd6c5bd7fea Mon Sep 17 00:00:00 2001 From: Hemanth Nakkina Date: Thu, 9 Jan 2025 14:19:03 +0530 Subject: [PATCH] Deploy Ubuntu pro on machine model Ubuntu pro is hardcoded to deploy on controller model. Change the logic to deploy on machine model. --- .../sunbeam/features/pro/etc/deploy-pro/main.tf | 8 ++------ .../sunbeam/features/pro/etc/deploy-pro/variables.tf | 5 +++++ sunbeam-python/sunbeam/features/pro/feature.py | 2 +- sunbeam-python/tests/unit/sunbeam/features/test_pro.py | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/main.tf b/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/main.tf index 103e2515..1479d66a 100644 --- a/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/main.tf +++ b/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/main.tf @@ -26,14 +26,10 @@ terraform { provider "juju" {} -data "juju_model" "controller" { - name = "controller" -} - resource "juju_application" "ubuntu_pro" { count = var.token != "" ? 1 : 0 name = "ubuntu-pro" - model = data.juju_model.controller.name + model = var.machine-model units = 0 charm { @@ -49,7 +45,7 @@ resource "juju_application" "ubuntu_pro" { resource "juju_integration" "juju_info" { count = var.token != "" ? 1 : 0 - model = data.juju_model.controller.name + model = var.machine-model application { name = "sunbeam-machine" diff --git a/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/variables.tf b/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/variables.tf index a7b9349f..0d667bb0 100644 --- a/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/variables.tf +++ b/sunbeam-python/sunbeam/features/pro/etc/deploy-pro/variables.tf @@ -19,6 +19,11 @@ variable "ubuntu-advantage-channel" { default = "latest/edge" } +variable "machine-model" { + description = "Name of model to deploy ubuntu-pro into." + type = string +} + variable "token" { description = "Ubuntu Pro token to use to attach support subscriptions" type = string diff --git a/sunbeam-python/sunbeam/features/pro/feature.py b/sunbeam-python/sunbeam/features/pro/feature.py index 2325d580..037a545c 100644 --- a/sunbeam-python/sunbeam/features/pro/feature.py +++ b/sunbeam-python/sunbeam/features/pro/feature.py @@ -94,7 +94,7 @@ def is_skip(self, status: Status | None = None) -> Result: def run(self, status: Status | None = None) -> Result: """Apply terraform configuration to deploy ubuntu-pro.""" - extra_tfvars = {"token": self.token} + extra_tfvars = {"machine-model": self.model, "token": self.token} try: self.tfhelper.update_tfvars_and_apply_tf( self.client, diff --git a/sunbeam-python/tests/unit/sunbeam/features/test_pro.py b/sunbeam-python/tests/unit/sunbeam/features/test_pro.py index 4945f538..42947d7a 100644 --- a/sunbeam-python/tests/unit/sunbeam/features/test_pro.py +++ b/sunbeam-python/tests/unit/sunbeam/features/test_pro.py @@ -72,7 +72,7 @@ def test_enable(self): self.client, self.manifest, tfvar_config=None, - override_tfvars={"token": self.token}, + override_tfvars={"machine-model": self.model, "token": self.token}, ) self.jhelper.wait_application_ready.assert_called_once() assert result.result_type == ResultType.COMPLETED