Compare commits
13 Commits
main
...
aa28319166
| Author | SHA1 | Date | |
|---|---|---|---|
| aa28319166 | |||
| bd69138c68 | |||
| b18e0ec5a2 | |||
| 1f344183f8 | |||
| e3ff9de93e | |||
| ea215256e1 | |||
| df9d025406 | |||
| 2bc66b21b3 | |||
| 1a83d45b66 | |||
| 242459b5b5 | |||
| 42dd3fb11c | |||
| c4e88b89e3 | |||
| b74e128a5e |
24
terraform/environments/dev/main.tf
Normal file
24
terraform/environments/dev/main.tf
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
google = {
|
||||||
|
source = "hashicorp/google"
|
||||||
|
version = "~> 6.12.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "google" {
|
||||||
|
project = var.project_id
|
||||||
|
region = var.region
|
||||||
|
}
|
||||||
|
|
||||||
|
module "network" {
|
||||||
|
source = "../../modules/network"
|
||||||
|
project_name = var.project_name
|
||||||
|
region = var.region
|
||||||
|
frontend_cidr = var.frontend_cidr
|
||||||
|
backend_cidr = var.backend_cidr
|
||||||
|
database_cidr = var.database_cidr
|
||||||
|
ssh_source_ranges = var.ssh_source_ranges
|
||||||
|
|
||||||
|
}
|
||||||
0
terraform/environments/dev/outputs.tf
Normal file
0
terraform/environments/dev/outputs.tf
Normal file
46
terraform/environments/dev/variables.tf
Normal file
46
terraform/environments/dev/variables.tf
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# Commentaire
|
||||||
|
variable "project_name" {
|
||||||
|
type = string
|
||||||
|
description = "but3-iac"
|
||||||
|
default = "Automaticsearch"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "region" {
|
||||||
|
type = string
|
||||||
|
description = "Région dans laquelle déployer les ressources"
|
||||||
|
default = "europe-west9"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "frontend_cidr" {
|
||||||
|
description = "CIDR for frontend subnet"
|
||||||
|
type = string
|
||||||
|
default = "10.0.1.0/24"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "backend_cidr" {
|
||||||
|
description = "CIDR for backend subnet"
|
||||||
|
type = string
|
||||||
|
default = "10.0.2.0/24"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "database_cidr" {
|
||||||
|
description = "CIDR for database subnet"
|
||||||
|
type = string
|
||||||
|
default = "10.0.3.0/24"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ssh_source_ranges" {
|
||||||
|
type = string
|
||||||
|
description = "Plages d’adresses autorisées à se connecter en SSH"
|
||||||
|
default = "0.0.0.0/0"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
variable "project_id"{
|
||||||
|
description = "id du projet"
|
||||||
|
type = string
|
||||||
|
default = "automaticsearch-477610"
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
76
terraform/modules/compute/main.tf
Normal file
76
terraform/modules/compute/main.tf
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
resource "google_compute_instance" "vm_frontend" {
|
||||||
|
name = "frontend-instance"
|
||||||
|
machine_type = var.instance_type
|
||||||
|
zone = var.zone
|
||||||
|
|
||||||
|
boot_disk {
|
||||||
|
initialize_params {
|
||||||
|
image = "debian-cloud/debian-11"
|
||||||
|
size = 10
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
network_interface {
|
||||||
|
subnetwork = var.frontend_subnet_id
|
||||||
|
|
||||||
|
access_config {}
|
||||||
|
}
|
||||||
|
|
||||||
|
tags= ["frontend", "ssh"]
|
||||||
|
|
||||||
|
metadata = {
|
||||||
|
enable-oslogin = "TRUE"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_instance" "vm_backend" {
|
||||||
|
name = "backend-instance"
|
||||||
|
machine_type = var.instance_type
|
||||||
|
zone = var.zone
|
||||||
|
|
||||||
|
boot_disk {
|
||||||
|
initialize_params {
|
||||||
|
image = "debian-cloud/debian-11"
|
||||||
|
size = 10
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
network_interface {
|
||||||
|
subnetwork = var.backend_subnet_id
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
tags = ["backend", "ssh"]
|
||||||
|
|
||||||
|
metadata = {
|
||||||
|
enable-oslogin = "TRUE"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_instance" "vm_database" {
|
||||||
|
name = "database-instance"
|
||||||
|
machine_type = var.instance_type
|
||||||
|
zone = var.zone
|
||||||
|
|
||||||
|
|
||||||
|
boot_disk {
|
||||||
|
initialize_params {
|
||||||
|
image = "debian-cloud/debian-11"
|
||||||
|
size = 20
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
network_interface {
|
||||||
|
subnetwork = var.database_subnet_id
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
tags = ["database", "ssh"]
|
||||||
|
|
||||||
|
metadata = {
|
||||||
|
enable-oslogin = "TRUE"
|
||||||
|
}
|
||||||
|
}
|
||||||
19
terraform/modules/compute/outputs.tf
Normal file
19
terraform/modules/compute/outputs.tf
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
output "ip_internes" {
|
||||||
|
value = {
|
||||||
|
frontend = google_compute_instance.vm_frontend.network_interface[0].network_ip
|
||||||
|
backend = google_compute_instance.vm_backend.network_interface[0].network_ip
|
||||||
|
database = google_compute_instance.vm_database.network_interface[0].network_ip
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output "ip_public_frontend" {
|
||||||
|
value = google_compute_instance.vm_frontend.network_interface[0].access_config[0].nat_ip
|
||||||
|
}
|
||||||
|
|
||||||
|
output "nom_instances" {
|
||||||
|
value = {
|
||||||
|
frontend = google_compute_instance.vm_frontend.name
|
||||||
|
backend = google_compute_instance.vm_backend.name
|
||||||
|
database = google_compute_instance.vm_database.name
|
||||||
|
}
|
||||||
|
}
|
||||||
27
terraform/modules/compute/variables.tf
Normal file
27
terraform/modules/compute/variables.tf
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
variable "instance_type" {
|
||||||
|
description = "Type de machine à utiliser pour les instances"
|
||||||
|
type = string
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "zone" {
|
||||||
|
description = "Zone où déployer les instances"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "frontend_subnet_id" {
|
||||||
|
description = "ID du sous-réseau frontend"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "backend_subnet_id" {
|
||||||
|
description = "ID du sous-réseau backend"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "database_subnet_id" {
|
||||||
|
description = "ID du sous-réseau database"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
0
terraform/modules/iam/main.tf
Normal file
0
terraform/modules/iam/main.tf
Normal file
0
terraform/modules/iam/outputs.tf
Normal file
0
terraform/modules/iam/outputs.tf
Normal file
0
terraform/modules/iam/variables.tf
Normal file
0
terraform/modules/iam/variables.tf
Normal file
87
terraform/modules/network/main.tf
Normal file
87
terraform/modules/network/main.tf
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
resource "google_compute_network" "vpc" {
|
||||||
|
name = "mon-vpc"
|
||||||
|
auto_create_subnetworks = false
|
||||||
|
}
|
||||||
|
|
||||||
|
# Sous-réseau
|
||||||
|
resource "google_compute_subnetwork" "frontend_network" {
|
||||||
|
name = "mon-frontend"
|
||||||
|
network = google_compute_network.vpc.id
|
||||||
|
ip_cidr_range = var.frontend_cidr
|
||||||
|
region = var.region
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_subnetwork" "backend_network" {
|
||||||
|
name = "mon-backend"
|
||||||
|
network = google_compute_network.vpc.id
|
||||||
|
ip_cidr_range = var.backend_cidr
|
||||||
|
region = var.region
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_subnetwork" "database_network" {
|
||||||
|
name = "mon-database"
|
||||||
|
network = google_compute_network.vpc.id
|
||||||
|
ip_cidr_range = var.database_cidr
|
||||||
|
region = var.region
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_firewall" "ssh_firewall" {
|
||||||
|
name = "mon-ssh"
|
||||||
|
network = google_compute_network.vpc.id
|
||||||
|
|
||||||
|
allow {
|
||||||
|
protocol = "tcp"
|
||||||
|
ports = ["22"]
|
||||||
|
}
|
||||||
|
|
||||||
|
source_ranges = ["0.0.0.0/0"]
|
||||||
|
target_tags = ["ssh"]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
resource "google_compute_firewall" "frontend_firewall" {
|
||||||
|
name = "frontend"
|
||||||
|
network = google_compute_network.vpc.id
|
||||||
|
|
||||||
|
allow {
|
||||||
|
protocol = "tcp"
|
||||||
|
ports = ["80", "443"]
|
||||||
|
}
|
||||||
|
|
||||||
|
source_ranges = ["0.0.0.0/0"]
|
||||||
|
target_tags = ["frontend"]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_firewall" "backend_firewall" {
|
||||||
|
name = "backend"
|
||||||
|
network = google_compute_network.vpc.id
|
||||||
|
|
||||||
|
allow {
|
||||||
|
protocol = "tcp"
|
||||||
|
ports = ["8000"]
|
||||||
|
}
|
||||||
|
|
||||||
|
source_tags = ["frontend"]
|
||||||
|
target_tags = ["backend"]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_compute_firewall" "database_firewall" {
|
||||||
|
name = "database"
|
||||||
|
network = google_compute_network.vpc.id
|
||||||
|
|
||||||
|
allow {
|
||||||
|
protocol = "tcp"
|
||||||
|
ports = ["3306"]
|
||||||
|
}
|
||||||
|
|
||||||
|
source_tags = ["backend"]
|
||||||
|
target_tags = ["database"]
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
17
terraform/modules/network/outputs.tf
Normal file
17
terraform/modules/network/outputs.tf
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
output "vpc_terraform" {
|
||||||
|
description = "ID du VPC créé"
|
||||||
|
value = google_compute_network.vpc.id
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
output "subnet_ids" {
|
||||||
|
description = "Map des IDs des sous-réseaux"
|
||||||
|
value = {
|
||||||
|
|
||||||
|
frontend = google_compute_subnetwork.frontend_network.id
|
||||||
|
backend = google_compute_subnetwork.backend_network.id
|
||||||
|
database = google_compute_subnetwork.database_network.id
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
36
terraform/modules/network/variables.tf
Normal file
36
terraform/modules/network/variables.tf
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
variable "project_name" {
|
||||||
|
type = string
|
||||||
|
description = "but3-iac"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "region" {
|
||||||
|
type = string
|
||||||
|
description = "Région dans laquelle déployer les ressources"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "frontend_cidr" {
|
||||||
|
description = "CIDR for frontend subnet"
|
||||||
|
type = string
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "backend_cidr" {
|
||||||
|
description = "CIDR for backend subnet"
|
||||||
|
type = string
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "database_cidr" {
|
||||||
|
description = "CIDR for database subnet"
|
||||||
|
type = string
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ssh_source_ranges" {
|
||||||
|
description = "Plages d’adresses autorisées à se connecter en SSH"
|
||||||
|
type = string
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user