Dagger
Search

vmtemplate

Packer and Vault, optionally driven by Git-hosted configurations.

This module is designed for infrastructure automation involving dynamic VM
image generation in vSphere environments. It supports building templates via
Packer with secure secret injection from Vault (AppRole or token-based),
optionally sourcing the build configuration from a Git repository.

The primary function RunVsphereWorkflow orchestrates this process. It clones
a Packer configuration from Git or uses a provided local directory, then
invokes the Bake function to initialize and optionally build the template.
Secrets such as vSphere credentials or config values are fetched from Vault
and injected securely into the Packer process.

This module is well-suited for use within Dagger-based CI/CD pipelines or
automated image delivery systems. Its integration with Vault ensures secrets
never touch the disk, while Git integration makes the workflow reproducible.

Future enhancements planned include:
- Creating and validating test VMs from newly built templates
- Running Ansible-based verification and post-provisioning logic
- Performing automated template promotion and cleanup
- Supporting versioned GitOps-style workflows for image release

This documentation provides an overview of the current implementation and
serves as a foundation for extending the VM lifecycle automation further.

Installation

dagger install github.com/stuttgart-things/blueprints/vmtemplate@v1.72.0

Entrypoint

Return Type
Vmtemplate
Example
dagger -m github.com/stuttgart-things/blueprints/vmtemplate@f3d10202deba4f1726692e874a8eb109b33b4184 call \
func (m *MyModule) Example() *dagger.Vmtemplate  {
	return dag.
			Vmtemplate()
}
@function
def example() -> dagger.Vmtemplate:
	return (
		dag.vmtemplate()
	)
@func()
example(): Vmtemplate {
	return dag
		.vmtemplate()
}

Types

Vmtemplate 🔗

bake() 🔗

Return Type
String !
Arguments
NameTypeDefault ValueDescription
packerConfigDirDirectory !-No description provided
packerConfigString !-No description provided
packerVersionString "1.13.1"The Packer version to use
archString "linux_amd64"The Packer arch
initOnlyBoolean falseIf true, only init packer w/out build
vaultAddrString -vaultAddr
vaultRoleIdSecret -vaultRoleID
vaultSecretIdSecret -vaultSecretID
vaultTokenSecret -vaultToken
Example
dagger -m github.com/stuttgart-things/blueprints/vmtemplate@f3d10202deba4f1726692e874a8eb109b33b4184 call \
 bake --packer-config-dir DIR_PATH --packer-config string
func (m *MyModule) Example(ctx context.Context, packerConfigDir *dagger.Directory, packerConfig string) string  {
	return dag.
			Vmtemplate().
			Bake(ctx, packerConfigDir, packerConfig)
}
@function
async def example(packer_config_dir: dagger.Directory, packer_config: str) -> str:
	return await (
		dag.vmtemplate()
		.bake(packer_config_dir, packer_config)
	)
@func()
async example(packerConfigDir: Directory, packerConfig: string): Promise<string> {
	return dag
		.vmtemplate()
		.bake(packerConfigDir, packerConfig)
}

cloneGitRepository() 🔗

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
scmString "github"Source code management (SCM) version to use
repositoryString !-No description provided
tokenSecret !-No description provided
Example
dagger -m github.com/stuttgart-things/blueprints/vmtemplate@f3d10202deba4f1726692e874a8eb109b33b4184 call \
 clone-git-repository --repository string --token env:MYSECRET
func (m *MyModule) Example(repository string, token *dagger.Secret) *dagger.Directory  {
	return dag.
			Vmtemplate().
			CloneGitRepository(repository, token)
}
@function
def example(repository: str, token: dagger.Secret) -> dagger.Directory:
	return (
		dag.vmtemplate()
		.clone_git_repository(repository, token)
	)
@func()
example(repository: string, token: Secret): Directory {
	return dag
		.vmtemplate()
		.cloneGitRepository(repository, token)
}

renderAndCommit() 🔗

RenderAndCommit renders templates and optionally commits the result to a GitHub branch with an optional pull request.

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
packerTemplatesDirDirectory !-Directory containing packer template files (.tmpl)
packerTemplatesString !-Comma-separated list of packer template files to render
testVmTemplatesDirDirectory -Directory containing test VM template files (.tmpl)
testVmTemplatesString -Comma-separated list of test VM template files to render
buildDirDirectory !-Directory containing build-specific variables and static files
envDirDirectory -Additional directory containing shared variable files (e.g., environment configs)
variablesFilesString !-Comma-separated list of YAML variable files to merge, in priority order (last wins)
overridesString -Comma-separated key=value overrides with highest priority (e.g., "isoChecksum=abc123,cpus=16")
repositoryString -GitHub repository (e.g., "stuttgart-things/stuttgart-things")
tokenSecret -GitHub authentication token
branchNameString -Branch name for the commit
baseBranchString "main"Base branch to create from
createBranchBoolean falseCreate a new branch before committing
commitConfigBoolean falseCommit rendered files to the branch
createPullRequestBoolean falseCreate a pull request after committing
commitMessageString -Commit message
packerDestinationPathString -Destination path in the repository for packer files
testVmDestinationPathString -Destination path in the repository for test VM files
pullRequestTitleString -Pull request title
pullRequestBodyString -Pull request body
Example
dagger -m github.com/stuttgart-things/blueprints/vmtemplate@f3d10202deba4f1726692e874a8eb109b33b4184 call \
 render-and-commit --packer-templates-dir DIR_PATH --packer-templates string --build-dir DIR_PATH --variables-files string
func (m *MyModule) Example(packerTemplatesDir *dagger.Directory, packerTemplates string, buildDir *dagger.Directory, variablesFiles string) *dagger.Directory  {
	return dag.
			Vmtemplate().
			RenderAndCommit(packerTemplatesDir, packerTemplates, buildDir, variablesFiles)
}
@function
def example(packer_templates_dir: dagger.Directory, packer_templates: str, build_dir: dagger.Directory, variables_files: str) -> dagger.Directory:
	return (
		dag.vmtemplate()
		.render_and_commit(packer_templates_dir, packer_templates, build_dir, variables_files)
	)
@func()
example(packerTemplatesDir: Directory, packerTemplates: string, buildDir: Directory, variablesFiles: string): Directory {
	return dag
		.vmtemplate()
		.renderAndCommit(packerTemplatesDir, packerTemplates, buildDir, variablesFiles)
}

renderBuildConfig() 🔗

RenderBuildConfig renders templates by merging multiple YAML variable files (environment + OS + build overrides) into a single context. Later files override earlier ones. Returns a directory with rendered files.

Return Type
Directory !
Arguments
NameTypeDefault ValueDescription
templatesDirDirectory !-Directory containing the template files (.tmpl)
templatesString !-Comma-separated list of template files to render
buildDirDirectory !-Directory containing build-specific variable files and static files
variablesFilesString !-Comma-separated list of YAML variable files to merge, in order of priority (last wins)
envDirDirectory -Additional directory containing shared variable files (e.g., environment configs)
overridesString -Comma-separated key=value overrides with highest priority (e.g., "isoChecksum=abc123,cpus=16")
Example
dagger -m github.com/stuttgart-things/blueprints/vmtemplate@f3d10202deba4f1726692e874a8eb109b33b4184 call \
 render-build-config --templates-dir DIR_PATH --templates string --build-dir DIR_PATH --variables-files string
func (m *MyModule) Example(templatesDir *dagger.Directory, templates string, buildDir *dagger.Directory, variablesFiles string) *dagger.Directory  {
	return dag.
			Vmtemplate().
			RenderBuildConfig(templatesDir, templates, buildDir, variablesFiles)
}
@function
def example(templates_dir: dagger.Directory, templates: str, build_dir: dagger.Directory, variables_files: str) -> dagger.Directory:
	return (
		dag.vmtemplate()
		.render_build_config(templates_dir, templates, build_dir, variables_files)
	)
