-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
60 lines (47 loc) · 1.33 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
### Instance EC2 (VM)
#### ----> SSH-PUBLIC-KEY --> DONE
#### ----> SG (Sécurity Group) [22/TCP] --> DONE
# Axes d'améliorations
#
# - Commennter le code
# - Variaviliser les élèments pour le rendre universel
#??
resource "aws_key_pair" "myssh-key" {
key_name = var.ssh_key_name
public_key = var.public_ssh_key
}
resource "aws_security_group" "my-sg" {
#description = "security group to allow incoming SSH connection to ec2 instance"
name = "mysg"
ingress = [{
cidr_blocks = ["0.0.0.0/0"]
description = "Allow SSH"
from_port = 22
ipv6_cidr_blocks = []
prefix_list_ids = []
protocol = "TCP"
security_groups = []
self = false
to_port = 22
}]
egress = [{
description = "Allow connection to any internet service"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
self = false
ipv6_cidr_blocks = []
prefix_list_ids = []
security_groups = []
}]
}
resource "aws_instance" "myec2" {
ami = "ami-0574da719dca65348"
instance_type = "t2.medium"
key_name = aws_key_pair.myssh-key.key_name # 1ère variable terraform
security_groups = [aws_security_group.my-sg.name]
tags = {
"Name" = "myvm"
}
}