Utilising Doppler for managing environment variable configuration
Published: 2022-05-31 06:34:35

## What are environment variables and why are they important?

Environment variables are key-value pairs that are used during the execution/runtime of a program. This may be a connection string to the database, or ports used for listening to incoming traffic.

Every developer has at least 2 environments. A development environment where most of the work is done and a production environment where users interact with your product. There is a clear separation of resources in those environments. 

For example, You have a database set up locally for testing functionality and a database in production containing user-generated data that we don't want to temper during our tests. In this instance, we maintain two connection variables that we can switch according to the environment we are currently working on. 

These variables are usually maintained in separate files from the source code by design to allow you to make changes to the variables without affecting your source code. 


## What is the conventional way of managing environment variables?   

One of the common ways to manage environment variables adopted by developers is the usage of a separate file that contains multiple key-value pairs that represent the variables utilized in the application. This file is usually never added to any version control system. It is often added manually to the directory/site of deployment. It is also added as a hidden file in the file system (eg Linux) by prefixing the file with “**.**”. 

Most projects that utilise version control systems often contain a sample of the environment variables file that is usually postfixed by the -example.format name to inform new developers of the environment variables required to execute the project or existing developers of new variables added by fellow contributors.   

It is usually written in JSON, YAML or TEXT file formats.


## Drawbacks of the conventional way

At ClickPesa, we maintain multiple environments that are used in our development and release cycle. Each environment variable contains its own set of “key-value” pairs that dictate the behaviour of the application(s).

Our release cycle contains automated tests that are performed on the automated build and deployment process. We needed a way to call upon these secret key-value pairs during the testing process just as how it should work in any given environment when a user interacts with our application. 



* Does that mean we need to duplicate the same file and provide it as input to the build-test-deploy process? 
* How do we deal with changes to the file in a development cycle?

The two above questions can be resolved with an introduction of a centralized area where we can store our environment variables and call them from anywhere. Whether that is a Bitbucket pipeline, Github Action, Virtual Private Server, Lambda function etc.


## What is Doppler

Doppler is a SaaS platform that streamlines environment variables management with an intuitive dashboard, powerful CLI, and integrations for syncing secrets across development environments, cloud providers, hosting platforms, CI/CD tools, Docker, Kubernetes, and Terraform.

Doppler solves our need to centralize and version our environment variables across our applications with interoperable tools. 

We use it to configure environment variables for specific locations in the file system where our applications are hosted inside a VPC. This means we can maintain different versions of the same application according to the context of the environment. 

These variables can be updated by using scripts defined in our build-test-deployment process.


## Conclusion

For more information please use the following [link](https://blog.doppler.com/series/tutorials) for a practical guide on how you can use doppler in your current working environment.