Skip to content

test/e2e/run: Adjust tests to make script and TF plan work in offline environments - #1500

Open
ggouzi wants to merge 1 commit into
canonical:mainfrom
ggouzi:update-e2e-tests-for-offline-envs
Open

test/e2e/run: Adjust tests to make script and TF plan work in offline environments#1500
ggouzi wants to merge 1 commit into
canonical:mainfrom
ggouzi:update-e2e-tests-for-offline-envs

Conversation

@ggouzi

@ggouzi ggouzi commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

In offline environments, the e2e tests do not work because we relied on:

  • A default hardcoded remote ubuntu-minimal-daily
  • A default hardcoded project/profile

In offline envs, we have an additional remote pointing to custom simplestreams LXD mirrors. We also have custom profiles with cloud-init-user-data so the images apt sources and snap proxy are overridden to point to local mirrors. We may also share images across projects (features.images=false)

This PR aims to tackle down those changes to make the script and TF plan work in offline environments. Tested and confirmed to be working in an offline production environment.

Added the following variables

  • image_remote (string)

  • image_project (string)

  • copy_image_aliases (bool)

  • project (string)

  • create_project (bool)

  • profile (string)

  • create_profile (bool)

  • Checklist

  • I have read the contributing guidelines and attest that all commits in this PR are signed off, cryptographically signed, and follow this project's commit structure.

  • I have checked and added or updated relevant documentation.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts the e2e Terraform plan and runner script to support offline environments by making LXD image sourcing and project/profile selection configurable, instead of relying on hardcoded defaults.

Changes:

  • Adds new Terraform variables to configure image remote/project and whether to copy image aliases, plus project/profile creation toggles.
  • Updates Terraform resources to use the new variables (optional project/profile creation; configurable image caching behavior).
  • Updates the test/e2e/run helper to consistently operate against a configurable LXD project and pass it into Terraform.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
test/e2e/variables.tf Introduces new variables for image sourcing and project/profile configuration.
test/e2e/main.tf Applies new variables to LXD project/profile, cached images, and instance creation (including optional resource creation).
test/e2e/run Uses a configurable PROJECT for lxc operations and passes project into terraform apply/destroy.
test/e2e/terraform.tfvars.offline.example Adds an offline example tfvars file showing how to set the new variables.
Suppressed comments (2)

test/e2e/variables.tf:26

  • copy_image_aliases description references source_remote, but the variable exposed to users is image_remote and main.tf uses var.image_remote. This is confusing when configuring offline environments.
variable "copy_image_aliases" {
  description = "Whether to copy the source image's aliases to the cached image copy. Set to true if source_remote's images carry aliases"
  type        = bool
  default     = false
}

test/e2e/terraform.tfvars.offline.example:16

  • Minor grammar: "Can be configure" should be "Can be configured" (and "re-use" is usually written as "reuse").
# LXD project/profile to use. By default, a project and profile named e2e-testing
# Can be configure to re-use an existing project/profile

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread test/e2e/variables.tf
Comment thread test/e2e/terraform.tfvars.offline.example Outdated
@ggouzi ggouzi changed the title test/e2e/run: Adjust tests to make script and TF plan work in offline… test/e2e/run: Adjust tests to make script and TF plan work in offline environments Aug 13, 2026

@roosterfish roosterfish left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, please have a look at my comments.

Also please make sure the commits are squashed accordingly, I saw there were some from the copilot suggestions I assume. They should be integrated with the actual code changes.
It might also help to commit the changes in smaller chunks. One commit that adds new vars, one that uses it and so on.

Comment thread test/e2e/variables.tf Outdated
default = "e2e-testing"
}

variable "create_project" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for project and profile: Can we please check if the project exists and if not simply create it?
Otherwise when you want to reuse an existing one, you have to not only provide its name, but also have to set create_* var to false.

Comment thread test/e2e/main.tf Outdated
# Project
resource "lxd_project" "e2e" {
name = "e2e-testing"
count = var.create_project ? 1 : 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead let's check whether or not the project/profile already exists.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking if profile/project exist implies using local-exec bash commands no ? Or is there a better way to check ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was you could maybe use the profile or project resource to check if they exist?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data lxd_project and data lxd_profile are plain read data sources but the real objects in LXD API can have been created outside TF (not managed by TF plan)

Won't they error if the resource doesn't exist ?

Switched to external type with bash commands for now

Comment thread test/e2e/main.tf Outdated
project = lxd_project.e2e.name
remote = lxd_project.e2e.remote
count = var.create_profile ? 1 : 0
name = var.profile

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can still derive the project/remote from the lxd_project? It's id doesn't change, only its display name based on the var.

Comment thread test/e2e/main.tf
Comment thread test/e2e/terraform.tfvars.custom-image-server.example
@roosterfish

Copy link
Copy Markdown
Contributor

Please also commit -s to ensure each commit as a Signed-off-by line to pass the DCO stage.

… environments

Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Gaëtan GOUZI <gouzi.gaetan@gmail.com>

remove boolean create_profile/create_project + check exist instead + rename example file

Signed-off-by: ggouzi <gaetan.gouzi@canonical.com>
@ggouzi
ggouzi force-pushed the update-e2e-tests-for-offline-envs branch from 0046f9e to 8f116f5 Compare August 14, 2026 11:25
Comment thread test/e2e/main.tf
# Project
# Check whether the project already exists
data "external" "project_exists" {
program = ["bash", "-c", "lxc project list \"${var.remote}:\" -f csv | awk -F, '{gsub(/ \\(current\\)$/, \"\", $1); print $1}' | grep -qxF \"${var.project}\" && echo '{\"exists\": \"true\"}' || echo '{\"exists\": \"false\"}'"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used AI for this ugly command FYI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants