This commit is contained in:
2023-07-04 19:02:30 +02:00
parent 04c1aa3086
commit 7cc046ea2a
41 changed files with 1401 additions and 4 deletions

View File

@ -0,0 +1,54 @@
%title: Terraform
%author: Hubert
# Terraform : docker network
<br>
Doc network : https://www.terraform.io/docs/providers/docker/r/network.html
Doc container: https://www.terraform.io/docs/providers/docker/r/container.html
<br>
* création d'un réseau
```
resource "docker_network" "tips-of-mine" {
name = "mynet"
}
```
<br>
* utilisation
```
resource "docker_container" "nginx" {
image = docker_image.nginx.latest
name = "enginecks"
ports {
internal = 80
external = 80
}
networks_advanced {
name = docker_network.tips-of-mine.name
}
}
```
-----------------------------------------------------------------------------------------------
# Terraform : docker network
<br>
* changement de range
```
resource "docker_network" "tips-of-mine" {
name = "mynet1"
driver = "bridge"
ipam_config {
subnet = "10.0.5.0/24"
}
}
```
Remarque: attention à la manière de modifier

View File

@ -0,0 +1,18 @@
variable "ssh_host" {}
variable "ssh_user" {}
variable "ssh_key" {}
module "docker_install" {
source = "./modules/docker_install"
ssh_host = var.ssh_host
ssh_user = var.ssh_user
ssh_key = var.ssh_key
}
module "docker_run" {
source = "./modules/docker_run"
ssh_host = var.ssh_host
}
output "ip_container" {
value = module.docker_run.ip_docker
}

View File

@ -0,0 +1,29 @@
resource "null_resource" "ssh_target" {
connection {
type = "ssh"
user = var.ssh_user
host = var.ssh_host
private_key = file(var.ssh_key)
}
provisioner "remote-exec" {
inline = [
"sudo apt update -qq >/dev/null",
"curl -fsSL https://get.docker.com -o get-docker.sh",
"sudo chmod 755 get-docker.sh",
"sudo ./get-docker.sh >/dev/null"
]
}
provisioner "file" {
source = "${path.module}/startup-options.conf"
destination = "/tmp/startup-options.conf"
}
provisioner "remote-exec" {
inline = [
"sudo mkdir -p /etc/systemd/system/docker.service.d/",
"sudo cp /tmp/startup-options.conf /etc/systemd/system/docker.service.d/startup_options.conf",
"sudo systemctl daemon-reload",
"sudo systemctl restart docker",
"sudo usermod -aG docker vagrant"
]
}
}

View File

@ -0,0 +1,3 @@
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://10.0.41.103:2375 -H unix:///var/run/docker.sock

View File

@ -0,0 +1,3 @@
variable "ssh_host" {}
variable "ssh_user" {}
variable "ssh_key" {}

View File

@ -0,0 +1,28 @@
provider "docker" {
host = "tcp://${var.ssh_host}:2375"
}
resource "docker_network" "tips-of-mine" {
name = "mynet1"
driver = "bridge"
ipam_config {
subnet = "10.0.5.0/24"
}
}
resource "docker_image" "nginx" {
name = "nginx:latest"
}
resource "docker_container" "nginx" {
image = docker_image.nginx.latest
name = "enginecks"
ports {
internal = 80
external = 80
}
networks_advanced {
name = docker_network.tips-of-mine.name
}
}

View File

@ -0,0 +1,3 @@
output "ip_docker" {
value = docker_container.nginx.ip_address
}

View File

@ -0,0 +1 @@
variable "ssh_host" {}

View File

@ -0,0 +1,3 @@
ssh_host = "10.0.4.103"
ssh_user = "vagrant"
ssh_key = "/home/vagrant/.ssh/id_rsa"