-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path3-PrerequisNetworkAzurepourVMdeployeeparPacker.tf
144 lines (130 loc) · 5.61 KB
/
3-PrerequisNetworkAzurepourVMdeployeeparPacker.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# définition des pre-requis à déploiement VM depuis template généré par Packer
# Definition of prerequisite mandatory for Packer to deploy a VM
# - VNet Azure / Azure VNet
# - Network Security Group (appliqué au Subnet / apply to Subnet)
# - SubNet
# - Une IP publique / a Public IP
# - Une carte réseau associée au SubNet et à l'IP publique / a NIC associated to Subnet and Public IP
#
# More infos
# https://github.com/Azure/packer-azure/issues/201
#
#
# Pour personnaliser recherchez et remplacez Stan par votre chaine !
# To Custom : find and replace Stan with your own string !
#
# Variable pour définir la région Azure où déployer la plateforme
# Variable to define Azure Location where to deploy
# Pour obtenir la liste des valeurs possible via la ligne de commande Azure, executer la commande suivante :
# To list available Azure Location using CLI :
# az account list-locations
variable "AzureRegion" {
description = "choix de la region Azure"
type = "string"
default = "West Europe"
}
# Définition du ressource group
# Resource Group Definition
resource "azurerm_resource_group" "Terra-RG-PackerStan1" {
name = "RG-DeploiementPacker1"
location = "${var.AzureRegion}"
}
# Définition d un VNet
# plus d info : https://www.terraform.io/docs/providers/azurerm/r/virtual_network.html
resource "azurerm_virtual_network" "Terra-VNet-PackerStan1" {
name = "VNet-PackerStan1"
resource_group_name = "${azurerm_resource_group.Terra-RG-PackerStan1.name}"
address_space = ["10.0.0.0/8"]
location = "${var.AzureRegion}"
dns_servers = ["8.8.8.8", "10.0.0.5"]
}
# Définition des Network Security Group : you pouvez ici personnalisé en fonction du type de VM
# Network Security Group Definition : you can customize here depending on your type of VM
# More info : https://www.terraform.io/docs/providers/azurerm/r/network_security_group.html
resource "azurerm_network_security_group" "Terra-NSG-PackerStan1" {
name = "NSG-PackerStan1"
location = "${var.AzureRegion}"
resource_group_name = "${azurerm_resource_group.Terra-RG-PackerStan1.name}"
# regle autorisant SSH
security_rule {
name = "OK-SSH-entrant"
priority = 1200
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "*"
destination_address_prefix = "*"
}
# regle autorisant HTTP
security_rule {
name = "OK-HTTP-entrant"
priority = 1300
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "80"
source_address_prefix = "*"
destination_address_prefix = "*"
}
# regle autorisant RDP (TCP 3389)
security_rule {
name = "OK-RDP-entrant"
priority = 1400
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "3389"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}
# Définition du subnet Subnet-PackerStan1
# SubNet Definition
# More info : https://www.terraform.io/docs/providers/azurerm/r/subnet.html
resource "azurerm_subnet" "Terra-Subnet-PackerStan1" {
name = "Subnet-PackerStan1"
resource_group_name = "${azurerm_resource_group.Terra-RG-PackerStan1.name}"
virtual_network_name = "${azurerm_virtual_network.Terra-VNet-PackerStan1.name}"
address_prefix = "10.0.0.0/16"
network_security_group_id = "${azurerm_network_security_group.Terra-NSG-PackerStan1.id}"
}
# Définition IP publique pour le Load Balancer permettant d accéder à la PackerStan1
# Definition of Public IP
# more info : https://www.terraform.io/docs/providers/azurerm/r/public_ip.html
resource "azurerm_public_ip" "Terra-PublicIp-PackerStan1" {
name = "PublicIp-PackerStan1"
location = "${var.AzureRegion}"
resource_group_name = "${azurerm_resource_group.Terra-RG-PackerStan1.name}"
public_ip_address_allocation = "static"
domain_name_label = "publicpackerstan1"
}
# Définition d une carte reseau pour la VM PackerStan1
# Network Card Interface definition for PackerStan1 VM
# More info : https://www.terraform.io/docs/providers/azurerm/r/network_interface.html
resource "azurerm_network_interface" "Terra-NIC1-PackerStan1" {
name = "NIC1-PackerStan1"
location = "${var.AzureRegion}"
resource_group_name = "${azurerm_resource_group.Terra-RG-PackerStan1.name}"
ip_configuration {
name = "configIPNIC1-PackerStan1"
subnet_id = "${azurerm_subnet.Terra-Subnet-PackerStan1.id}"
private_ip_address_allocation = "dynamic"
public_ip_address_id = "${azurerm_public_ip.Terra-PublicIp-PackerStan1.id}"
}
}
# --------------------
# - Output
# --------------------
output "IP Publique de la VM" {
value = "${azurerm_public_ip.Terra-PublicIp-PackerStan1.ip_address}"
}
output "FQDN de la VM" {
value = "${azurerm_public_ip.Terra-PublicIp-PackerStan1.fqdn}"
}
output "NICid de la VM" {
value = "${azurerm_network_interface.Terra-NIC1-PackerStan1.id}"
}