init: terraform
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
# This file is maintained automatically by "terraform init".
|
||||
# Manual edits may be lost in future updates.
|
||||
|
||||
provider "registry.terraform.io/hashicorp/archive" {
|
||||
version = "2.8.1"
|
||||
constraints = "~> 2.4"
|
||||
hashes = [
|
||||
"h1:eehhIUcuegkswQDKArYBAhVV9wQmRVMhyYGaD7kHIj0=",
|
||||
"zh:03de290604114a89fcd45c2e5bc7787d5a1ebfc5f964fb5989306bea7a4c79ec",
|
||||
"zh:0a7d69dc9fbbc48960bc2f04588c8fb1bd92c78a8f306566b7fb17fc4a4f2058",
|
||||
"zh:4df1f3981379c35f1757da957470f7f7724496b57219da3485177cf1647bdf59",
|
||||
"zh:50f0e72ba53bfe6e11b03b7fc899e1f72536354381d302a743a274ae2a3f45f4",
|
||||
"zh:5c4e15a04c98e2a8cafb1cd9632b48ad318051e8462d105b1153006277985c35",
|
||||
"zh:66069e604bcf5c4af0278e15997d9e6bd755c54fb3801d78885838b889729c5f",
|
||||
"zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3",
|
||||
"zh:979765db3f42601870ab377104ba70befb029547b278337ec4ada980e3582de6",
|
||||
"zh:b165254da774f49945a73fbccc3ef1b63d70ea00a98fa9e14716665ba80ecaad",
|
||||
"zh:c0bb2697b525da9fec4511f569ed2bd2b42f25d5c1f9fa00f8f3645b50cfc2e9",
|
||||
"zh:c48f6695d12df0d0fa5231f7c1b8d518a4feae91a733fdd35a5804af3a303831",
|
||||
"zh:d589954c93f075180c9f4e2ce91780d5edcb56dfd0d3cda8ba08e13c10b52249",
|
||||
"zh:f5792ed06da65d0daf7ca3711f5399ff78c7cb4400afe53fbce9a926fbde4477",
|
||||
]
|
||||
}
|
||||
|
||||
provider "registry.terraform.io/hashicorp/null" {
|
||||
version = "3.3.2"
|
||||
hashes = [
|
||||
"h1:7rn0+p+fbrHfJxNVgTnlKp6C3yu0jENMXffz9Xb9XjQ=",
|
||||
"zh:10ec43b8b7b18d5639238c7fb9e111f6a4b038523dd66c7a426bf27b25fa4c08",
|
||||
"zh:60beb9cc2ad5b871c710860cee75b42850cc6acd43db0d77cb5e00fda7288b55",
|
||||
"zh:62538582d0a4a2f10ad8a8d9a6c3cd3f05af6c6d91c6641ffc78d4f0e8e69b27",
|
||||
"zh:64a8f9ce7852d9efc5b464c12306c946366d59f5e2757def97969c9fd64bd1d6",
|
||||
"zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3",
|
||||
"zh:92a374fb736a52f465283326d0a5bf4f495132eb99be209dfb4c75ec803fe8db",
|
||||
"zh:98da9c42785d27a50f0604758bcb61a30f6278b9f2acd92bb3b2046e0e71916c",
|
||||
"zh:b0f7896fae554729cdf4a24ac06359a050cff5817e6cd8597cba8a4ae01a7409",
|
||||
"zh:bc8179ee35d67c72fb03012e7023b9f9816f033a7ec4109c001dd6d29752e812",
|
||||
"zh:d23a598f713bfb6098bc003571d7de90b5a33b78f9be240488252fe5f3c2a60d",
|
||||
"zh:d2855b922ea345dbd89ea287e4c6c4757e38bc0aaffeb2b79aa0b8004f9c53ff",
|
||||
"zh:d3a60422bc6a2f9244d076c5222c07060c826ef91bdbaf4634cb752b86057473",
|
||||
"zh:faa01928c25d2a6ecd9c7eb8b88134cb08de55a6b11ca6c703ac0092845344ba",
|
||||
]
|
||||
}
|
||||
|
||||
provider "registry.terraform.io/kreuzwerker/docker" {
|
||||
version = "4.5.0"
|
||||
constraints = "~> 4.5.0"
|
||||
hashes = [
|
||||
"h1:eXPMxNcZjz5gC7Nc1oEPJldpI6B5btbvldjLOgJQNbI=",
|
||||
"zh:0ee4e9121632158a9ae1049bdd53c71fd9e06357de915dd193df2c1c55ae8814",
|
||||
"zh:12c6991012b5a548a406e1960c323484f95a9538c2522af15ec82f47fdb832d1",
|
||||
"zh:19c86ae59ed1e062e8402a49ea842f957fcda2f9689e06ecbd9480cc9bd1e41a",
|
||||
"zh:3ac8bc9805acd20c40c0ed474c9f4605aa73b61cf52809e1131e335fcbfe8e49",
|
||||
"zh:5a0e70d143759712fdda109f024a41d59d4758b5615378aa21ee6b959f65a416",
|
||||
"zh:5d3599285f71cc53c88a5802fa6e2f8ba87b9deea03abe5fe8bb2639e9d95654",
|
||||
"zh:a42f573a2526cddc9b8a93637a2c5478bc6e903ff29556ab8b2f1467681d5bde",
|
||||
"zh:c8de50d902cc8457e565a5d959f1e3e49064d31c2f14f7adf5f3ec632cfe3695",
|
||||
"zh:d40543d51eb4e902125d2c5a8a0f425a60edcec6c1dc07c4a89d92335ec05541",
|
||||
"zh:dd3105018ffddc8114083dcf84798c32fdecca7ef708eceaee49eb4b306fc061",
|
||||
"zh:e51e0199700698b962085683af4551d1f982dce37f3b6950da062c65e0145505",
|
||||
"zh:ffe415d3d3deffffdbd3a7173e3a9f90b74601cb6d8acafec1ab701a5b91dbff",
|
||||
]
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
locals {
|
||||
frontend_environments = {
|
||||
dev = {
|
||||
source_dir = "${path.root}/../../../apps/frontend/dist/frontend-dev/browser"
|
||||
source_dir = "${path.root}/../../../../apps/frontend/dist/frontend/browser"
|
||||
domain = "dev.enervision"
|
||||
}
|
||||
}
|
||||
@@ -9,15 +9,22 @@ locals {
|
||||
selected_frontend = local.frontend_environments[var.deployment_environment]
|
||||
}
|
||||
|
||||
resource "null_resource" "frontend" {
|
||||
provider "docker" {
|
||||
host = "npipe:////.//pipe//docker_cli"
|
||||
}
|
||||
|
||||
resource "docker_image" "frontend" {
|
||||
name = "enervision-front:latest"
|
||||
keep_locally = false
|
||||
|
||||
depends_on = [module.k3s]
|
||||
|
||||
triggers = {
|
||||
environment = var.deployment_environment
|
||||
|
||||
|
||||
build_hash = sha256(join("", [
|
||||
for file in fileset("${path.root}/../../../apps/frontend/dist/frontend/browser", "**") :
|
||||
filesha256("${path.root}/../../../apps/frontend/dist/frontend/browser/${file}")
|
||||
for file in fileset(local.selected_frontend.source_dir, "**") :
|
||||
filesha256("${local.selected_frontend.source_dir}/${file}")
|
||||
]))
|
||||
}
|
||||
|
||||
@@ -27,6 +34,7 @@ resource "null_resource" "frontend" {
|
||||
host = var.ssh_host
|
||||
port = var.ssh_port
|
||||
user = var.ssh_user
|
||||
password = var.ssh_password
|
||||
private_key = file(pathexpand(var.ssh_private_key_path))
|
||||
}
|
||||
|
||||
@@ -43,15 +51,24 @@ resource "null_resource" "frontend" {
|
||||
|
||||
// Copie des fichiers vers le serveur
|
||||
provisioner "file" {
|
||||
source = "${path.root}/../../../apps/frontend/dist/frontend/browser/"
|
||||
source = "${local.selected_frontend.source_dir}/"
|
||||
destination = "/tmp/enervision-frontend"
|
||||
}
|
||||
|
||||
// Déplacement des fichiers
|
||||
provisioner "remote-exec" {
|
||||
inline = [
|
||||
"sudo cp -r /tmp/enervision-frontend/* /var/www/enervision/",
|
||||
"sudo cp -r /tmp/enervision-frontend/ /var/www/enervision/",
|
||||
"sudo chown -R www-data:www-data /var/www/enervision"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "docker_container" "nginx" {
|
||||
image = "enervision-front:latest"
|
||||
name = "front"
|
||||
ports {
|
||||
internal = 4200
|
||||
external = 3000
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ module "k3s" {
|
||||
ssh_port = var.ssh_port
|
||||
ssh_user = var.ssh_user
|
||||
ssh_private_key_path = var.ssh_private_key_path
|
||||
ssh_password = var.ssh_password
|
||||
k3s_version = var.k3s_version
|
||||
k3s_disable_components = var.k3s_disable_components
|
||||
kubeconfig_output_path = var.kubeconfig_output_path
|
||||
|
||||
@@ -21,6 +21,11 @@ variable "ssh_private_key_path" {
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "ssh_password" {
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "k3s_version" {
|
||||
type = string
|
||||
description = "Version k3s a epingler pour un deploiement reproductible (ex: v1.31.5+k3s1). Voir https://github.com/k3s-io/k3s/releases."
|
||||
@@ -37,3 +42,13 @@ variable "kubeconfig_output_path" {
|
||||
description = "Chemin local ou ecrire le kubeconfig recupere apres installation."
|
||||
default = "./kubeconfig"
|
||||
}
|
||||
|
||||
variable "deployment_environment" {
|
||||
type = string
|
||||
default = "dev"
|
||||
|
||||
validation {
|
||||
condition = contains(["dev", "rec", "prod"], var.deployment_environment)
|
||||
error_message = "L'environnement doit être dev, rec ou prod."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,14 @@ terraform {
|
||||
required_version = ">= 1.7"
|
||||
|
||||
required_providers {
|
||||
null = {
|
||||
source = "hashicorp/null"
|
||||
version = "~> 3.2"
|
||||
archive = {
|
||||
source = "hashicorp/archive"
|
||||
version = "~> 2.4"
|
||||
}
|
||||
|
||||
docker = {
|
||||
source = "kreuzwerker/docker"
|
||||
version = "~> 4.5.0"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,17 +7,21 @@ locals {
|
||||
|
||||
resource "null_resource" "k3s_install" {
|
||||
triggers = {
|
||||
ssh_host = var.ssh_host
|
||||
k3s_version = var.k3s_version
|
||||
disable_components = join(",", var.k3s_disable_components)
|
||||
ssh_host = var.ssh_host
|
||||
ssh_port = tostring(var.ssh_port)
|
||||
ssh_user = var.ssh_user
|
||||
ssh_password = var.ssh_password
|
||||
k3s_version = var.k3s_version
|
||||
disable_components = join(",", var.k3s_disable_components)
|
||||
sudo_prefix = local.sudo_prefix
|
||||
}
|
||||
|
||||
connection {
|
||||
type = "ssh"
|
||||
host = var.ssh_host
|
||||
port = var.ssh_port
|
||||
user = var.ssh_user
|
||||
private_key = file(var.ssh_private_key_path)
|
||||
type = "ssh"
|
||||
host = self.triggers.ssh_host
|
||||
port = self.triggers.ssh_port
|
||||
user = self.triggers.ssh_user
|
||||
password = self.triggers.ssh_password
|
||||
}
|
||||
|
||||
provisioner "remote-exec" {
|
||||
@@ -33,7 +37,7 @@ resource "null_resource" "k3s_install" {
|
||||
when = destroy
|
||||
on_failure = continue
|
||||
inline = [
|
||||
"${local.sudo_prefix}sh -c 'test -x /usr/local/bin/k3s-uninstall.sh && /usr/local/bin/k3s-uninstall.sh || true'",
|
||||
"${self.triggers.sudo_prefix}sh -c 'test -x /usr/local/bin/k3s-uninstall.sh && /usr/local/bin/k3s-uninstall.sh || true'",
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -46,10 +50,13 @@ resource "null_resource" "fetch_kubeconfig" {
|
||||
}
|
||||
|
||||
provisioner "local-exec" {
|
||||
interpreter = ["bash", "-c"]
|
||||
command = <<-EOT
|
||||
ssh -i "${var.ssh_private_key_path}" -p ${var.ssh_port} -o StrictHostKeyChecking=accept-new ${var.ssh_user}@${var.ssh_host} '${local.kubeconfig_cmd}' \
|
||||
| sed 's/127.0.0.1/${var.ssh_host}/' > "${var.kubeconfig_output_path}"
|
||||
interpreter = ["PowerShell", "-NoProfile", "-Command"]
|
||||
|
||||
command = <<-EOT
|
||||
$content = ssh -i "${pathexpand(var.ssh_private_key_path)}" -p ${var.ssh_port} -o StrictHostKeyChecking=accept-new ${var.ssh_user}@${var.ssh_host} "cat /etc/rancher/k3s/k3s.yaml"
|
||||
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
|
||||
$content -replace "127.0.0.1", "${var.ssh_host}" |
|
||||
Set-Content -Path "${var.kubeconfig_output_path}" -Encoding UTF8
|
||||
EOT
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,11 @@ variable "ssh_private_key_path" {
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "ssh_password" {
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "k3s_version" {
|
||||
type = string
|
||||
description = "Version k3s a epingler pour un deploiement reproductible (ex: v1.31.5+k3s1). Voir https://github.com/k3s-io/k3s/releases."
|
||||
|
||||
@@ -2,9 +2,9 @@ terraform {
|
||||
required_version = ">= 1.7"
|
||||
|
||||
required_providers {
|
||||
null = {
|
||||
source = "hashicorp/null"
|
||||
version = "~> 3.2"
|
||||
provider = {
|
||||
source = "hashicorp/archive"
|
||||
version = "~> 2.4"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user