Compare commits

..

No commits in common. "master" and "master" have entirely different histories.

13 changed files with 0 additions and 419 deletions

View File

@ -1,60 +0,0 @@
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 6.0"
}
}
}
provider "google" {
project = var.project_name
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
frontend_cidr = var.frontend_cidr
backend_cidr = var.backend_cidr
database_cidr = var.database_cidr
ssh_source_ranges = var.ssh_source_ranges
}
module "compute" {
source = "../../modules/compute"
#autres variables spécifiques au module
instance_type = var.instance_type
zone = var.zone
frontend_subnet = module.network.subnet_id["frontend"]
backend_subnet = module.network.subnet_id["backend"]
database_subnet = module.network.subnet_id["database"]
}
module "iam" {
source = "../../modules/iam"
project_id = var.project_id
}
data "google_client_openid_userinfo" "me" {
}
resource "local_file" "ansible_config" {
content = templatefile("${path.module}/../../templates/ansible.cfg.tpl",
{
remote_user = data.google_client_openid_userinfo.me.email
}
)
filename = "../../../ansible/ansible.cfg"
}
resource "local_file" "service_account" {
content = base64decode(module.iam.service_account_key)
filename = "../../../ansible/service_account.json"
}

View File

@ -1,31 +0,0 @@
output "vpc_id" {
value = module.network.vpc_id
}
output "subnet_id" {
value = {
frontend = module.network.subnet_id.frontend,
backend = module.network.subnet_id.backend,
database = module.network.subnet_id.database
}
}
output "ip_instance" {
value = {
frontend = module.compute.ip_instance.frontend,
backend = module.compute.ip_instance.backend,
database = module.compute.ip_instance.database
}
}
output "frontend_public_ip" {
value = module.compute.frontend_public_ip
}
output "name_instance" {
value = {
frontend = module.compute.name_instance.frontend,
backend = module.compute.name_instance.backend,
database = module.compute.name_instance.database
}
}

View File

@ -1,53 +0,0 @@
variable "project_name" {
description = "nom du projet"
type = string
default = "projet-vertu"
}
variable "region" {
description = "region"
type = string
default = "europe-west4"
}
variable "frontend_cidr" {
description = "sous réseau frontend"
type = string
default = "10.0.1.0/24"
}
variable "backend_cidr" {
description = "sous réseau backend"
type = string
default = "10.0.2.0/24"
}
variable "database_cidr" {
description = "sous réseau database"
type = string
default = "10.0.3.0/24"
}
variable "ssh_source_ranges" {
description = "ssh"
type = string
default = "0.0.0.0/0"
}
variable "instance_type" {
description = "Type de machine"
type = string
default = "e2-small"
}
variable "zone" {
description = "zone"
type = string
default = "europe-west4-b"
}
variable "project_id" {
description = "ID du projet GCP"
type = string
default = "projet-vertu"
}

View File

@ -1,71 +0,0 @@
resource "google_compute_instance" "vm_front" {
name = "frontend-vm"
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
access_config {} # IP publique
}
tags = ["frontend", "ssh"]
metadata = {
enable-oslogin = "TRUE"
}
}
resource "google_compute_instance" "vm_back" {
name = "backend-vm"
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
access_config {} # IP publique
}
tags = ["backend", "ssh"]
metadata = {
enable-oslogin = "TRUE"
}
}
resource "google_compute_instance" "vm_db" {
name = "database-vm"
machine_type = var.instance_type
zone = var.zone
boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
size = 10
}
}
network_interface {
subnetwork = var.database_subnet
access_config {} # IP publique
}
tags = ["database", "ssh"]
metadata = {
enable-oslogin = "TRUE"
}
}

View File

