diff --git a/ctf/deploy.py b/ctf/deploy.py index e6294a3..960fa18 100644 --- a/ctf/deploy.py +++ b/ctf/deploy.py @@ -46,6 +46,14 @@ def deploy( remote: Annotated[ str, typer.Option("--remote", help="Incus remote to deploy to") ] = "local", + vm_remote: Annotated[ + str | None, + typer.Option("--vm-remote", help="Incus remote for VM to be deployed to"), + ] = None, + vm_project: Annotated[ + str | None, + typer.Option("--vm-project", help="Incus project for VM to be deployed to"), + ] = None, redeploy: Annotated[ bool, typer.Option("--redeploy", help="Do not use. Use `ctf redeploy` instead.") ] = False, @@ -76,6 +84,8 @@ def deploy( exclude_tracks=exclude_tracks, production=production, remote=remote, + vm_remote=vm_remote, + vm_project=vm_project, redeploy=redeploy, ) @@ -355,11 +365,7 @@ def terraform_apply( production: bool, remote: str, ) -> set[Track]: - args = [ - terraform_binary(), - "apply", - "-auto-approve", - ] + args = [terraform_binary(), "apply", "-auto-approve"] try: subprocess.run( diff --git a/ctf/generate.py b/ctf/generate.py index c43465f..fb87680 100644 --- a/ctf/generate.py +++ b/ctf/generate.py @@ -44,6 +44,14 @@ def generate( remote: Annotated[ str, typer.Option("--remote", help="Incus remote to deploy to") ] = "local", + vm_remote: Annotated[ + str | None, + typer.Option("--vm-remote", help="Incus remote for VM to be deployed to"), + ] = None, + vm_project: Annotated[ + str | None, + typer.Option("--vm-project", help="Incus project for VM to be deployed to"), + ] = None, redeploy: Annotated[ bool, typer.Option("--redeploy", help="Do not use. Use `ctf redeploy` instead.") ] = False, @@ -81,6 +89,8 @@ def generate( production=production, require_build_container=does_track_require_build_container(track), has_virtual_machine=track_has_virtual_machine(track), + vm_project=vm_project, + vm_remote=vm_remote, ) ) distinct_tracks = tmp_tracks diff --git a/ctf/models.py b/ctf/models.py index ee63e04..7319e99 100644 --- a/ctf/models.py +++ b/ctf/models.py @@ -19,6 +19,8 @@ class Track(BaseModel): # Every object is unique on it's name name: IncusStr remote: str = "local" + vm_remote: str | None = None + vm_project: str | None = None production: bool = False require_build_container: bool = False has_virtual_machine: bool = False diff --git a/ctf/redeploy.py b/ctf/redeploy.py index 09fa0d9..1c3262a 100644 --- a/ctf/redeploy.py +++ b/ctf/redeploy.py @@ -28,6 +28,14 @@ def redeploy( remote: Annotated[ str, typer.Option("--remote", help="Incus remote to deploy to") ] = "local", + vm_remote: Annotated[ + str | None, + typer.Option("--vm-remote", help="Incus remote for VM to be deployed to"), + ] = None, + vm_project: Annotated[ + str | None, + typer.Option("--vm-project", help="Incus project for VM to be deployed to"), + ] = None, force: Annotated[ bool, typer.Option( @@ -63,6 +71,8 @@ def redeploy( tracks=tracks, production=production, remote=remote, + vm_remote=vm_remote, + vm_project=vm_project, redeploy=True, force=force, skip_build=skip_build, diff --git a/ctf/templates/init/.deploy/common/variables.tf b/ctf/templates/init/.deploy/common/variables.tf index f9041fe..8623707 100644 --- a/ctf/templates/init/.deploy/common/variables.tf +++ b/ctf/templates/init/.deploy/common/variables.tf @@ -3,6 +3,16 @@ variable "incus_remote" { type = string } +variable "incus_vm_remote" { + default = null + type = string +} + +variable "incus_vm_project" { + default = null + type = string +} + variable "deploy" { default = "dev" type = string diff --git a/ctf/utils.py b/ctf/utils.py index 1130a57..9ffa53a 100644 --- a/ctf/utils.py +++ b/ctf/utils.py @@ -138,6 +138,8 @@ def add_tracks_to_terraform_modules(tracks: set[Track]): already_deployed = {{ 'true' if track.already_deployed else 'false' }} {% if track.production %}deploy = "production"{% endif %} {% if track.remote %}incus_remote = "{{ track.remote }}"{% endif %} + {% if track.vm_remote %}incus_vm_remote = "{{ track.vm_remote }}"{% endif %} + {% if track.vm_project %}incus_vm_project = "{{ track.vm_project }}"{% endif %} {% for ov in output_variables %} {{ ov }} = module.common.{{ ov }} {% endfor %} @@ -154,7 +156,12 @@ def add_tracks_to_terraform_modules(tracks: set[Track]): ) -def create_terraform_modules_file(remote: str, production: bool = False): +def create_terraform_modules_file( + remote: str, + vm_remote: str | None = None, + vm_project: str | None = None, + production: bool = False, +): with open( file=os.path.join(find_ctf_root_directory(), ".deploy", "modules.tf"), mode="w+" ) as fd: @@ -165,12 +172,21 @@ def create_terraform_modules_file(remote: str, production: bool = False): source = "./common" {% if production %}deploy = "production"{% endif %} {% if remote %}incus_remote = "{{ remote }}"{% endif %} + {% if vm_remote %}incus_vm_remote = "{{ vm_remote }}"{% endif %} + {% if vm_project %}incus_vm_project = "{{ track.vm_project }}"{% endif %} } """ ) ) - fd.write(template.render(production=production, remote=remote)) + fd.write( + template.render( + production=production, + remote=remote, + vm_remote=vm_remote, + vm_project=vm_project, + ) + ) def get_common_modules_output_variables() -> set[str]: diff --git a/pyproject.toml b/pyproject.toml index f3cb4c3..2a06fdc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ dependencies = [ "typer==0.24.1", "pydantic", ] -version = "4.5.2" +version = "4.6.0" classifiers = [ "Programming Language :: Python :: 3", "Operating System :: OS Independent",