Create your first environment
Managing multiple virtual machines, volumes, and other resources can become challenging due to the lack of organization.
To address this issue, you can group your resources within environments. In Infrahub, each resource, including SSH keypairs, virtual machines, volumes, etc., is created within a designated environment. These environments provide users with an organized management system.
Creating an environment
POST /core/environments
Using this API endpoint, you can create multiple environments to efficiently manage all your resources.
For example, if you are handling two distinct projects with designated environments for development and production, you can assign them meaningful names like project-1-development
and project-1-production
. You can then create the necessary resources for each corresponding environment.
To create an environment:
-
Send a POST request to
https://infrahub-api.nexgencloud.com/v1/core/environments
with the following headers and request body:- Include the following headers:
- To authenticate the request include the
api_key
header containing your API Key generated in the previous step. - Include the
"Content-Type: application/json"
header so that the request body will be accepted.
- To authenticate the request include the
- Include the following fields in the request body:
name
: Name of the environment you are creating.region
: Specify the region in which to create the environment, choose eitherCANADA-1
, orNORWAY-1
.
- Include the following headers:
curl -X POST "https://infrahub-api.nexgencloud.com/v1/core/environments"\
-H "api_key: YOUR-API-KEY"\
-H "Content-Type: application/json"
-d '{
"name": "development",
"region": "NORWAY-1"
}'
{
"status": true,
"message": "Environment is created successfully",
"environment": {
"id": 2,
"name": "development",
"region": "NORWAY-1",
"created_at": "2023-04-19T05:09:16"
}
}
This response indicates that the creation of the environment named development
in region NORWAY-1
has been successful. For any other response, refer to documentation for handling errors.
Next, to gain access to your resources, let's import your first SSH key.