Skip to content

Commit 1747927

Browse files
ffasslerdebovema
authored andcommitted
Upgrade to terraform 0.12
1 parent 02e143c commit 1747927

File tree

4 files changed

+52
-31
lines changed

4 files changed

+52
-31
lines changed

main.tf

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,73 @@
1+
provider "scaleway" {
2+
#access_key = "<SCALEWAY-ACCESS-KEY>"
3+
#secret_key = "<SCALEWAY-SECRET-KEY>"
4+
#organization_id = "<SCALEWAY-ORGANIZATION-ID>"
5+
zone = "fr-par-1"
6+
region = "fr-par"
7+
}
8+
19
data "scaleway_image" "image" {
2-
count = "${var.node_count > 0 ? 1 : 0}"
10+
count = var.node_count > 0 ? 1 : 0
311

4-
architecture = "${var.server_arch}"
5-
name = "${var.server_image}"
12+
architecture = var.server_arch
13+
name = var.server_image
614
}
715

8-
resource "scaleway_server" "node" {
9-
count = "${var.node_count}"
16+
resource "scaleway_instance_server" "node" {
17+
count = var.node_count
1018

11-
name = "${var.node_name}-${count.index}"
19+
name = "${var.node_name}-${count.index}"
1220

13-
image = "${data.scaleway_image.image.id}"
14-
type = "${var.server_type}"
15-
dynamic_ip_required = true
16-
boot_type = "local"
21+
image = data.scaleway_image.image[0].id
22+
type = var.server_type
23+
enable_dynamic_ip = true
24+
# boot_type = "local"
1725

1826
# initialization sequence
19-
cloudinit = "${data.template_file.userdata.rendered}"
27+
cloud_init = data.template_file.userdata.rendered
28+
29+
connection {
30+
host = element(scaleway_instance_server.node.*.public_ip, count.index)
31+
user = var.username
32+
private_key = file("~/.ssh/scaleway")
33+
}
34+
2035
provisioner "remote-exec" {
2136
inline = [
2237
"tail -f /var/log/cloud-init-output.log &",
23-
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do sleep 10; done;"
38+
"while [ ! -f /var/lib/cloud/instance/boot-finished ]; do sleep 10; done;",
2439
]
2540
}
2641
provisioner "local-exec" {
2742
command = "sleep 80" # wait more than 1 minute for the instance to be rebooted
2843
}
29-
3044
}
3145

3246
data "template_file" "userdata" {
33-
template = "${file("${path.module}/cloud-init-user-data")}"
47+
template = file("${path.module}/cloud-init-user-data")
3448

35-
vars {
36-
codename = "${var.docker_distrib_codename}"
37-
distrib = "${var.docker_distrib}"
38-
user = "${var.username}"
49+
vars = {
50+
codename = var.docker_distrib_codename
51+
distrib = var.docker_distrib
52+
user = var.username
3953
}
4054
}
4155

4256
resource "null_resource" "node" {
43-
count = "${var.node_count}"
57+
count = var.node_count
4458

4559
connection {
46-
host = "${element(scaleway_server.node.*.public_ip, count.index)}"
47-
user = "${var.username}"
60+
host = element(scaleway_instance_server.node.*.public_ip, count.index)
61+
user = var.username
62+
private_key = file("~/.ssh/scaleway")
4863
}
4964

5065
provisioner "remote-exec" {
5166
inline = [
5267
"mkdir -p ~/www",
5368
"echo 'It works' > ~/www/index.html",
54-
"docker run --name http-nginx --restart=always -v ~/www:/usr/share/nginx/html:ro -p 80:80 -d nginx"
69+
"docker run --name http-nginx --restart=always -v ~/www:/usr/share/nginx/html:ro -p 80:80 -d nginx",
5570
]
5671
}
5772
}
73+

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
output "public_ips" {
2-
value = "${scaleway_server.node.*.public_ip}"
2+
value = scaleway_instance_server.node.*.public_ip
33
}
44

variables.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
variable "node_count" {
2-
type = "string"
2+
type = string
33
default = "1"
44
}
55

66
variable "node_name" {
7-
type = "string"
7+
type = string
88
default = "cloud-init"
99
}
1010

1111
variable "server_arch" {
12-
type = "string"
12+
type = string
1313
default = "x86_64"
1414
}
1515

1616
variable "server_image" {
17-
type = "string"
17+
type = string
1818
default = "Ubuntu Bionic"
1919
}
2020

2121
variable "server_type" {
22-
type = "string"
22+
type = string
2323
default = "START1-S"
2424
}
2525

2626
variable "username" {
27-
type = "string"
27+
type = string
2828
default = "user"
2929
}
3030

3131
variable "docker_distrib" {
32-
type = "string"
32+
type = string
3333
default = "ubuntu"
3434
}
3535

3636
variable "docker_distrib_codename" {
37-
type = "string"
37+
type = string
3838
default = "bionic"
3939
}
40+

versions.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
terraform {
3+
required_version = ">= 0.12"
4+
}

0 commit comments

Comments
 (0)