This Terraform module can be used to create cheap and disposable development machines with Scaleway cloud provider. For instance, these machines are well suited to be used with Visual Studio Code SSH remote developement feature.
- Terraform 1.0+
- A Scaleway project (default project is fine but creating a new one is encouraged)
- Git, OpenSSH
- jq (only for magic commands)
- Define shell helper function to set Terraform variables
set_tfvar() { ( [ $(grep "$1" terraform.tfvars 2>/dev/null | wc -l) -gt 0 ] && sed -i -e "/^$1 /s/=.*$/= $(echo $2 | sed 's|\"|\\"|g' | sed 's|/|\\/|g')/" terraform.tfvars ) || echo "$1 = $2" >> terraform.tfvars }
This shell function takes two arguments (the variable key and value) and put the key = value in the terraform.tfvars file regardless of the existence of the variable (create or replace behaviour)
- Create your SSH key pair and add the public key in authorized keys of your Scleway project in the Scaleway console
ssh-keygen -t ed25519 -q -C 'scaleway' -N '' -f ~/.ssh/scaleway
if using an existing SSH key, it is assumed its name is ~/.ssh/scaleway
Add the SSH key file in Terraform variables
set_tfvar ssh_key_file '"~/.ssh/scaleway"'
- Retrieve your project credentials and export them:
export SCW_DEFAULT_PROJECT_ID=<REDACTED>
export SCW_ACCESS_KEY=<REDACTED>
export SCW_SECRET_KEY=<REDACTED>
export SCW_DEFAULT_REGION=fr-par
export SCW_DEFAULT_ZONE=fr-par-1
- Clone this repository
git clone https://github.com/debovema/terraform-scaleway-dev-instance.git
cd terraform-scaleway-dev-instance
- Initialize Terraform
terraform init
- Define username
set_tfvar username '"developer"'
Mind the double quotes
- Select optional features
set_tfvar feature_omz true
set_tfvar feature_docker true
- nvm (for Node developments):
set_tfvar feature_nvm true
- SDKMAN! (for Java developments):
set_tfvar feature_sdkman true
- Apply default plan
terraform apply
- SSH to the (first) created host
eval `terraform output --json ssh_commands | jq -r ".[0]"`
To display the SSH command used to connect:
echo $(terraform output --json ssh_commands | jq -r ".[0]")