Infrastructure as Code
You can use the Nullstone UI to configure your applications and infrastructure, but there are times when you want to configure in code. Placing configuration in code allows you to track infrastructure changes in version control, share configuration with your team, and automate configuration.
Pipeline and Workflow
Having configuration in code also allows you to correlate infrastructure changes with code changes. As an example, lets say you are adding a new feature that requires the use of new infrastructure. In the same commit or PR, you can add both the configuration to the IaC (infrastructure as code) file and the code for the new feature. As the PR is opened, a preview environment might be created and launched. Because the configuration is in the IaC file, the preview environment will be configured with the new infrastructure. You can test the new feature in the preview environment and ensure it works as expected. Once the PR is merged, all the infrastructure changes will be applied to all of your environments including production.
IaC File
A Nullstone IaC file is a YAML file and must be placed in the .nullstone
directory of your repo. For preview environments this file must be named previews.yaml
.
The format of the IaC file is similar to a docker-compose file. An example is shown below.
version: "0.1"
apps:
acme-api:
vars:
service_count: 1
service_cpu: 256
service_memory: 512
environment:
DATABASE_URL: "{{ POSTGRES_URL }}"
ANOTHER_VAR: abc123
At the root of the file, first specify the IaC file version. The current version is 0.1
.
Next, specify all the applications you want to configure. Each application should be listed by its unique name. It must match the name of the application in Nullstone.
vars
For each application, you can configure variables and environment variables. The vars
section is used to provide configuration for your application. Depending on the application module you are using, different variables may be available.
To see the available variables, check out the module's documentation in the Nullstone Registry. For example, if you are using the aws-fargate-service
module, you can find the list of available variables here.
Another way to determine the list of available variables is to check the Configuration
tab for your application in the UI.
If you don't include a variable in your IaC file, it is no problem. Nullstone will use the default value. However, if you specify a variable that doesn't exist, an error will occur during launch.
vars:
service_count: 1
service_cpu: 256
service_memory: 512
From the example above, we are explicitly setting the service_count
to 1
, service_cpu
to 256
, and service_memory
to 512
. All other variables will use the default values.
environment
The environment
section is used to configure environment variables for the application. Specify as many key/value pairs as you like. Any environment variables not specified in the IaC file will be removed from the application at the next launch. Interpolation is also supported when specifying environment variables in the IaC file. You can use interpolation to build new environment variables from other environment variables. Check out the guide on Environment Variables for more information.
environment:
DATABASE_URL: "{{ POSTGRES_URL }}"
ANOTHER_VAR: abc123
When configuring environment variables in the UI, you can mark sensitive values as secrets. Secrets are not currently supported in the IaC file.