A Terraform provider that allows you to manage Anomalo resources in bulk.
Benefits:
- Version controlled, declarative configuration
- Bulk actions (ex with
for_each
) - Line-by-line diffs
- Collaboration, via cloud based state and resource locks to keep you from overwriting a teammate's work
- Variables
- ex. update the notification time for all checks with a single variable change
- Use the same (or similar) check across tables & environments
- Integrate with your existing workflow
Full provider documentation is here.
See example.tf
for a sample configuration.
First, install Terraform.
To use the provider, include it in your Terraform configuration and run terraform init
.
terraform {
required_providers {
anomalo = {
source = "square/anomalo"
}
}
}
You'll need to provide an API token and instance host to authenticate with Anomalo. These can be provided explicitly or in environment variables ANOMALO_INSTANCE_HOST
and ANOMALO_API_SECRET_TOKEN
. Running terraform plan
should output no errors if the plugin connects successfully.
This section shows a minimal example that connects to Anomalo and configures a new table with terraform.
Copy the following terraform code into a new or existing terraform directory, replacing values where necessary:
# Tell Terraform to install the provider
terraform {
required_providers {
anomalo = {
source = "square/anomalo"
}
}
}
# Provide credentials
provider "anomalo" {
host = "https://anomalo.example.com" # Your Anomalo host
token = "<token>" # Your Anomalo API token
}
# Configure the table
resource "anomalo_table" "MyTable" {
# Replace with a table you want to configure. It must already be accesible by Anomalo but not be configured.
table_name = "square.items.variations" # Must include the warehouse name (in this case, Square)
check_cadence_type = "daily" # Whether to run checks at a set time (daily) or on arrival
check_cadence_run_at_duration = "PT6H" # 6 AM Pacific Time
always_alert_on_errors = true
}
- Run
terraform init
(if you haven't already) - Run
terraform plan
to preview changes - Run
terraform apply
to configure the table in Anomalo
This table is now tracked by terraform. If you make changes in the Anomalo UI or API, Terraform will notify you what changed when you run terraform plan
.
To see a complete configuration, jump to this section.
To import tables and checks that have already been created in Anomalo, jump to this section.
See examples/example.tf
here.
To manage resources that are already configured in Anomalo you must import them. Both tables and checks implement terraform import
.
See the plugin documentation for details on each resource.
To import a table (or multiple tables) and all of its existing checks, use the Python script provided in the bootstrap
folder. This script will import the state for each table and all of its checks, and write the configuration to a .tf
file (one file per table).
- Download the
bootstrap
folder contents into the root of your terraform directory. - [Optional] Create a virtual environment
python -m venv env && source env/bin/activate
- Run
pip install -r requirements.txt
- Create a file
tables.txt
with a line-separated list of tables to bootstrap.- Table names should be fully qualified with the warehouse name - i.e.
square.items.variations
5.SetANOMALO_INSTANCE_HOST
andANOMALO_API_SECRET_TOKEN
environment variables - Optionally set them via command line arugments:
--anomalo-host
and--anomalo-token
- Table names should be fully qualified with the warehouse name - i.e.
- Run
python3 download_tables.py --table-file tables.txt
After executing the script, you should have one .tf
file per table. Run terraform plan
to make sure it worked. You may need to make some configuration updates manually.
--