-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
72 lines (63 loc) · 1.75 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
locals {
generate_password = var.basic_auth_password == null || var.basic_auth_password == ""
basic_auth_user = var.basic_auth_user
basic_auth_password = local.generate_password ? random_password.faasd[0].result : var.basic_auth_password
user_data_vars = {
basic_auth_user = local.basic_auth_user
basic_auth_password = local.basic_auth_password
domain = var.domain
email = var.email
}
}
resource "random_password" "faasd" {
count = local.generate_password ? 1 : 0
length = 16
special = false
}
resource "scaleway_instance_ip" "faasd" {
project_id = var.project_id
zone = var.zone
}
resource "scaleway_instance_security_group" "faasd" {
project_id = var.project_id
zone = var.zone
name = var.name
inbound_default_policy = "drop"
dynamic "inbound_rule" {
for_each = var.domain == "" ? [1] : []
content {
action = "accept"
port = 8080
}
}
dynamic "inbound_rule" {
for_each = var.domain != "" ? [1] : []
content {
action = "accept"
port = 80
}
}
dynamic "inbound_rule" {
for_each = var.domain != "" ? [1] : []
content {
action = "accept"
port = 443
}
}
inbound_rule {
action = "accept"
port = 22
}
}
resource "scaleway_instance_server" "faasd" {
project_id = var.project_id
zone = var.zone
name = var.name
type = var.type
image = "ubuntu_focal"
ip_id = scaleway_instance_ip.faasd.id
security_group_id = scaleway_instance_security_group.faasd.id
user_data = {
cloud-init = templatefile("${path.module}/templates/startup.sh", local.user_data_vars)
}
}