Newer
Older
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
73
74
75
76
77
78
79
80
81
82
83
84
############
# Terraform SSH key
############
resource "scaleway_account_ssh_key" "ssh_key" {
name = "FORGE alpha_project_manager"
public_key = var.SCW_SSH_PUB_KEY
}
############
# Public IP
############
resource "scaleway_instance_ip" "public_ip" {
count = var.INSTANCES_COUNT
project_id = var.SCW_PROJECT_ID
}
################
# DOMAIN RECORD
################
resource "scaleway_domain_record" "subdomain_record" {
count = var.INSTANCES_COUNT
dns_zone = "daag.alpha.grandlyon.com"
name = "lab-${count.index}-daag-${var.ENVIRONMENT}"
type = "A"
data = scaleway_instance_ip.public_ip[count.index].address
ttl = 3600
}
resource "scaleway_domain_record" "host_subdomain_record" {
count = var.INSTANCES_COUNT
dns_zone = "daag.alpha.grandlyon.com"
name = "*.lab-${count.index}-daag-${var.ENVIRONMENT}"
type = "A"
data = scaleway_instance_ip.public_ip[count.index].address
ttl = 3600
}
##################################
## Security group - Allowed ports
##################################
resource "scaleway_instance_security_group" "www" {
project_id = var.SCW_PROJECT_ID
name = "security-group-daag-lab-${var.ENVIRONMENT}"
inbound_default_policy = "drop"
outbound_default_policy = "accept"
inbound_rule {
action = "accept"
port = "22"
}
inbound_rule {
action = "accept"
port = "80"
}
inbound_rule {
action = "accept"
port = "8080"
}
inbound_rule {
action = "accept"
port = "443"
}
}
##############################
## VM Instance - User Machine
##############################
resource "scaleway_instance_server" "user_instance_server" {
count = var.INSTANCES_COUNT
project_id = var.SCW_PROJECT_ID
name = "instance-${count.index}-daag-lab-${var.ENVIRONMENT}"
type = "DEV1-L"
image = "ubuntu_jammy"
ip_id = scaleway_instance_ip.public_ip[count.index].id
security_group_id = scaleway_instance_security_group.www.id
depends_on = [
scaleway_account_ssh_key.ssh_key,
scaleway_instance_security_group.www
]