Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit f7581ce

Browse files
committed
refactor: reorganize templates directory structure
- Move templates/provision/tofu/ to templates/tofu/ - Move templates/provision/cloud-init.yml to templates/tofu/cloud-init.yml - Remove empty templates/provision/ directory - Update all code references to use new paths - Update documentation in README.md - All tests pass (unit, integration, container, e2e)
1 parent d3a8f4f commit f7581ce

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ carmel exec -- ./bin/torrust-deploy provision
102102

103103
This command will:
104104

105-
1. Copy OpenTofu configuration templates from `templates/provision/` directory
105+
1. Copy OpenTofu configuration templates from `templates/tofu/` directory
106106
2. Initialize OpenTofu if needed
107107
3. Create a minimal Ubuntu 22.04 LTS VM with hardcoded configuration
108108
4. Wait for cloud-init completion via SSH monitoring

lib/TorrustDeploy/OpenTofu.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ sub copy_templates {
4646
# Ensure tofu directory exists
4747
$tofu_dir->mkpath unless $tofu_dir->exists;
4848

49-
my $templates_dir = path('templates/provision');
49+
my $templates_dir = path('templates');
5050

5151
# Check if templates directory exists
5252
unless ($templates_dir->exists) {
@@ -65,7 +65,7 @@ sub copy_templates {
6565
say "Copied: $main_tf_template -> $main_tf_dest";
6666

6767
# Copy cloud-init.yml template
68-
my $cloud_init_template = $templates_dir->child('cloud-init.yml');
68+
my $cloud_init_template = $templates_dir->child('tofu/cloud-init.yml');
6969
my $cloud_init_dest = $tofu_dir->child('cloud-init.yml');
7070

7171
unless ($cloud_init_template->exists) {

t/e2e/provision.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ subtest 'cleanup leftover resources from previous runs' => sub {
9898
};
9999

100100
# Ensure we have required templates
101-
ok(-f 'templates/provision/tofu/providers/libvirt/main.tf', 'Required OpenTofu template exists');
102-
ok(-f 'templates/provision/cloud-init.yml', 'Required cloud-init template exists');
101+
ok(-f 'templates/tofu/providers/libvirt/main.tf', 'Required OpenTofu template exists');
102+
ok(-f 'templates/tofu/cloud-init.yml', 'Required cloud-init template exists');
103103

104104
subtest 'provision command executes successfully' => sub {
105105
plan tests => 3;

t/unit/command/provision.t

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ subtest 'Provision command is discoverable by app' => sub {
3131

3232
subtest 'Template files exist and are readable' => sub {
3333
my $project_root = path($Bin)->parent->parent->parent;
34-
my $templates_dir = $project_root->child('templates/provision');
34+
my $templates_dir = $project_root->child('templates');
3535

36-
ok($templates_dir->exists, 'Templates/provision directory exists');
37-
ok($templates_dir->is_dir, 'Templates/provision directory is a directory');
36+
ok($templates_dir->exists, 'Templates directory exists');
37+
ok($templates_dir->is_dir, 'Templates directory is a directory');
3838

3939
my $main_tf_template = $templates_dir->child('tofu/providers/libvirt/main.tf');
40-
my $cloud_init_template = $templates_dir->child('cloud-init.yml');
40+
my $cloud_init_template = $templates_dir->child('tofu/cloud-init.yml');
4141

4242
ok($main_tf_template->exists, 'main.tf template exists');
4343
ok($main_tf_template->is_file, 'main.tf template is a file');
@@ -50,15 +50,15 @@ subtest 'Template files exist and are readable' => sub {
5050

5151
subtest 'Template files have expected content' => sub {
5252
my $project_root = path($Bin)->parent->parent->parent;
53-
my $templates_dir = $project_root->child('templates/provision');
53+
my $templates_dir = $project_root->child('templates');
5454

5555
my $main_tf_content = $templates_dir->child('tofu/providers/libvirt/main.tf')->slurp_utf8;
5656
like($main_tf_content, qr/required_providers/, 'main.tf contains provider configuration');
5757
like($main_tf_content, qr/libvirt/, 'main.tf contains libvirt provider');
5858
like($main_tf_content, qr/libvirt_domain/, 'main.tf contains domain resource');
5959
like($main_tf_content, qr/torrust-tracker/, 'main.tf contains torrust-tracker VM name');
6060

61-
my $cloud_init_content = $templates_dir->child('cloud-init.yml')->slurp_utf8;
61+
my $cloud_init_content = $templates_dir->child('tofu/cloud-init.yml')->slurp_utf8;
6262
like($cloud_init_content, qr/^#cloud-config/, 'cloud-init.yml has cloud-config header');
6363
like($cloud_init_content, qr/hostname:\s*torrust-tracker/, 'cloud-init.yml sets hostname');
6464
like($cloud_init_content, qr/name:\s*torrust/, 'cloud-init.yml creates torrust user');
@@ -77,10 +77,10 @@ subtest 'Provision command template copying functionality' => sub {
7777

7878
# Test the _copy_templates method directly
7979
my $project_root = path($Bin)->parent->parent->parent;
80-
my $templates_dir = $project_root->child('templates/provision');
80+
my $templates_dir = $project_root->child('templates');
8181

8282
# Test that template directory exists
83-
ok($templates_dir->exists, 'Source templates/provision directory exists');
83+
ok($templates_dir->exists, 'Source templates directory exists');
8484

8585
# Create the target directory
8686
$test_tofu_dir->mkpath;
@@ -104,7 +104,7 @@ subtest 'Provision command template copying functionality' => sub {
104104

105105
# Verify content matches the templates
106106
my $main_tf_template = $templates_dir->child('tofu/providers/libvirt/main.tf');
107-
my $cloud_init_template = $templates_dir->child('cloud-init.yml');
107+
my $cloud_init_template = $templates_dir->child('tofu/cloud-init.yml');
108108

109109
is($target_main_tf->slurp_utf8, $main_tf_template->slurp_utf8, 'main.tf content matches template');
110110
is($target_cloud_init->slurp_utf8, $cloud_init_template->slurp_utf8, 'cloud-init.yml content matches template');

t/unit/opentofu.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ subtest 'OpenTofu template copying functionality' => sub {
2929
$test_tofu_dir->mkpath;
3030

3131
# Verify templates directory exists before testing
32-
my $templates_dir = path('templates/provision');
32+
my $templates_dir = path('templates');
3333
skip_all "Templates directory not found: $templates_dir" unless $templates_dir->exists;
3434

3535
# Test the copy_templates method
@@ -47,7 +47,7 @@ subtest 'OpenTofu template copying functionality' => sub {
4747

4848
# Verify content matches the templates if templates exist
4949
my $main_tf_template = $templates_dir->child('tofu/providers/libvirt/main.tf');
50-
my $cloud_init_template = $templates_dir->child('cloud-init.yml');
50+
my $cloud_init_template = $templates_dir->child('tofu/cloud-init.yml');
5151

5252
if ($main_tf_template->exists && $cloud_init_template->exists) {
5353
is($target_main_tf->slurp_utf8, $main_tf_template->slurp_utf8, 'main.tf content matches template');
File renamed without changes.

0 commit comments

Comments
 (0)