@ -1,19 +0,0 @@
output "ip_instance" {
value = {
frontend = google_compute_instance.vm_front.network_interface.0.network_ip,
backend = google_compute_instance.vm_back.network_interface.0.network_ip,
database = google_compute_instance.vm_db.network_interface.0.network_ip
}
}
output "frontend_public_ip" {
value = google_compute_instance.vm_front.network_interface.0.access_config.0.nat_ip
}
output "name_instance" {
value = {
frontend = google_compute_instance.vm_front.name,
backend = google_compute_instance.vm_back.name,
database = google_compute_instance.vm_db.name
}
}

View File

@ -1,24 +0,0 @@
variable "instance_type" {
description = "Type de machine"
type = string
}
variable "zone" {
description = "zone"
type = string
}
variable "frontend_subnet" {
description = "sous réseau frontend"
type = string
}
variable "backend_subnet" {
description = "sous réseau backend"
type = string
}
variable "database_subnet" {
description = "sous réseau database"
type = string
}

View File

@ -1,24 +0,0 @@
resource "google_service_account" "service_account" {
account_id = "terraform"
display_name = "terraform"
}
resource "google_service_account_key" "service_account" {
service_account_id = google_service_account.service_account.name
public_key_type = "TYPE_X509_PEM_FILE"
}
resource "google_project_iam_binding" "service_account_roles" {
project = var.project_id
role = "roles/viewer"
members = ["serviceAccount:${google_service_account.service_account.email}"]
}
data "google_client_openid_userinfo" "me" {
}
resource "google_os_login_ssh_public_key" "add_my_key" {
project = var.project_id
user = data.google_client_openid_userinfo.me.email
key = file("~/.ssh/id_ed25519.pub")
}

View File

@ -1,10 +0,0 @@
output "service_account_email" {
description = "Email du compte de service"
value = google_service_account.service_account.email
}
output "service_account_key" {
description = "Clé du compte de service"
value = google_service_account_key.service_account.private_key
sensitive = true
}

View File

@ -1,4 +0,0 @@
variable "project_id" {
description = "ID du projet GCP"
type = string
}

View File

@ -1,82 +0,0 @@
# VPC
resource "google_compute_network" "vpc" {
name = "tp7"
auto_create_subnetworks = false
}
# Sous-réseau frontend
resource "google_compute_subnetwork" "frontend" {
name = "frontend"
network = google_compute_network.vpc.id
ip_cidr_range = var.frontend_cidr
region = "europe-west4"
}
# Sous-réseau backend
resource "google_compute_subnetwork" "backend" {
name = "backend"
network = google_compute_network.vpc.id
ip_cidr_range = var.backend_cidr
region = "europe-west4"
}
# Sous-réseau database
resource "google_compute_subnetwork" "database" {
name = "database"
network = google_compute_network.vpc.id
ip_cidr_range = var.database_cidr
region = "europe-west4"
}
# Règle de pare-feu
resource "google_compute_firewall" "allow_ssh" {
name = "allow-ssh-22"
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" "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 = ["frontend"]
}
resource "google_compute_firewall" "allow_frontend_backend" {
name = "allow-front-to-back"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["8000"]
}
source_tags = ["frontend"]
target_tags = ["backend"]
}
resource "google_compute_firewall" "allow_backend_db" {
name = "allow-back-to-db"
network = google_compute_network.vpc.id
allow {
protocol = "tcp"
ports = ["3306"]
}
source_tags = ["backend"]
target_tags = ["database"]
}

View File

@ -1,12 +0,0 @@
# Output
output "vpc_id" {
value = google_compute_network.vpc.id
}
output "subnet_id" {
value = {
frontend = google_compute_subnetwork.frontend.id,
backend = google_compute_subnetwork.backend.id,
database = google_compute_subnetwork.database.id
}
}

View File

@ -1,29 +0,0 @@
variable "project_name" {
description = "nom du projet"
type = string
}
variable "region" {
description = "region"
type = string
}
variable "frontend_cidr" {
description = "sous réseau frontend"
type = string
}
variable "backend_cidr" {
description = "sous réseau backend"
type = string
}
variable "database_cidr" {
description = "sous réseau database"
type = string
}
variable "ssh_source_ranges" {
description = "ssh"
type = string
}