In this section you will learn how to use Lynx RESTful API and the terraform provider to automate the boring stuff.
We provide a Swagger/OpenAPI Specification that defines the structure and behavior of a RESTful API. You can use the swagger editor to render the API documentation or check this online guide
Here’s a brief documentation on how to use this API:
The API requires authentication using an API key. The key should be included in the Authorization header with the value Bearer <api_key>
.
Users
GET /api/v1/user
- Get a list of usersPOST /api/v1/user
- Create a new userGET /api/v1/user/{id}
- Get a userPUT /api/v1/user/{id}
- Update a userDELETE /api/v1/user/{id}
- Delete a userTeams
POST /api/v1/team
- Create a new teamGET /api/v1/team
- Get a list of teamsGET /api/v1/team/{id}
- Get a teamPUT /api/v1/team/{id}
- Update a teamDELETE /api/v1/team/{id}
- Delete a teamProjects
POST /api/v1/project
- Create a new projectGET /api/v1/project
- Get a list of projectsGET /api/v1/project/{id}
- Get a projectPUT /api/v1/project/{id}
- Update a projectDELETE /api/v1/project/{id}
- Delete a projectEnvironments
POST /api/v1/project/{projectId}/environment
- Create a new environmentGET /api/v1/project/{projectId}/environment
- Get a list of environmentsGET /api/v1/project/{projectId}/environment/{environmentId}
- Get an environmentPUT /api/v1/project/{projectId}/environment/{environmentId}
- Update an environmentDELETE /api/v1/project/{projectId}/environment/{environmentId}
- Delete an environmentSnapshots
POST /api/v1/snapshot
- Create a new snapshotGET /api/v1/snapshot
- Get a list of snapshotsGET /api/v1/snapshot/{id}
- Get a snapshotPUT /api/v1/snapshot/{id}
- Update a snapshotDELETE /api/v1/snapshot/{id}
- Delete a snapshotThe API expects JSON request bodies for creating/updating resources like users, teams, projects, environments, and snapshots. The request schemas are defined under #/components/schemas
, for example:
UserCreate
for creating a new userTeamUpdate
for updating an existing teamProjectCreate
for creating a new projectEnvironmentUpdate
for updating an environmentSnapshotCreate
for creating a new snapshotThe API returns JSON responses with data and metadata. Successful responses include:
201 Created
when a new resource is created, returning the new resource object200 OK
when getting or updating an existing resource, returning the resource object204 No Content
when deleting a resource successfullyError responses include:
404 Not Found
if the requested resource does not exist500 Internal Server Error
for any other errors, with an ErrorResponse object providing detailsThe response schemas are defined under #/components/schemas
as well, such as:
User
for user objectsTeam
for team objectsProject
for project objectsEnvironment
for environment objectsSnapshot
for snapshot objectsFor list endpoints that return multiple resources, the response contains:
limit
, offset
, and totalCount
So in summary, the requests accept JSON for creating/updating, and the responses return JSON data or error objects and standard HTTP status codes.
Here is an example to setup team, team users, project, project environment and a snapshot using our terraform provider.
terraform {
required_providers {
lynx = {
source = "Clivern/lynx"
version = "0.3.0"
}
}
}
provider "lynx" {
api_url = "http://localhost:4000/api/v1"
api_key = "~api key here~"
}
resource "lynx_user" "stella" {
name = "Stella"
email = "[email protected]"
role = "regular"
password = "~password-here~"
}
resource "lynx_user" "skylar" {
name = "Skylar"
email = "[email protected]"
role = "regular"
password = "~password-here~"
}
resource "lynx_user" "erika" {
name = "Erika"
email = "[email protected]"
role = "regular"
password = "~password-here~"
}
resource "lynx_user" "adriana" {
name = "Adriana"
email = "[email protected]"
role = "regular"
password = "~password-here~"
}
resource "lynx_team" "monitoring" {
name = "Monitoring"
slug = "monitoring"
description = "System Monitoring Team"
members = [
lynx_user.stella.id,
lynx_user.skylar.id,
lynx_user.erika.id,
lynx_user.adriana.id
]
}
resource "lynx_project" "grafana" {
name = "Grafana"
slug = "grafana"
description = "Grafana Project"
team = {
id = lynx_team.monitoring.id
}
}
resource "lynx_environment" "prod" {
name = "Development"
slug = "dev"
username = "~username-here~"
secret = "~secret-here~"
project = {
id = lynx_project.grafana.id
}
}
resource "lynx_snapshot" "my_snapshot" {
title = "Grafana Project Snapshot"
description = "Grafana Project Snapshot"
record_type = "project"
record_id = lynx_project.grafana.id
team = {
id = lynx_team.monitoring.id
}
}
The provided code is a Terraform configuration that uses the lynx
provider to manage resources in a hypothetical API. Here’s a brief explanation:
The required_providers
block specifies that the lynx provider
(version 0.3.0
) should be used. The provider block configures the lynx provider
with the API URL
and API key
.
lynx_user
resources create four users (Stella, Skylar, Erika, and Adriana) with regular roles and specified email addresses and passwords.lynx_team
resource creates a team named “Monitoring” with the four users as members.lynx_project
resource creates a project named “Grafana” and associates it with the “Monitoring” team.lynx_environment
resource creates an environment named “Development” with a specified username and secret, associated with the “Grafana” project.lynx_snapshot
resource creates a snapshot titled “Grafana Project Snapshot” of type “project” for the “Grafana” project, associated with the “Monitoring” team