Skip to content

Commit 7b5f405

Browse files
committed
Implement issue 406
coauthored with chatgpt codex 5.2
1 parent 20eeccf commit 7b5f405

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

common/variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ variable "config_git_url" {
7474
type = string
7575
description = "URL to the Magic Castle Puppet configuration git repo"
7676
validation {
77-
condition = can(regex("^https://.*\\.git$", var.config_git_url))
78-
error_message = "The config_git_url variable must be an https url to a git repo."
77+
condition = can(regex("^(https://.*\\.git|/.*|file:///.+)$", var.config_git_url))
78+
error_message = "The config_git_url variable must be an https url to a git repo or an absolute local path (optionally prefixed with file://)."
7979
}
8080
}
8181

docs/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,11 @@ config_git_url = "https://oauth2:${oauth-key-goes-here}@domain.com/username/repo
328328
```
329329
This works for GitHub and GitLab (including community edition).
330330

331+
For the `incus` provider only, `config_git_url` can also be an absolute local
332+
path (or `file:///...`) to a git repository on the host running Incus. The
333+
repository is mounted into the puppet server at `/opt/magic-castle/puppetenv`
334+
and cloned via `file:///opt/magic-castle/puppetenv`.
335+
331336
**Post build modification effect**: no effect. To change the Puppet configuration source,
332337
destroy the cluster or change it manually on the Puppet server.
333338

incus/infrastructure.tf

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ module "design" {
1111
bastion_tags = var.bastion_tags
1212
}
1313

14+
locals {
15+
config_git_url_is_local = can(regex("^(file://|/)", var.config_git_url))
16+
config_git_url_host_path = local.config_git_url_is_local ? (startswith(var.config_git_url, "file://") ? replace(var.config_git_url, "file://", "") : var.config_git_url) : ""
17+
config_git_url_mount_path = "/opt/magic-castle/puppetenv"
18+
config_git_url_effective = local.config_git_url_is_local ? "file://${local.config_git_url_mount_path}" : var.config_git_url
19+
}
20+
1421
module "configuration" {
1522
source = "../common/configuration"
1623
inventory = local.inventory
1724
post_inventory = local.post_inventory
18-
config_git_url = var.config_git_url
25+
config_git_url = local.config_git_url_effective
1926
config_version = var.config_version
2027
sudoer_username = var.sudoer_username
2128
public_keys = var.public_keys
@@ -115,6 +122,18 @@ resource "incus_instance" "instances" {
115122
}
116123
}
117124

125+
dynamic "device" {
126+
for_each = local.config_git_url_is_local && contains(each.value.tags, "puppet") ? { puppetenv = local.config_git_url_host_path } : {}
127+
content {
128+
type = "disk"
129+
name = "puppetenv"
130+
properties = {
131+
source = device.value
132+
path = local.config_git_url_mount_path
133+
}
134+
}
135+
}
136+
118137
dynamic "device" {
119138
for_each = incus_storage_volume.filesystems
120139
content {

0 commit comments

Comments
 (0)