@func()
example(templatesDir: Directory, templates: string, buildDir: Directory, variablesFiles: string): Directory {
	return dag
		.vmtemplate()
		.renderBuildConfig(templatesDir, templates, buildDir, variablesFiles)
}

runVsphereWorkflow() 🔗

Return Type
String !
Arguments
NameTypeDefault ValueDescription
packerConfigString !-The Packer configuration file name (after rendering, e.g., "vsphere-base-os.pkr.hcl")
packerVersionString "1.13.1"The Packer version to use
archString "linux_amd64"The Packer arch
initOnlyBoolean falseIf true, only init packer w/out build
vaultAddrString -vaultAddr
vaultRoleIdSecret -vaultRoleID
vaultSecretIdSecret -vaultSecretID
vaultTokenSecret -vaultToken
packerTemplatesDirDirectory !-Directory containing packer template files (.tmpl), e.g., packer/templates/packer
packerTemplatesString !-Comma-separated list of packer template files to render (e.g., "vsphere-base-os.pkr.hcl.tmpl,user-data.tmpl")
testVmTemplatesDirDirectory -Directory containing test VM template files (.tmpl), e.g., packer/templates/test-vm
testVmTemplatesString -Comma-separated list of test VM template files to render (e.g., "test-vm.tf.tmpl,state.tf.tmpl")
buildDirDirectory !-Directory containing build-specific variables and static files (e.g., base-os.yaml, meta-data)
envDirDirectory -Directory containing shared environment variable files (e.g., packer/environments)
variablesFilesString !-Comma-separated list of YAML variable files to merge, in priority order (last wins)
overridesString -Comma-separated key=value overrides with highest priority (e.g., "isoChecksum=abc123,cpus=16")
testVmBoolean falseEnable test VM creation and validation before promotion
testPlaybooksString -Comma-separated Ansible playbook paths for test VM validation
testRequirementsFile -Ansible requirements file for test playbooks
ansibleWaitTimeoutInteger 30Seconds to wait for test VM before running Ansible
sshUserSecret -SSH user for test VM
sshPasswordSecret -SSH password for test VM
ansibleParametersString -Ansible parameters for test playbooks (e.g., "key1=value1,key2=value2")
ansibleInventoryTypeString "simple"Ansible inventory type: "simple" or "cluster"
promoteTemplateBoolean falseEnable golden image promotion (rename, move, delete old)
goldenTemplateNameString -Target name for the golden template (e.g., "ubuntu25-base")
goldenTemplateFolderString -vCenter folder to move the golden template to (e.g., "/LabUL/vm/golden")
vcenterSecret -vCenter URL for govc operations
vcenterUsernameSecret -vCenter username for govc operations
vcenterPasswordSecret -vCenter password for govc operations
Example
dagger -m github.com/stuttgart-things/blueprints/vmtemplate@f3d10202deba4f1726692e874a8eb109b33b4184 call \
 run-vsphere-workflow --packer-config string --packer-templates-dir DIR_PATH --packer-templates string --build-dir DIR_PATH --variables-files string
func (m *MyModule) Example(ctx context.Context, packerConfig string, packerTemplatesDir *dagger.Directory, packerTemplates string, buildDir *dagger.Directory, variablesFiles string) string  {
	return dag.
			Vmtemplate().
			RunVsphereWorkflow(ctx, packerConfig, packerTemplatesDir, packerTemplates, buildDir, variablesFiles)
}
@function
async def example(packer_config: str, packer_templates_dir: dagger.Directory, packer_templates: str, build_dir: dagger.Directory, variables_files: str) -> str:
	return await (
		dag.vmtemplate()
		.run_vsphere_workflow(packer_config, packer_templates_dir, packer_templates, build_dir, variables_files)
	)
@func()
async example(packerConfig: string, packerTemplatesDir: Directory, packerTemplates: string, buildDir: Directory, variablesFiles: string): Promise<string> {
	return dag
		.vmtemplate()
		.runVsphereWorkflow(packerConfig, packerTemplatesDir, packerTemplates, buildDir, variablesFiles)
}