Variables

Variables

Confix has the concept of variables. These variables are typically used to reference secrets, or any configuration data that should not be directly entered into the configuration files. They can be used for values are not known at development time.

In Confix, variables have a distinct structure: $providerName:path.to.resource, where providerName refers to the source or provider of the variable value, and path.to.resource indicates the specific resource or secret in the provider's repository. Variables may be nested in strings. in that case the variable must be placed within double curly braces like {{$provider:path.to.resource}}.

Variables are resolved during the build operation of the configuration. This operation can take place at various stages of your development lifecycle. You can also validate your configuration against a specific environment to ensure that all variables can be resolved before deployment. For more on this, checkout Deployments .

During project initialization, all potential variables are fetched from the providers (if possible), offering intelligent code completion during your development.

Providers

Variable providers are typically defined in the .confixrc or .confix.solution files but can also be defined in .confix.project.

The variableProviders property determines the variable providers that are available for your project. These providers assist in resolving variables present in your configuration files.

Each variable provider is identified by a name, which is how it's referenced in your config files. For instance, if you have a variable provider defined as "name": "secret", it can be referenced in your configuration files using $secret.

The type field defines the type of the provider. Each type carries its specific configuration. For example, the azure-keyvault type would require configuration related to Azure Keyvault, while the secret type would need details about public and private keys.

The environmentOverride property lets you override provider-specific configuration based on the environment. This can be useful when, for instance, a provider has different URLs for different environments like development, staging, or production.

Sample

{
  "name": "local",
  "type": "local",
  "path": "./variables.json",
  "environmentOverride": {
    "dev": {
      "path": "./variables.dev.json"
    }
  }
}

This provider would use the ./variables.json unless the environment is dev, in which case ./variables.dev.json would be used.

Sample Configuration

Here is an example JSON demonstrating the structure of the variableProviders property:

.confixrc
{
  "variableProviders": [
    {
      "name": "local",
      "type": "local",
      "path": "./variables.json"
    },
    {
      "name": "keyvault",
      "type": "azure-keyvault",
      "environmentOverride": {
        "dev": {
          "uri": "https://mykeyvault-dev.vault.azure.net"
        },
        "qa": {
          "uri": "https://mykeyvault-qa.vault.azure.net"
        },
        "prod": {
          "uri": "https://mykeyvault-prod.vault.azure.net"
        }
      }
    }
  ]
}

Supported Providers

TypeDescriptionsDocs
azure-keyvaultVariables stored in an Azure KeyVaultDocs↗
gitfetch variables stored in a separate git repositoryDocs↗
localreference local variables stored in a json fileDocs↗
secretinline the secrets using public-private key encryptionDocs↗

Additional can be easily implemented. Contributions are welcomed.

Example JSON with Variables

Here's an example JSON configuration file that uses Confix variables:

{
  "database": {
    "connectionString": "$keyvault:database.connectionString",
    "maxPoolSize": 12
  },
  "logging": {
    "level": "$git:logging.level",
    "destinatin": "$git:logging.server.url"
  },
  "appSecrets": {
    "apiKey": "$secret:aHR0cHM6Ly93d3cueW91dHViZS5jb20vd2F0Y2g/dj1hM1o3ekVjN0FYUQ==",
    "jwtSecret": "$vault:jwt.secret"
  },
  "clients": {
    "baseUrl": "{{$keyvault:api.baseUrl}}/my-endpoint"
  }
}

Commands

Confix provides the following commands to manage variables

  • confix variables list: This command lists all available variables from the providers.
  • confix variables set: This command sets the value for a specified variable.
  • confix variables get <name>: This command retrieves the current value of a specified variable.