Provision with Teraform instead of Ansible

This commit is contained in:
Paul-Henri Froidmont 2018-09-15 01:18:57 +02:00
parent 3f36885343
commit 9e83baffb3
9 changed files with 147 additions and 60 deletions

3
terraform/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
.terraform*
terraform.tfstate
terraform.tfstate.backup

34
terraform/README.md Normal file
View file

@ -0,0 +1,34 @@
Terraform Scaleaway
===================
```
export SCALEWAY_TOKEN=<your-access-key>
export SCALEWAY_ORGANIZATION=<your-organization-key>
# terraform init
# terraform plan
# terraform apply
# terraform show
data.scaleway_image.ubuntu:
id =
architecture = x86_64
creation_date = 2017-01-05T10:01:28.406069+00:00
name = Ubuntu Xenial (16.04 latest)
organization =
public = true
scaleway_server.server1:
id =
enable_ipv6 = false
image =
name = server1
private_ip =
public_ip =
state = stopped
state_detail =
tags.# = 0
type = VC1S
volume.# = 1
volume.0.size_in_gb = 50
volume.0.type = l_ssd
volume.0.volume_id =
```

74
terraform/sl.tf Normal file
View file

@ -0,0 +1,74 @@
provider "scaleway" {
region = "${var.region}"
}
data "scaleway_image" "ubuntu" {
architecture = "${var.architecture}"
name = "${var.image}"
}
//resource "scaleway_ip" "public_ip" {
// count = 1
//}
resource "scaleway_server" "worker" {
count = "${var.worker_instance_count}"
name = "worker${count.index+1}"
image = "${data.scaleway_image.ubuntu.id}"
type = "${var.worker_instance_type}"
state = "running"
tags = ["k8s","k8s_workers"]
// volume {
// size_in_gb = 50
// type = "l_ssd"
// }
}
resource "scaleway_server" "master" {
count = "${var.master_instance_count}"
name = "master${count.index+1}"
image = "${data.scaleway_image.ubuntu.id}"
type = "${var.master_instance_type}"
state = "running"
tags = ["k8s","k8s_masters"]
}
resource "scaleway_server" "proxy1" {
count = 1
name = "proxy1"
image = "${data.scaleway_image.ubuntu.id}"
type = "${var.proxy_instance_type}"
public_ip = "51.158.77.6"
state = "running"
tags = ["k8s","k8s_proxy","primary"]
}
resource "scaleway_server" "proxy2" {
count = 1
name = "proxy2"
image = "${data.scaleway_image.ubuntu.id}"
type = "${var.proxy_instance_type}"
state = "running"
tags = ["k8s","k8s_proxy","secondary"]
}
output "worker_private_ips" {
value = ["${scaleway_server.worker.*.private_ip}"]
}
output "master_private_ips" {
value = ["${scaleway_server.master.*.private_ip}"]
}
output "proxy0_private_ips" {
value = ["${scaleway_server.proxy1.*.private_ip}"]
}
output "proxy1_private_ips" {
value = ["${scaleway_server.proxy2.*.private_ip}"]
}
output "public_ip" {
value = ["${scaleway_server.proxy1.*.public_ip}"]
}

35
terraform/variables.tf Normal file
View file

@ -0,0 +1,35 @@
variable "region" {
default = "par1"
}
variable "architecture" {
default = "x86_64"
}
variable "image" {
default = "Ubuntu Bionic"
}
variable "master_instance_type" {
default = "START1-S"
}
variable "master_instance_count" {
default = 3
}
variable "proxy_instance_type" {
default = "START1-S"
}
variable "worker_instance_type" {
default = "START1-S"
}
variable "worker_volume_size" {
default = 100
}
variable "worker_instance_count" {
default = 3
}