forked from pierront/but3-iac
*
This commit is contained in:
@@ -26,3 +26,17 @@ module "network" {
|
|||||||
database_cidr = var.database_cidr
|
database_cidr = var.database_cidr
|
||||||
ssh_source_ranges = var.ssh_source_ranges
|
ssh_source_ranges = var.ssh_source_ranges
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module "compute" {
|
||||||
|
source = "../../modules/compute"
|
||||||
|
instance_type = var.instance_type
|
||||||
|
zone = var.zone
|
||||||
|
frontend_subnet_id = module.network.subnets.frontend
|
||||||
|
backend_subnet_id = module.network.subnets.backend
|
||||||
|
database_subnet_id = module.network.subnets.database
|
||||||
|
}
|
||||||
|
|
||||||
|
module "iam" {
|
||||||
|
source = "../../modules/iam"
|
||||||
|
project_id = var.project_id
|
||||||
|
}
|
||||||
@@ -39,5 +39,17 @@ variable "ssh_source_ranges" {
|
|||||||
variable "project_id" {
|
variable "project_id" {
|
||||||
description = "ID du projet"
|
description = "ID du projet"
|
||||||
type = string
|
type = string
|
||||||
default = "fourth-palisade-478713-i3"
|
default = "fourth-palisade-478713-i3 "
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "instance_type" {
|
||||||
|
description = "type de l'instance"
|
||||||
|
type = string
|
||||||
|
default = "e2-small"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "zone" {
|
||||||
|
description = "Nom de la zone"
|
||||||
|
type = string
|
||||||
|
default = "europe-west9-b"
|
||||||
}
|
}
|
||||||
@@ -21,88 +21,72 @@
|
|||||||
# - Tags : database, ssh
|
# - Tags : database, ssh
|
||||||
# - OS Login enabled
|
# - OS Login enabled
|
||||||
|
|
||||||
resource "google_compute_instance" "frontend" {
|
resource "google_compute_instance" "vm_frontend" {
|
||||||
name = "frontend"
|
name = "vm-frontend"
|
||||||
machine_type = var.instance_type
|
machine_type = var.instance_type
|
||||||
zone = var.zone
|
zone = var.zone
|
||||||
|
|
||||||
|
boot_disk {
|
||||||
|
initialize_params {
|
||||||
|
image = "debian-cloud/debian-11"
|
||||||
|
size = 10
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
boot_disk {
|
network_interface {
|
||||||
initialize_params {
|
access_config {} # IP publique
|
||||||
image = "debian-cloud/debian-11"
|
subnetwork = var.frontend_subnet_id
|
||||||
size = 10
|
}
|
||||||
}
|
|
||||||
|
tags = ["frontend", "ssh"]
|
||||||
|
|
||||||
|
metadata = {
|
||||||
|
enable-oslogin = "TRUE"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resource "google_compute_instance" "vm_backend" {
|
||||||
|
name = "vm-backend"
|
||||||
|
machine_type = var.instance_type
|
||||||
|
zone = var.zone
|
||||||
|
|
||||||
network_interface {
|
boot_disk {
|
||||||
subnetwork = var.frontend_subnet_id
|
initialize_params {
|
||||||
|
image = "debian-cloud/debian-11"
|
||||||
|
size = 10
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
network_interface {
|
||||||
|
subnetwork = var.backend_subnet_id
|
||||||
|
}
|
||||||
|
|
||||||
access_config {}
|
tags = ["backend", "ssh"]
|
||||||
|
|
||||||
|
metadata = {
|
||||||
|
enable-oslogin = "TRUE"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resource "google_compute_instance" "vm_database" {
|
||||||
|
name = "vm-database"
|
||||||
|
machine_type = var.instance_type
|
||||||
|
zone = var.zone
|
||||||
|
|
||||||
metadata = {
|
boot_disk {
|
||||||
enable-oslogin = "TRUE"
|
initialize_params {
|
||||||
}
|
image = "debian-cloud/debian-11"
|
||||||
|
size = 20
|
||||||
|
}
|
||||||
tags = ["frontend", "ssh"]
|
}
|
||||||
}
|
|
||||||
|
network_interface {
|
||||||
|
subnetwork = var.database_subnet_id
|
||||||
resource "google_compute_instance" "backend" {
|
}
|
||||||
name = "backend"
|
|
||||||
machine_type = var.instance_type
|
tags = ["database", "ssh"]
|
||||||
zone = var.zone
|
|
||||||
|
metadata = {
|
||||||
|
enable-oslogin = "TRUE"
|
||||||
boot_disk {
|
}
|
||||||
initialize_params {
|
|
||||||
image = "debian-cloud/debian-11"
|
|
||||||
size = 10
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
network_interface {
|
|
||||||
subnetwork = var.backend_subnet_id
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
metadata = {
|
|
||||||
enable-oslogin = "TRUE"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
tags = ["backend", "ssh"]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
resource "google_compute_instance" "database" {
|
|
||||||
name = "database"
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
metadata = {
|
|
||||||
enable-oslogin = "TRUE"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
tags = ["database", "ssh"]
|
|
||||||
}
|
}
|
||||||
@@ -3,30 +3,22 @@
|
|||||||
# 2. L'IP publique du frontend
|
# 2. L'IP publique du frontend
|
||||||
# 3. Les noms des instances
|
# 3. Les noms des instances
|
||||||
|
|
||||||
output "frontend_internal_ip" {
|
output "ip_internes" {
|
||||||
value = google_compute_instance.frontend.network_interface[0].network_ip
|
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" {
|
||||||
output "backend_internal_ip" {
|
value = google_compute_instance.vm_frontend.network_interface[0].access_config[0].nat_ip
|
||||||
value = google_compute_instance.backend.network_interface[0].network_ip
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output "nom_instances" {
|
||||||
output "database_internal_ip" {
|
value = {
|
||||||
value = google_compute_instance.database.network_interface[0].network_ip
|
frontend = google_compute_instance.vm_frontend.name
|
||||||
}
|
backend = google_compute_instance.vm_backend.name
|
||||||
|
database = google_compute_instance.vm_database.name
|
||||||
|
}
|
||||||
output "frontend_public_ip" {
|
|
||||||
value = google_compute_instance.frontend.network_interface[0].access_config[0].nat_ip
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
output "instance_names" {
|
|
||||||
value = [
|
|
||||||
google_compute_instance.frontend.name,
|
|
||||||
google_compute_instance.backend.name,
|
|
||||||
google_compute_instance.database.name
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
@@ -6,25 +6,26 @@
|
|||||||
# - database_subnet_id
|
# - database_subnet_id
|
||||||
|
|
||||||
variable "instance_type" {
|
variable "instance_type" {
|
||||||
type = string
|
description = "type de l'instance"
|
||||||
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
variable "zone" {
|
variable "zone" {
|
||||||
type = string
|
description = "Nom de la zone"
|
||||||
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
variable "frontend_subnet_id" {
|
variable "frontend_subnet_id" {
|
||||||
type = string
|
description = "id du frontend"
|
||||||
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
variable "backend_subnet_id" {
|
variable "backend_subnet_id" {
|
||||||
type = string
|
description = "id du backend"
|
||||||
|
type = string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
variable "database_subnet_id" {
|
variable "database_subnet_id" {
|
||||||
type = string
|
description = "id du database"
|
||||||
|
type = string
|
||||||
}
|
}
|
||||||
@@ -3,3 +3,30 @@
|
|||||||
# 2. Une clé pour ce compte de service
|
# 2. Une clé pour ce compte de service
|
||||||
# 3. Les rôles IAM nécessaires
|
# 3. Les rôles IAM nécessaires
|
||||||
# 4. La configuration OS Login avec votre clé SSH
|
# 4. La configuration OS Login avec votre clé SSH
|
||||||
|
|
||||||
|
resource "google_service_account" "service_account" {
|
||||||
|
account_id = "terraform"
|
||||||
|
display_name = "terraform"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_service_account_key" "mykey" {
|
||||||
|
service_account_id = google_service_account.service_account.name
|
||||||
|
public_key_type = "TYPE_X509_PEM_FILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_project_iam_binding" "custom_service_account" {
|
||||||
|
project = var.project_id
|
||||||
|
role = "roles/view"
|
||||||
|
|
||||||
|
members = [
|
||||||
|
"serviceAccount:${google_service_account.service_account.email}",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
data "google_client_openid_userinfo" "me" {
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "google_os_login_ssh_public_key" "cache" {
|
||||||
|
user = data.google_client_openid_userinfo.me.email
|
||||||
|
key = file("~/.ssh/id_ed25519")
|
||||||
|
}
|
||||||
@@ -1,3 +1,14 @@
|
|||||||
# À vous d'exposer :
|
# À vous d'exposer :
|
||||||
# 1. L'email du compte de service
|
# 1. L'email du compte de service
|
||||||
# 2. La clé du compte de service (sensitive = true)
|
# 2. La clé du compte de service (sensitive = true)
|
||||||
|
|
||||||
|
output "email" {
|
||||||
|
description = "Service account email."
|
||||||
|
value = google_service_account.service_account.email
|
||||||
|
}
|
||||||
|
|
||||||
|
output "key" {
|
||||||
|
description = "Service account key."
|
||||||
|
sensitive = true
|
||||||
|
value = google_service_account.service_account.key
|
||||||
|
}
|
||||||
@@ -1,2 +1,7 @@
|
|||||||
# À vous de définir :
|
# À vous de définir :
|
||||||
# - project_id (string)
|
# - project_id (string)
|
||||||
|
|
||||||
|
variable "project_id" {
|
||||||
|
description = "ID du projet"
|
||||||
|
type = string
|
||||||
|
}
|
||||||
@@ -2,11 +2,11 @@
|
|||||||
# 1. L'ID du VPC
|
# 1. L'ID du VPC
|
||||||
# 2. Les IDs des sous-réseaux sous forme de map
|
# 2. Les IDs des sous-réseaux sous forme de map
|
||||||
|
|
||||||
output "vpc_terraform_output" {
|
output "vpc" {
|
||||||
value = google_compute_network.vpc_terraform.id
|
value = google_compute_network.vpc_terraform.id
|
||||||
}
|
}
|
||||||
|
|
||||||
output "list_id" {
|
output "subnets" {
|
||||||
value = {
|
value = {
|
||||||
frontend = google_compute_subnetwork.subnet_frontend.id
|
frontend = google_compute_subnetwork.subnet_frontend.id
|
||||||
backend = google_compute_subnetwork.subnet_backend.id
|
backend = google_compute_subnetwork.subnet_backend.id
|
||||||
|
|||||||
Reference in New Issue
Block a user