Skip to content
Snippets Groups Projects
Commit cf0e1f24 authored by tom.ryser's avatar tom.ryser :carousel_horse:
Browse files

pull last version (not used)

parent f42c5232
No related branches found
No related tags found
No related merge requests found
......@@ -13,19 +13,6 @@ system_info:
# add any basic packages here:
packages:
- curl
- nano
- ripgrep
- docker.io
- bash-completion
# SH commands to install jenkns
runcmd:
- sudo yum update -y # updates the package list and upgrades installed packages on the system
- sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo #downloads the Jenkins repository configuration file and saves it to /etc/yum.repos.d/jenkins.repo
- sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key #imports the GPG key for the Jenkins repository. This key is used to verify the authenticity of the Jenkins packages
- sudo yum upgrade -y # upgrades packages again, which might be necessary to ensure that any new dependencies required by Jenkins are installed
- sudo dnf install java-11-amazon-corretto -y # installs Amazon Corretto 11, which is a required dependency for Jenkins.
- sudo yum install jenkins -y #installs Jenkins itself
- sudo systemctl enable jenkins #enables the Jenkins service to start automatically at boot time
- sudo systemctl start jenkins #starts the Jenkins service immediately
......@@ -13,3 +13,33 @@ system_info:
sudo: ALL=(ALL) NOPASSWD:ALL
ssh_authorized_keys:
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICd2om++e154/EKtD66CaRELfJ/lbzum44EqLbRKjjuQ terraform@TF-lab
runcmd:
# Met à jour la liste des paquets
- sudo apt update
# Met à jour tous les paquets sans prompt
- sudo DEBIAN_FRONTEND=noninteractive apt upgrade -y
# Installe OpenSSH sans demander d’interaction
- sudo DEBIAN_FRONTEND=noninteractive apt install -y openssh-server
# Redémarre SSH pour s'assurer qu'il fonctionne
- sudo systemctl restart ssh
# Installe Java en premier (nécessaire pour Jenkins)
- sudo apt install -y openjdk-17-jre fontconfig
# Ajoute la clé et le dépôt Jenkins
- curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
- echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
# Met à jour la liste des paquets après ajout du repo Jenkins
- sudo apt update
# Installe Jenkins
- sudo apt install -y jenkins
# Active et démarre Jenkins
- sudo systemctl enable jenkins
- sudo systemctl start jenkins
\ No newline at end of file
......@@ -23,34 +23,39 @@ provider "openstack" {
cloud = "engines"
}
# SSH Key generation
resource "tls_private_key" "my_generated_key" {
algorithm = "RSA"
rsa_bits = 2048
}
resource "openstack_compute_keypair_v2" "my_keypair" {
name = "my-keypair"
name = "${var.key_name}-keypair"
public_key = tls_private_key.my_generated_key.public_key_openssh
}
resource "local_file" "private_key" {
content = tls_private_key.my_generated_key.private_key_pem
filename = "${path.module}/private_key.pem"
filename = "${pathexpand(var.private_key_path)}/${var.key_name}-keypair.pem"
provisioner "local-exec" {
command = "chmod 600 ${self.filename}"
}
}
resource "openstack_compute_instance_v2" "app_server" {
name = var.instance_name
name = "${var.instance_name}-instance"
image_id = "654bf798-579b-47aa-a7f7-8a8798c9779d"
flavor_name = "m1.medium"
key_pair = openstack_compute_keypair_v2.my_keypair.name
security_groups = ["default", "secgrp_1"]
security_groups = ["default", "${var.secgrp_name}-group"]
user_data = data.cloudinit_config.my_config.rendered
}
# Network configuration
resource "openstack_networking_secgroup_v2" "secgrp_1" {
name = "secgrp_1"
name = "${var.secgrp_name}-group"
}
resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_1" {
......@@ -93,7 +98,7 @@ resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_4" {
resource "openstack_networking_floatingip_v2" "fip_1" {
pool = "public"
description = "TF-Lab"
description = var.project_name
}
data "openstack_networking_port_v2" "port" {
......@@ -106,6 +111,7 @@ resource "openstack_networking_floatingip_associate_v2" "fip_associate" {
port_id = data.openstack_networking_port_v2.port.id
}
# Cloud-init configuration
data "cloudinit_config" "my_config" {
gzip = false
base64_encode = false
......@@ -116,16 +122,9 @@ data "cloudinit_config" "my_config" {
content = file("conf/cloud-init.users.yaml")
merge_type = "list(append)+dict(no_replace,recurse_list)"
}
part {
filename = "file-2"
content_type = "text/cloud-config"
content = file("conf/cloud-init.packages.yaml")
merge_type = "list(append)+dict(no_replace,recurse_list)"
}
}
# Configuration du provider AWS pour OpenStack Swift (S3-compatible)
# AWS S3-compatible provider for OpenStack Swift
provider "aws" {
region = "us-east-1"
skip_credentials_validation = true
......@@ -138,9 +137,9 @@ provider "aws" {
}
}
# Création d'un conteneur (équivalent à un bucket S3)
# Bucket and object creation in OpenStack Swift
resource "aws_s3_bucket" "bucket" {
bucket = var.container_name
bucket = "${var.bucket_name}-bucket"
}
resource "aws_s3_bucket_policy" "public_policy" {
......@@ -161,4 +160,4 @@ resource "aws_s3_bucket_policy" "public_policy" {
}
]
})
}
\ No newline at end of file
}
# outputs.tf
output "instance_id" {
description = "ID of the instance"
value = openstack_compute_instance_v2.app_server.id
}
output "instance_public_ip" {
description = "Public IP address of instance"
value = openstack_networking_floatingip_v2.fip_1.address
}
output "private_key" {
description = "Private key for SSH access"
value = tls_private_key.my_generated_key.private_key_pem
sensitive = true
}
\ No newline at end of file
variable "os_access_key" {
description = "OpenStack Swift Access Key"
type = string
}
variable "os_secret_key" {
description = "OpenStack Swift Secret Key"
type = string
}
variable "project_name" {
description = "Name of the project"
type = string
default = "jenkins-qcm"
}
variable "instance_name" {
description = "Value of the instance's name tag"
description = "Name of the instance"
type = string
default = "jenkins-qcm"
}
variable "secgrp_name" {
description = "Name of the security group"
type = string
default = "Jenkins"
default = "jenkins-qcm"
}
variable "container_name" {
variable "bucket_name" {
description = "Name of the OpenStack Swift container"
type = string
default = "Jenkins-Server"
default = "jenkins-qcm"
}
# Variables nécessaires
variable "os_access_key" {
description = "OpenStack Swift Access Key"
variable "key_name" {
description = "Name of the SSH key"
type = string
default = "jenkins-qcm"
}
variable "os_secret_key" {
description = "OpenStack Swift Secret Key"
variable "private_key_path" {
description = "Destination for SSH key"
type = string
default = "~/.ssh/"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment