Skip to content

[Suggestion] Flexible Runtime Variable Management for Configurations #466

@rrmistry

Description

@rrmistry

Problem Being Solved For

Currently, environment variables can only be assigned to values at the bundle level, not the module level. While it is possible to assign Timoni runtime tags to module-level values for setting them via environment variables, this process can be cumbersome and error-prone.

For example:

// bundle.cue
package bundle

bundle: {
	apiVersion: "v1alpha1"
	name:       string | *"my-timoni-app" @timoni(runtime:string:RELEASE)

	_env:                string | *"dev"                  @timoni(runtime:string:ENVIRONMENT_NAME)
	_namespace:          string | *"my-app"               @timoni(runtime:string:KUBERNETES_NAMESPACE)
	_timoniRegistryHost: string | *"mycompany.azurecr.io" @timoni(runtime:string:TIMONI_REGISTRY_HOST)

	instances: {
		"\(name)": {
			module: {
				url:     string | *"oci://\(_timoniRegistryHost)/timoni/module" @timoni(runtime:string:TIMONI_MODULE_REPOSITORY)
				version: string | *"latest"                                     @timoni(runtime:string:TIMONI_BUILD_TAG)
			}
			namespace: _namespace
			values:    #BundleValues
		}
	}
}

And corresponding values:

// values.cue
package bundle

#BundleValues: {
	frontend: {
		image: {
			repository: string @timoni(runtime:string:IMAGE_REPOSITORY_FRONTEND)
			tag:        string @timoni(runtime:string:IMAGE_TAG_FRONTEND)
		}
	}
	api: {
		image: {
			repository: string @timoni(runtime:string:IMAGE_REPOSITORY_API)
			tag:        string @timoni(runtime:string:IMAGE_TAG_API)
		}
	}
}

This approach requires developers to explicitly map each value to a unique environment variable, introducing complexity and increasing the risk of naming collisions.

Proposal

To simplify configuration management and expand its flexibility, Timoni should integrate a configuration management library like spf13/viper (or an equivalent). This enhancement would enable users to manage both module-level and bundle-level values effortlessly.

Key Benefits:

  • Enhanced Format Support: Ability to define defaults and read configurations from formats like JSON, YAML, TOML, HCL, envfiles, and Java properties.
  • Dynamic Configuration: Support for live watching and reloading of config files (optional).
  • Centralized Management: Read values from environment variables, command-line flags, remote config systems (e.g., etcd, Consul), and even buffers.
  • Reduced Boilerplate: Eliminate the need to tag each value explicitly, reducing setup time and improving maintainability.
  • No Collisions: Automatic management of environment variable namespaces to avoid conflicts.

This approach would not only simplify the developer experience but also unlock new possibilities, such as:

  • More dynamic configurations with live reloads.
  • Cleaner module definitions with reduced boilerplate.
  • Greater flexibility for different deployment environments.

By adopting a widely-used library like Viper, Timoni can deliver a powerful and developer-friendly configuration experience while maintaining compatibility with existing setups.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions