Skip to content

Commit 5ffd503

Browse files
Merge pull request #54 from canonical/test/terraform
Test/terraform
2 parents e2caad5 + 99c422b commit 5ffd503

File tree

4 files changed

+215
-5
lines changed

4 files changed

+215
-5
lines changed

.github/workflows/pull-request.yaml

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,34 @@ jobs:
2525
output-method: inject
2626
git-push: "true"
2727

28-
terraform-lint:
28+
terraform-validate:
2929
runs-on: ubuntu-latest
3030
steps:
3131
- uses: actions/checkout@v6
32-
with:
33-
ref: ${{ github.event.pull_request.head.ref }}
34-
- name: Lint Terraform
35-
uses: actionshub/terraform-lint@main
32+
- name: Install dependencies
33+
run: |
34+
sudo apt update
35+
sudo apt install -y tox
36+
sudo snap install terraform --classic
37+
- name: Validate Terraform
38+
run: |
39+
tox -e terraform-validate
40+
41+
terraform-test:
42+
needs: terraform-validate
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v6
46+
- name: Install dependencies
47+
run: |
48+
sudo apt update
49+
sudo apt install -y tox
50+
sudo snap install terraform --classic
51+
sudo snap install concierge --classic
52+
sudo concierge prepare --preset microk8s
53+
- name: Test Terraform
54+
run: |
55+
tox -e terraform-test
3656
3757
pull-request:
3858
name: PR

terraform/tests/main.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
data "juju_model" "model" {
2+
name = "testing"
3+
owner = "admin"
4+
}
5+
6+
variable "channel" {
7+
description = "The channel to use when deploying a charm"
8+
type = string
9+
default = "latest/edge"
10+
}
11+
12+
terraform {
13+
required_providers {
14+
juju = {
15+
version = "~> 1.0"
16+
source = "juju/juju"
17+
}
18+
}
19+
}
20+
21+
provider "juju" {}
22+
23+
module "cos_registration_server_k8s" {
24+
app_name = "cos-registration-server"
25+
source = "./.."
26+
channel = var.channel
27+
model_uuid = data.juju_model.model.uuid
28+
units = 1
29+
}

