Skip to content

Commit

Permalink
✨ Improve SCW startup scripts and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jpetazzo committed Oct 3, 2021
1 parent 47766be commit 61bd320
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ prepare-scw/.terraform*
prepare-scw/terraform.*
prepare-scw/stage2/*.tf
prepare-scw/stage2/kubeconfig.*
prepare-scw/stage2/.terraform*
prepare-scw/stage2/terraform.*
prepare-scw/stage2/wildcard_dns.*

slides/*.yml.html
Expand Down
5 changes: 3 additions & 2 deletions prepare-scw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ To use it:
```bash
scw init
terraform init
export TF_VAR_how_many_clusters=5
export TF_VAR_nodes_per_cluster=2
terraform apply
cd stage2
terraform init
terraform apply
```

Edit `variables.tf` to change the number of clusters.
2 changes: 1 addition & 1 deletion prepare-scw/kapsule_cluster/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
scaleway = {
source = "scaleway/scaleway"
version = "2.0.0"
version = "2.1.0"
}
kubernetes = {
source = "hashicorp/kubernetes"
Expand Down
2 changes: 1 addition & 1 deletion prepare-scw/kapsule_cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ variable "pool_size" {

variable "pool_min_size" {
type = number
default = 1
default = 2
}

variable "pool_max_size" {
Expand Down
14 changes: 11 additions & 3 deletions prepare-scw/main.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
module "kapsule_cluster" {
count = var.how_many_clusters
source = "./kapsule_cluster"
cluster_name = format("tf-%03d", count.index + 101)
count = var.how_many_clusters
source = "./kapsule_cluster"
cluster_name = format("tf-%s-%03d", random_string.tag.result, count.index + 101)
pool_size = var.nodes_per_cluster
pool_min_size = var.nodes_per_cluster
}

output "kubectl_config" {
value = format("scw k8s kubeconfig install %s", split("/", module.kapsule_cluster.0.cluster_id)[1])
}

resource "random_string" "tag" {
length = 5
special = false
upper = false
}

resource "local_file" "stage2" {
filename = "${path.module}/stage2/main.tf"
content = templatefile(
Expand Down
2 changes: 1 addition & 1 deletion prepare-scw/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
scaleway = {
source = "scaleway/scaleway"
version = "2.0.0"
version = "2.1.0"
}
}
required_version = ">= 0.14"
Expand Down
3 changes: 3 additions & 0 deletions prepare-scw/purge-clusters.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
scw k8s cluster list -o json |
jq -r '.[] | select(.status=="'${STATE-creating}'") | .id' | xargs -n1 scw k8s cluster delete
5 changes: 5 additions & 0 deletions prepare-scw/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ variable "how_many_clusters" {
type = number
default = 2
}

variable "nodes_per_cluster" {
type = number
default = 1
}

0 comments on commit 61bd320

Please sign in to comment.