This commit is contained in:
2024-12-06 16:23:40 +01:00
parent d376bf9e98
commit 39851e8a42
13 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 6.0"
}
}
}
provider "google" {
project = var.project_id
region = var.region
}
module "network" {
source = "../../modules/network"
# Variables d'entrée
project_name = var.project_name
region = var.region
# Autres variables spécifiques au module
backend_cidr = var.backend_cidr
frontend_cidr = var.frontend_cidr
database_cidr = var.database_cidr
ssh_source_ranges = var.ssh_source_ranges
}
/*module "iam" {
source = "../../modules/iam"
# Variables d'entrée
# Autres variables spécifiques au module
}*/
module "compute" {
source = "../../modules/compute"
zone = var.zone
instance_type = var.instance_type
sub1 = module.network.subnet["frontend"]
sub2 = module.network.subnet["backend"]
sub3 = module.network.subnet["database"]
}

View File

View File

@@ -0,0 +1,53 @@
variable "project_id" {
description = "ID du projet GCP"
type = string
default = "radiant-pen-442314-f9"
}
variable "project_name" {
description = "nom_du_projet"
type = string
default = "My Project 91685"
}
variable "region" {
description = "region"
type = string
default = "europe-west4"
}
variable "frontend_cidr" {
description = "range_front"
type = string
default = "10.0.1.0/24"
}
variable "backend_cidr" {
description = "range_back"
type = string
default = "10.0.2.0/24"
}
variable "database_cidr" {
description = "range_database"
type = string
default = "10.0.3.0/24"
}
variable "ssh_source_ranges" {
description = "range_ssh"
type = string
default = "0.0.0.0/0"
}
variable "instance_type" {
description = "type d'instance"
type = string
default = "e2-micro"
}
variable "zone" {
description = "zone"
type = string
default = "europe-west4-a"
}

View File

@@ -0,0 +1,73 @@
resource "google_compute_instance" "vm-front" {
name = "vm-front"
machine_type = var.instance_type
zone = var.zone
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
size = 10
}
}
network_interface {
subnetwork = var.sub1
access_config {} # IP publique
}
tags = ["web", "ssh"]
metadata = {
enable-oslogin = "TRUE"
}
}
resource "google_compute_instance" "vm-back" {
name = "vm-back"
machine_type = var.instance_type
zone = var.zone
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
size = 10
}
}
network_interface {
subnetwork = var.sub2
access_config {} # IP publique
}
tags = ["backend", "ssh"]
metadata = {
enable-oslogin = "TRUE"
}
}
resource "google_compute_instance" "vm-database" {
name = "vm-database"
machine_type = var.instance_type
zone = var.zone
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
size = 20
}
}
network_interface {
subnetwork = var.sub3
access_config {} # IP publique
}
tags = ["database", "ssh"]
metadata = {
enable-oslogin = "TRUE"
}
}

View File

View File

@@ -0,0 +1,47 @@
variable "instance_type" {
description = "type d'instance"
type = string
default = "e2-micro"
}
variable "zone" {
description = "zone"
type = string
default = "europe-west4-a"
}
variable "frontend_cidr" {
description = "range_front"
type = string
default = "10.0.1.0/24"
}
variable "backend_cidr" {
description = "range_back"
type = string
default = "10.0.2.0/24"
}
variable "database_cidr" {
description = "range_database"
type = string
default = "10.0.3.0/24"
}
variable "sub1" {
description = "subnet front"
type = string
}
variable "sub2" {
description = "subnet back"
type = string
}
variable "sub3" {
description = "subnet database"
type = string
}

View File

View File

View File

View File

@@ -0,0 +1,78 @@
resource "google_compute_network" "vpc" {
name = "vpc2"
auto_create_subnetworks = false
}
# Sous-réseau
resource "google_compute_subnetwork" "subnet_front" {
name = "frontend"
network = google_compute_network.vpc.id
ip_cidr_range = var.frontend_cidr
region = var.region
}
resource "google_compute_subnetwork" "subnet_back" {
name = "backend"
network = google_compute_network.vpc.id
ip_cidr_range = var.backend_cidr
region = var.region
}
resource "google_compute_subnetwork" "subnet_db" {
name = "database"
network = google_compute_network.vpc.id
ip_cidr_range = var.database_cidr
region = var.region
}
resource "google_compute_firewall" "allow_http" {
name = "allow-http"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["80", "443"]
}
source_ranges = ["0.0.0.0/0"]
target_tags = ["web"]
}
resource "google_compute_firewall" "allow_ssh" {
name = "allow-ssh"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["22"]
}
source_ranges = [var.ssh_source_ranges]
target_tags = ["ssh"]
}
resource "google_compute_firewall" "allow_frontend_to_backend" {
name = "allow-frontend-to-backend"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["8000"]
}
source_tags = ["web"]
target_tags = ["backend"]
}
resource "google_compute_firewall" "allow_backend_to_database" {
name = "allow-backend-to-database"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["3306"]
}
source_tags = ["backend"]
target_tags = ["database"]
}

View File

@@ -0,0 +1,11 @@
output "vpc"{
value = google_compute_network.vpc.id
}
output "subnet" {
value = {
frontend = google_compute_subnetwork.subnet_front.id,
backend = google_compute_subnetwork.subnet_back.id,
database = google_compute_subnetwork.subnet_db.id
}
}

View File

@@ -0,0 +1,47 @@
variable "project_id" {
description = "ID du projet GCP"
type = string
default = "radiant-pen-442314-f9"
}
variable "project_name" {
description = "nom_du_projet"
type = string
default = "My Project 91685"
}
variable "region" {
description = "region"
type = string
default = "europe-west4"
}
variable "frontend_cidr" {
description = "range_front"
type = string
default = "10.0.1.0/24"
}
variable "backend_cidr" {
description = "range_back"
type = string
default = "10.0.2.0/24"
}
variable "database_cidr" {
description = "range_database"
type = string
default = "10.0.3.0/24"
}
variable "ssh_source_ranges" {
description = "range_ssh"
type = string
default = "0.0.0.0/0"
}
variable "http_source_ranges" {
description = "range_http"
type = string
default = "0.0.0.0/0"
}

View File