terraform/tests/main.tftest.hcl

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
run "basic_deploy" {
2+
3+
assert {
4+
condition = module.cos_registration_server_k8s.app_name == "cos-registration-server"
5+
error_message = "app_name did not match expected default value"
6+
}
7+
8+
# Test requires integration endpoints - check count
9+
assert {
10+
condition = length(module.cos_registration_server_k8s.requires) == 6
11+
error_message = "Expected 6 required integration endpoints"
12+
}
13+
14+
# Test requires integration endpoints - check specific keys
15+
assert {
16+
condition = contains(keys(module.cos_registration_server_k8s.requires), "catalogue")
17+
error_message = "requires output is missing 'catalogue' endpoint"
18+
}
19+
20+
assert {
21+
condition = contains(keys(module.cos_registration_server_k8s.requires), "ingress")
22+
error_message = "requires output is missing 'ingress' endpoint"
23+
}
24+
25+
assert {
26+
condition = contains(keys(module.cos_registration_server_k8s.requires), "logging")
27+
error_message = "requires output is missing 'logging' endpoint"
28+
}
29+
30+
assert {
31+
condition = contains(keys(module.cos_registration_server_k8s.requires), "tracing")
32+
error_message = "requires output is missing 'tracing' endpoint"
33+
}
34+
35+
assert {
36+
condition = contains(keys(module.cos_registration_server_k8s.requires), "logging_alerts_devices")
37+
error_message = "requires output is missing 'logging_alerts_devices' endpoint"
38+
}
39+
40+
assert {
41+
condition = contains(keys(module.cos_registration_server_k8s.requires), "send_remote_write_alerts_devices")
42+
error_message = "requires output is missing 'send_remote_write_alerts_devices' endpoint"
43+
}
44+
45+
# Test requires integration endpoints - check exact values
46+
assert {
47+
condition = module.cos_registration_server_k8s.requires["catalogue"] == "catalogue"
48+
error_message = "requires.catalogue endpoint did not match expected value"
49+
}
50+
51+
assert {
52+
condition = module.cos_registration_server_k8s.requires["ingress"] == "ingress"
53+
error_message = "requires.ingress endpoint did not match expected value"
54+
}
55+
56+
assert {
57+
condition = module.cos_registration_server_k8s.requires["logging"] == "logging"
58+
error_message = "requires.logging endpoint did not match expected value"
59+
}
60+
61+
assert {
62+
condition = module.cos_registration_server_k8s.requires["tracing"] == "tracing"
63+
error_message = "requires.tracing endpoint did not match expected value"
64+
}
65+
66+
assert {
67+
condition = module.cos_registration_server_k8s.requires["logging_alerts_devices"] == "logging-alerts-devices"
68+
error_message = "requires.logging_alerts_devices endpoint did not match expected value"
69+
}
70+
71+
assert {
72+
condition = module.cos_registration_server_k8s.requires["send_remote_write_alerts_devices"] == "send-remote-write-alerts-devices"
73+
error_message = "requires.send_remote_write_alerts_devices endpoint did not match expected value"
74+
}
75+
76+
# Test provides integration endpoints - check count
77+
assert {
78+
condition = length(module.cos_registration_server_k8s.provides) == 5
79+
error_message = "Expected 5 provided integration endpoints"
80+
}
81+
82+
# Test provides integration endpoints - check specific keys
83+
assert {
84+
condition = contains(keys(module.cos_registration_server_k8s.provides), "grafana_dashboard")
85+
error_message = "provides output is missing 'grafana_dashboard' endpoint"
86+
}
87+
88+
assert {
89+
condition = contains(keys(module.cos_registration_server_k8s.provides), "grafana_dashboard_devices")
90+
error_message = "provides output is missing 'grafana_dashboard_devices' endpoint"
91+
}
92+
93+
assert {
94+
condition = contains(keys(module.cos_registration_server_k8s.provides), "probes")
95+
error_message = "provides output is missing 'probes' endpoint"
96+
}
97+
98+
assert {
99+
condition = contains(keys(module.cos_registration_server_k8s.provides), "probes_devices")
100+
error_message = "provides output is missing 'probes_devices' endpoint"
101+
}
102+
103+
assert {
104+
condition = contains(keys(module.cos_registration_server_k8s.provides), "auth_devices_keys")
105+
error_message = "provides output is missing 'auth_devices_keys' endpoint"
106+
}
107+
108+
# Test provides integration endpoints - check exact values
109+
assert {
110+
condition = module.cos_registration_server_k8s.provides["grafana_dashboard"] == "grafana-dashboard"
111+
error_message = "provides.grafana_dashboard endpoint did not match expected value"
112+
}
113+
114+
assert {
115+
condition = module.cos_registration_server_k8s.provides["grafana_dashboard_devices"] == "grafana-dashboard-devices"
116+
error_message = "provides.grafana_dashboard_devices endpoint did not match expected value"
117+
}
118+
119+
assert {
120+
condition = module.cos_registration_server_k8s.provides["probes"] == "probes"
121+
error_message = "provides.probes endpoint did not match expected value"
122+
}
123+
124+
assert {
125+
condition = module.cos_registration_server_k8s.provides["probes_devices"] == "probes-devices"
126+
error_message = "provides.probes_devices endpoint did not match expected value"
127+
}
128+
129+
assert {
130+
condition = module.cos_registration_server_k8s.provides["auth_devices_keys"] == "auth-devices-keys"
131+
error_message = "provides.auth_devices_keys endpoint did not match expected value"
132+
}
133+
134+
}

tox.ini

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,30 @@ deps =
106106
pytest-operator
107107
commands =
108108
pytest -vv --tb native --log-cli-level=INFO --color=yes -s {posargs} {toxinidir}/tests/integration
109+
110+
[testenv:terraform-format]
111+
description = Format terraform files
112+
commands =
113+
terraform fmt -recursive
114+
allowlist_externals =
115+
terraform
116+
117+
[testenv:terraform-validate]
118+
description = Validate terraform files
119+
changedir = {toxinidir}/terraform
120+
commands =
121+
terraform fmt -check -recursive -diff
122+
terraform init -backend=false
123+
terraform validate
124+
allowlist_externals =
125+
terraform
126+
127+
[testenv:terraform-test]
128+
description = Test terraform modules
129+
changedir = {toxinidir}/terraform/tests
130+
depends = terraform-validate
131+
commands =
132+
terraform init
133+
terraform test -verbose
134+
allowlist_externals =
135+
terraform

0 commit comments

Comments
 (0)