bcp de chose
This commit is contained in:
parent
34fe765565
commit
d41d21f0e1
52
environments/dev/main.tf
Normal file
52
environments/dev/main.tf
Normal file
@ -0,0 +1,52 @@
|
||||
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
|
||||
cidr_range = "10.0.0.0/16"
|
||||
}
|
||||
|
||||
module "network" {
|
||||
source = "./modules/iam"
|
||||
|
||||
# Variables d'entrée
|
||||
project_name = var.project_name
|
||||
region = var.region
|
||||
|
||||
# Autres variables spécifiques au module
|
||||
cidr_range = "10.0.0.0/16"
|
||||
}
|
||||
|
||||
module "network" {
|
||||
source = "./modules/compute"
|
||||
|
||||
# Variables d'entrée
|
||||
project_name = var.project_name
|
||||
region = var.region
|
||||
|
||||
# Autres variables spécifiques au module
|
||||
cidr_range = "10.0.0.0/16"
|
||||
backend_cidr = var.backend_cidr
|
||||
frontend_cidr = var.frontend_cidr
|
||||
database_cidr = var.database_cidr
|
||||
ssh_source_ranges = var.ssh_source_ranges
|
||||
zone = var.zone
|
||||
instance_type = var.instance_type
|
||||
}
|
0
environments/dev/outputs.tf
Normal file
0
environments/dev/outputs.tf
Normal file
53
environments/dev/variables.tf
Normal file
53
environments/dev/variables.tf
Normal file
@ -0,0 +1,53 @@
|
||||
variable "project_id" {
|
||||
description = "ID du projet GCP"
|
||||
type = string
|
||||
default = "97892"
|
||||
}
|
||||
|
||||
variable "project_name" {
|
||||
description = "nom_du_projet"
|
||||
type = string
|
||||
default = "terraforming"
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
description = "emplacement"
|
||||
type = string
|
||||
default = "europe-west4"
|
||||
}
|
||||
|
||||
variable "frontend_cidr" {
|
||||
description = "addr_front"
|
||||
type = string
|
||||
default = "10.0.1.0/24"
|
||||
}
|
||||
|
||||
variable "backend_cidr" {
|
||||
description = "addr_back"
|
||||
type = string
|
||||
default = "10.0.2.0/24"
|
||||
}
|
||||
|
||||
variable "database_cidr" {
|
||||
description = "addr_bdd"
|
||||
type = string
|
||||
default = "10.0.3.0/24"
|
||||
}
|
||||
|
||||
variable "ssh_source_ranges" {
|
||||
description = "addr_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"
|
||||
}
|
72
modules/compute/main.tf
Normal file
72
modules/compute/main.tf
Normal file
@ -0,0 +1,72 @@
|
||||
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 = google_compute_subnetwork.subnet.id
|
||||
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 = google_compute_subnetwork.subnet.id
|
||||
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 = google_compute_subnetwork.subnet.id
|
||||
access_config {} # IP publique
|
||||
}
|
||||
|
||||
tags = ["database", "ssh"]
|
||||
|
||||
metadata = {
|
||||
enable-oslogin = "TRUE"
|
||||
}
|
||||
}
|
||||
|
4
modules/compute/outputs.tf
Normal file
4
modules/compute/outputs.tf
Normal file
@ -0,0 +1,4 @@
|
||||
# Output
|
||||
output "instance_ip" {
|
||||
value = google_compute_instance.main.network_interface[0].access_config[0].nat_ip
|
||||
}
|
31
modules/compute/variables.tf
Normal file
31
modules/compute/variables.tf
Normal file
@ -0,0 +1,31 @@
|
||||
variable "instance_type" {
|
||||
description = "type d'instance"
|
||||
type = string
|
||||
default = "e2-micro"
|
||||
}
|
||||
|
||||
variable "zone" {
|
||||
description = "zone"
|
||||
type = string
|
||||
default = "europe-west4-a"
|
||||
}
|
||||
|
||||
variable "frontend_subnet_id" {
|
||||
description = "front sub id"
|
||||
type = string
|
||||
default = "10.0.1.0/24"
|
||||
}
|
||||
|
||||
variable "backend_subnet_id" {
|
||||
description = "back sub id"
|
||||
type = string
|
||||
default = "10.0.2.0/24"
|
||||
}
|
||||
|
||||
variable "database_subnet_id" {
|
||||
description = "data sub id"
|
||||
type = string
|
||||
default = "10.0.3.0/24"
|
||||
}
|
||||
|
||||
|
0
modules/iam/main.tf
Normal file
0
modules/iam/main.tf
Normal file
0
modules/iam/outputs.tf
Normal file
0
modules/iam/outputs.tf
Normal file
0
modules/iam/variables.tf
Normal file
0
modules/iam/variables.tf
Normal file
@ -0,0 +1,77 @@
|
||||
resource "google_compute_network" "vpc" {
|
||||
name = "net1"
|
||||
auto_create_subnetworks = false
|
||||
}
|
||||
|
||||
# Sous-réseau
|
||||
resource "google_compute_subnetwork" "subnet1" {
|
||||
name = "frontend"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = var.frontend_cidr
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_subnetwork" "subnet2" {
|
||||
name = "backend"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = var.backend_cidr
|
||||
region = var.region
|
||||
|
||||
resource "google_compute_subnetwork" "subnet3" {
|
||||
name = "database"
|
||||
network = google_compute_network.vpc.id
|
||||
ip_cidr_range = var.database_cidr
|
||||
region = var.region
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "allow_http" {
|
||||
name = "rule-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" "front_to_back" {
|
||||
name = "front_to_back"
|
||||
network = google_compute_network.vpc.id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["8000"]
|
||||
}
|
||||
|
||||
source_tags = ["web"]
|
||||
target_tags = ["backend"]
|
||||
}
|
||||
|
||||
resource "google_compute_firewall" "back_to_bdd" {
|
||||
name = "back_to_bdd"
|
||||
network = google_compute_network.vpc.id
|
||||
|
||||
allow {
|
||||
protocol = "tcp"
|
||||
ports = ["8000"]
|
||||
}
|
||||
|
||||
source_tags = ["backend"]
|
||||
target_tags = ["database"]
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
# Output
|
||||
output "instance_ip" {
|
||||
value = google_compute_instance.main.network_interface[0].access_config[0].nat_ip
|
||||
}
|
Loading…
Reference in New Issue
Block a user