Skip to content
Snippets Groups Projects
Commit 77868cd6 authored by MUNIER Florian's avatar MUNIER Florian
Browse files

[add] rancher.tf

parent a0ff858d
Branches
No related tags found
No related merge requests found
Pipeline #15888 canceled
......@@ -2,20 +2,25 @@ module "mod-os-private-network" {
source = "./mod-os-private-network/"
KEYPAIR_PATH = "$HOME/.ssh"
EXTERNAL_NETWORK = "external"
ROUTER_NAME = "router"
NETWORK_NAME = "network"
SUBNET_NAME = "subnet"
SUBNET_IP_RANGE = "192.168.3.0/24"
ROUTER_NAME = "router_tf_private"
NETWORK_NAME = "network_tf_private"
SUBNET_NAME = "subnet_tf_private"
SUBNET_IP_RANGE = "192.168.1.0/24"
DNS = ["192.44.75.10"]
INSTANCE_BASTION_NAME = "bastion"
INSTANCE_BASTION_IMAGE = "imta-docker"
INSTANCE_BASTION_FLAVOR = "s10.medium"
INSTANCE_BASTION_KEY_PAIR = "projet_terraform2"
INSTANCE_BASTION_KEY_PAIR = "projet_terraform"
INSTANCE_ORCHEST_NAME = ["node01", "node02", "node03"]
INSTANCE_ORCHEST_IMAGE = "imta-docker"
INSTANCE_ORCHEST_FLAVOR = "s10.medium"
INSTANCE_ORCHEST_KEY_PAIR = "cluster_key2"
SECGROUP_BASTION_NAME = "secgroup_bastion2"
SECGROUP_APPLICATION_NAME = "secgroup_application2"
SECGROUP_INTERNAL_NETWORK_NAME = "secgroup_internal_network2"
INSTANCE_ORCHEST_KEY_PAIR = "cluster_key"
INSTANCE_ZABBIX_SERVER_NAME = "zabbix_server"
INSTANCE_ZABBIX_SERVER_IMAGE = "imta-docker"
INSTANCE_ZABBIX_SERVER_FLAVOR = "s10.medium"
INSTANCE_ZABBIX_SERVER_KEY_PAIR = "cluster_key"
SECGROUP_BASTION_NAME = "secgroup_bastion"
SECGROUP_APPLICATION_NAME = "secgroup_application"
SECGROUP_INTERNAL_NETWORK_NAME = "secgroup_internal_network"
K3S_TOKEN = "cluster"
}
resource "null_resource" "install_kubernetes_bastion" {
connection {
type = "ssh"
user = "ubuntu"
private_key = "${openstack_compute_keypair_v2.keypair_project.private_key}"
host = "${openstack_networking_floatingip_v2.floatip_admin.address}"
agent = "false"
}
for_each = toset(var.INSTANCE_ORCHEST_NAME)
# Install Kubernetes on the instance bastion
provisioner "remote-exec" {
inline = [
"sudo apt update",
"curl -fL https://get.k3s.io | K3S_TOKEN=${var.K3S_TOKEN} sh -s - server --cluster-init",
"mkdir ~/.kube",
"sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube",
]
}
depends_on = [openstack_compute_instance_v2.bastion_instance,
openstack_compute_instance_v2.orchestration_instance,
null_resource.copy_keypair_cluster]
}
# Join the worker nodes to the Kubernetes cluster
resource "null_resource" "join_worker_nodes" {
for_each = toset(var.INSTANCE_ORCHEST_NAME)
# Connexion aux instances du cluster
connection {
type = "ssh"
user = "ubuntu"
bastion_private_key = "${openstack_compute_keypair_v2.keypair_project.private_key}"
bastion_host = "${openstack_networking_floatingip_v2.floatip_admin.address}"
private_key = "${openstack_compute_keypair_v2.keypair_cluster.private_key}"
host = "${openstack_compute_instance_v2.orchestration_instance[each.key].access_ip_v4}"
agent = "false"
}
provisioner "remote-exec" {
inline = [
"curl -fL https://get.k3s.io | K3S_TOKEN=${var.K3S_TOKEN} K3S_URL=https://${openstack_compute_instance_v2.bastion_instance.access_ip_v4}:6443 sh -s -",
]
}
depends_on = [openstack_compute_instance_v2.bastion_instance,
openstack_compute_instance_v2.orchestration_instance,
null_resource.install_kubernetes_bastion]
}
\ No newline at end of file
......@@ -38,6 +38,11 @@ variable "INSTANCE_ORCHEST_NAME" {
default = ["node01", "node02", "node03"]
}
variable "INSTANCE_ZABBIX_SERVER_NAME" {
type = string
default = "zabbix_server"
}
variable "INSTANCE_BASTION_IMAGE" {
type = string
default = "imta-docker"
......@@ -48,6 +53,11 @@ variable "INSTANCE_ORCHEST_IMAGE" {
default = "imta-docker"
}
variable "INSTANCE_ZABBIX_SERVER_IMAGE" {
type = string
default = "imta-docker"
}
variable "INSTANCE_BASTION_FLAVOR" {
type = string
default = "s10.medium"
......@@ -58,6 +68,11 @@ variable "INSTANCE_ORCHEST_FLAVOR" {
default = "s10.medium"
}
variable "INSTANCE_ZABBIX_SERVER_FLAVOR" {
type = string
default = "s10.medium"
}
variable "INSTANCE_BASTION_KEY_PAIR" {
type = string
default = "projet_terraform"
......@@ -68,6 +83,11 @@ variable "INSTANCE_ORCHEST_KEY_PAIR" {
default = "cluster_key"
}
variable "INSTANCE_ZABBIX_SERVER_KEY_PAIR" {
type = string
default = "cluster_key"
}
variable "SECGROUP_BASTION_NAME" {
type = string
default = "secgroup_bastion"
......@@ -87,3 +107,8 @@ variable "KEYPAIR_PATH" {
type = string
default = "$HOME/.ssh"
}
variable "K3S_TOKEN" {
type = string
default = "cluster"
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment