Skip to content

Commit fc95165

Browse files
committed
Add an example
1 parent d36fe64 commit fc95165

File tree

4 files changed

+173
-11
lines changed

4 files changed

+173
-11
lines changed

README.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44

55
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](https://code.visualstudio.com/docs/remote/ssh).
66

7+
## Examples
8+
9+
* [Full-featured development instance on a Scaleway DEV1-S instance running Ubuntu 20.04](examples/ubuntu_dev1-s_full)
10+
711
## Prerequisites
812

913
* Terraform 1.0+
10-
* [jq](https://stedolan.github.io/jq/)
1114
* A [Scaleway project](https://console.scaleway.com/project/) (default project is fine but [creating a new one](https://www.scaleway.com/en/docs/scaleway-project/) is encouraged)
15+
* Git, OpenSSH
16+
* [jq](https://stedolan.github.io/jq/) (only for magic commands)
1217

1318
## Introduction
1419

@@ -20,16 +25,18 @@ set_tfvar() { ( [ $(grep "$1" terraform.tfvars 2>/dev/null | wc -l) -gt 0 ] && s
2025

2126
> 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)
2227
23-
2. Create your SSH key pair and [add it in your authorized keys](https://console.scaleway.com/project/credentials)
28+
2. Create your SSH key pair and [add the public key in authorized keys of your Scleway project in the Scaleway console](https://console.scaleway.com/project/credentials)
2429

2530
```
2631
ssh-keygen -t rsa -b 4096 -q -C 'scaleway' -N '' -f ~/.ssh/scaleway
2732
```
2833

29-
> Add the SSH key file in Terraform variables
30-
> ```
31-
> set_tfvar ssh_key_file '"~/.ssh/scaleway"'
32-
> ```
34+
> if using an existing SSH key, it is assumed its name is *~/.ssh/scaleway*
35+
36+
Add the SSH key file in Terraform variables
37+
```
38+
set_tfvar ssh_key_file '"~/.ssh/scaleway"'
39+
```
3340

3441
3. [Retrieve your project credentials](https://console.scaleway.com/project/credentials) and export them:
3542

@@ -43,21 +50,28 @@ export SCW_DEFAULT_ZONE=fr-par-1
4350

4451
## Usage
4552

46-
1. Initialize Terraform
53+
1. Clone this repository
54+
55+
```
56+
git clone https://github.com/debovema/terraform-scaleway-dev-instance.git
57+
cd terraform-scaleway-dev-instance
58+
```
59+
60+
2. Initialize Terraform
4761

4862
```
4963
terraform init
5064
```
5165

52-
2. Define username
66+
3. Define username
5367

5468
```
5569
set_tfvar username '"developer"'
5670
```
5771

5872
> Mind the double quotes
5973
60-
3. Select optional features
74+
4. Select optional features
6175

6276
* [Oh My ZSH](https://ohmyz.sh/):
6377
```
@@ -79,12 +93,12 @@ set_tfvar feature_nvm true
7993
set_tfvar feature_sdkman true
8094
```
8195

82-
4. Apply default plan
96+
5. Apply default plan
8397
```
8498
terraform apply
8599
```
86100

87-
5. SSH to the (first) created host
101+
6. SSH to the (first) created host
88102

89103
```
90104
eval `terraform output --json ssh_commands | jq -r ".[0]"`

examples/ubuntu_dev1-s_full/.terraform.lock.hcl

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Example : Full-featured development instance on a Scaleway DEV1-S instance running Ubuntu 20.04
2+
3+
Read the [module documentation](../../README.md) for further explanation.
4+
5+
## Prerequisites
6+
7+
* Terraform 1.0+
8+
* A [Scaleway project](https://console.scaleway.com/project/) (default project is fine but [creating a new one](https://www.scaleway.com/en/docs/scaleway-project/) is encouraged)
9+
* curl, OpenSSH
10+
* [jq](https://stedolan.github.io/jq/) (only for magic commands)
11+
12+
## Introduction
13+
14+
1. Create your SSH key pair and [add the public key in authorized keys of your Scleway project in the Scaleway console](https://console.scaleway.com/project/credentials)
15+
16+
```
17+
ssh-keygen -t rsa -b 4096 -q -C 'scaleway' -N '' -f ~/.ssh/scaleway
18+
```
19+
20+
> if using an existing SSH key, it is assumed its name is *~/.ssh/scaleway*
21+
22+
2. [Retrieve your project credentials](https://console.scaleway.com/project/credentials) and export them:
23+
24+
```
25+
export SCW_DEFAULT_PROJECT_ID=<REDACTED>
26+
export SCW_ACCESS_KEY=<REDACTED>
27+
export SCW_SECRET_KEY=<REDACTED>
28+
export SCW_DEFAULT_REGION=fr-par
29+
export SCW_DEFAULT_ZONE=fr-par-1
30+
```
31+
32+
## Usage
33+
34+
1. Retrieve the (root) Terraform module of this example
35+
36+
```
37+
mkdir ubuntu_dev1-s_full
38+
cd ubuntu_dev1-s_full
39+
curl -fsSL -O https://raw.githubusercontent.com/debovema/terraform-scaleway-dev-instance/main/examples/ubuntu_dev1-s_full/main.tf
40+
```
41+
42+
2. Initialize Terraform
43+
44+
```
45+
terraform init
46+
```
47+
48+
3. Apply default plan
49+
```
50+
terraform apply
51+
```
52+
53+
4. SSH to the (first) created host
54+
55+
```
56+
eval `terraform output --json ssh_commands | jq -r ".[0]"`
57+
```
58+
59+
> To display the SSH command used to connect:
60+
> ```
61+
> echo $(terraform output --json ssh_commands | jq -r ".[0]")
62+
> ```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//--------------------------------------------------------------------
2+
// Variables
3+
variable "dev_ssh_key_file" { default = "~/.ssh/scaleway" }
4+
variable "dev_username" { default = "developer" }
5+
6+
//--------------------------------------------------------------------
7+
// Modules
8+
module "dev" {
9+
source = "app.terraform.io/scwdev/dev/scaleway"
10+
version = "0.0.2"
11+
12+
feature_docker = "true"
13+
feature_nvm = "true"
14+
feature_omz = "true"
15+
feature_sdkman = "true"
16+
ssh_key_file = var.dev_ssh_key_file
17+
username = var.dev_username
18+
}
19+
20+
//--------------------------------------------------------------------
21+
// Outputs
22+
output "public_ips" {
23+
value = module.dev.public_ips
24+
}
25+
26+
output "ssh_commands" {
27+
value = module.dev.ssh_commands
28+
}

0 commit comments

Comments
 (0)