Skip to content

Comments

feat: Tests for product module channel input#185

Draft
MichaelThamm wants to merge 5 commits intotrack/2from
feat/channel-tf-tests
Draft

feat: Tests for product module channel input#185
MichaelThamm wants to merge 5 commits intotrack/2from
feat/channel-tf-tests

Conversation

@MichaelThamm
Copy link
Contributor

@MichaelThamm MichaelThamm commented Feb 10, 2026

  • Merge this into main as well
  • Update the READMEs so they mention track/2
  • Fix the just lint-terraform-docs since it doesn't actually lint, it just formats it.
    • Add this to the central TF CI (requires each charm repo to have a tf-docs file?)

Issue

If a user specifies the TF COS (or COS Lite) modules

  1. without a ref "git::.../observability-stack//terraform/cos-lite then they must use track dev
  2. with a ref "git::.../observability-stack//terraform/cos-lite?ref=track/2 then they must use track 2

I noticed some users make this mistake (and I) where you try out a different track, e.g. dev, but leave the module source as ?ref=track/2 and notice a failure to deploy.

Solution

module "cos-lite" {
  source                          = "../../cos-lite"
  model_uuid                      = juju_model.cos-lite.uuid
  channel                         = "3/stable"
}
╷
│ Error: Invalid value for variable
│ 
│   on root.tf line 19, in module "cos-lite":
│   19:   channel                         = "3/stable"
│     ├────────────────
│     │ var.channel is "3/stable"
│ 
│ The track (the part before the '/') of the channel must match the default.
│ 
│ This was checked by the validation rule at ../../cos-lite/variables.tf:18,3-13.

Checklist

  • I have added or updated relevant documentation.
  • PR title makes an appropriate release note and follows conventional commits syntax.
  • Merge target is the correct branch, and relevant tandem backport PRs opened.

Context

Testing Instructions

Running Terraform tests:

  • tf -chdir=terraform/cos test
  • tf -chdir=terraform/cos-lite test

will result in running unit tests for channel validation

tests/channel_validation.tftest.hcl... in progress
  run "valid_channel_track"... pass
  run "valid_channel_stable"... pass
  run "valid_channel_candidate"... pass
  run "valid_channel_beta"... pass
  run "invalid_channel_track"... pass
  run "invalid_channel_track_numeric"... pass
  run "invalid_channel_track_string"... pass
  run "invalid_channel_track_dev"... pass
tests/channel_validation.tftest.hcl... tearing down
tests/channel_validation.tftest.hcl... pass

Success! 8 passed, 0 failed.

Upgrade Notes

default = "2/stable"

validation {
condition = split("/", var.channel)[0] == split("/", "2/stable")[0]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
condition = split("/", var.channel)[0] == split("/", "2/stable")[0]
condition = split("/", var.channel)[0] == "2"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or even better, use starts_with("3-lts")


validation {
condition = split("/", var.channel)[0] == split("/", "2/stable")[0]
error_message = "The track (the part before the '/') of the channel must match the default."
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update this to specify the actual track, not "default"

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.

1 participant