Alpha Project Manager
An Infrastructure as Code manager to deploy lab infrastructure. Working with Atrium, Gitlab CI, Terraform, Cloud-init and Scaleway.
How does it work ?
At first, Gitlab CI will run scripts to generate environment variables. They will be used in Terraform for configuration and securing credentials.
After this, Gitlab CI will initiate Terraform, which create infrastructure matching the configuration. While deploying resources, especially instances, Terraform will provide the cloud-init.yml script so it can be executed after boot and configure the instances.
Infrastructure is ready, which the script runned at boot 3 services are running : atrium which serve as a reverse-proxy, code-server and webtop. User just
Setup Terraform Locally
First, you must setup 2 local files for your variables :
variables-local.tf
Create a file variables-local.tf containing the following code :
variable "FORGE_PROJECT_ID" {
type = string
description = "Forge Project ID"
default = "your project id"
sensitive = true
}
variable "FORGE_USERNAME" {
type = string
description = "Forge Username"
default = "your username"
sensitive = true
}
variable "FORGE_ACCESS_TOKEN" {
type = string
description = "Forge Access Token"
default = "your access token"
sensitive = true
}
variables-local.tfvars
Now, you can create a file for your variables information called variables-local.tfvars containing the following code :
### SCW variables
SCW_PROJECT_ID = ""
SCW_ACCESS_KEY = ""
SCW_SECRET_KEY = ""
SCW_SSH_PUB_KEY = ""
SCW_SSH_PRIVATE_KEY = ""
INSTANCES_COUNT = "2"
ENVIRONMENT = "devrust"
Terraform init - Gitlab remote tfstate
You can grab a init command from your gitlab project on menu Infrastructure > Terraform. Select your environment and click the actions button, then you will only need to provide a gitlab project token. Command should look like :
export GITLAB_ACCESS_TOKEN=<YOUR-ACCESS-TOKEN>
terraform init \
-backend-config="address=https://forge.grandlyon.com/api/v4/projects/875/terraform/state/devrust" \
-backend-config="lock_address=https://forge.grandlyon.com/api/v4/projects/875/terraform/state/devrust/lock" \
-backend-config="unlock_address=https://forge.grandlyon.com/api/v4/projects/875/terraform/state/devrust/lock" \
-backend-config="username=xxxxxxx" \
-backend-config="password=$GITLAB_ACCESS_TOKEN" \
-backend-config="lock_method=POST" \
-backend-config="unlock_method=DELETE" \
-backend-config="retry_wait_min=5"
terraform init -var-file=variables-local.tfvars
Terraform plan - With variables file
terraform plan -var-file=variables-local.tfvars -out=tfplan
Terraform apply - With plan
terraform apply tfplan
Terraform destroy - With variables file
terraform destroy -var-file=variables-local.tfvars