Commit 842be545 authored by Ignacio Van Droogenbroeck's avatar Ignacio Van Droogenbroeck
Browse files

Update IV/terraform.tfvars.opt, IV/maria.tf, IV/provider.tf,...

Update IV/terraform.tfvars.opt, IV/maria.tf, IV/provider.tf, IV/terraform.tfstate, IV/terraform.tfstate.backup, IV/wordpress.tf.opt files
parent 9de86365
variable "password_root" {}
variable "password_user" {}
# Contenedor
resource "docker_container" "mariadb" {
name = "cduser_mariadb"
image = "mariadb:10.5.1"
# Especificamos el volumen a montar de mariadb. Siempre es recomendable que quede persistente en un volumen la carpeta /var/lib/mysql.
volumes {
container_path = "/var/lib/mysql"
read_only = false
host_path = "/Users/nacho/terraform/files/mariadb/lib"
}
# Especificamos variables de entorno para crear una base, generar un usuario root, una contraseña para ese usuario, el usuario de base de datos para wordpress y su contraseña.
env = ["MYSQL_DATABASE=wordpress", "MYSQL_USER=user", "MYSQL_PASSWORD=$password_user", "MYSQL_ROOT_PASSWORD=$password_root"]
command = ["--default-authentication-plugin=mysql_native_password"]
}
# Configure the Docker provider
provider "docker" {
host = "unix:///var/run/docker.sock"
}
{
"version": 4,
"terraform_version": "0.12.21",
"serial": 8,
"lineage": "2a0824a0-badf-0b4c-eb0c-56b64d0d8e68",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "docker_container",
"name": "mariadb",
"provider": "provider.docker",
"instances": [
{
"schema_version": 2,
"attributes": {
"attach": false,
"bridge": "",
"capabilities": [],
"command": [
"--default-authentication-plugin=mysql_native_password"
],
"container_logs": null,
"cpu_set": "",
"cpu_shares": 0,
"destroy_grace_seconds": null,
"devices": [],
"dns": null,
"dns_opts": null,
"dns_search": null,
"domainname": "",
"entrypoint": [
"docker-entrypoint.sh"
],
"env": [
"MYSQL_DATABASE=wordpress",
"MYSQL_PASSWORD=$password_user",
"MYSQL_ROOT_PASSWORD=$password_root",
"MYSQL_USER=user"
],
"exit_code": null,
"gateway": "172.17.0.1",
"group_add": null,
"healthcheck": [],
"host": [],
"hostname": "183fa471fdd4",
"id": "183fa471fdd47d78f1f8e949422a3e2e7ab61b7f0750cb64298374101eaab198",
"image": "sha256:3c1e634b5a426a9ad0f01ad8c55e32fe006ff70faf6a20a1f293421bfcff016a",
"ip_address": "172.17.0.2",
"ip_prefix_length": 16,
"ipc_mode": "private",
"labels": [],
"links": null,
"log_driver": "json-file",
"log_opts": null,
"logs": false,
"max_retry_count": 0,
"memory": 0,
"memory_swap": 0,
"mounts": [],
"must_run": true,
"name": "cduser_mariadb",
"network_alias": null,
"network_data": [
{
"gateway": "172.17.0.1",
"ip_address": "172.17.0.2",
"ip_prefix_length": 16,
"network_name": "bridge"
}
],
"network_mode": "default",
"networks": null,
"networks_advanced": [],
"pid_mode": "",
"ports": [],
"privileged": false,
"publish_all_ports": false,
"read_only": false,
"restart": "no",
"rm": false,
"shm_size": 64,
"start": true,
"sysctls": null,
"tmpfs": null,
"ulimit": [],
"upload": [],
"user": "",
"userns_mode": "",
"volumes": [
{
"container_path": "/var/lib/mysql",
"from_container": "",
"host_path": "/Users/nacho/terraform/files/mariadb/lib",
"read_only": false,
"volume_name": ""
}
],
"working_dir": ""
},
"private": "eyJzY2hlbWFfdmVyc2lvbiI6IjIifQ=="
}
]
}
]
}
{
"version": 4,
"terraform_version": "0.12.21",
"serial": 5,
"lineage": "2a0824a0-badf-0b4c-eb0c-56b64d0d8e68",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "docker_container",
"name": "mariadb",
"provider": "provider.docker",
"instances": [
{
"schema_version": 2,
"attributes": {
"attach": false,
"bridge": "",
"capabilities": [],
"command": [
"--default-authentication-plugin=mysql_native_password"
],
"container_logs": null,
"cpu_set": "",
"cpu_shares": 0,
"destroy_grace_seconds": null,
"devices": [],
"dns": null,
"dns_opts": null,
"dns_search": null,
"domainname": "",
"entrypoint": [
"docker-entrypoint.sh"
],
"env": [
"MYSQL_DATABASE=wordpress",
"MYSQL_PASSWORD=$password_user",
"MYSQL_ROOT_PASSWORD=$password_root",
"MYSQL_USER=user"
],
"exit_code": null,
"gateway": "172.17.0.1",
"group_add": null,
"healthcheck": [],
"host": [],
"hostname": "7f2ceea1c8e7",
"id": "7f2ceea1c8e7b29cd6e559e459ecd278d57e9f5661c91330af8ab6f5c16aa9f7",
"image": "sha256:3c1e634b5a426a9ad0f01ad8c55e32fe006ff70faf6a20a1f293421bfcff016a",
"ip_address": "172.17.0.2",
"ip_prefix_length": 16,
"ipc_mode": "private",
"labels": [],
"links": null,
"log_driver": "json-file",
"log_opts": null,
"logs": false,
"max_retry_count": 0,
"memory": 0,
"memory_swap": 0,
"mounts": [],
"must_run": true,
"name": "cduser_mariadb",
"network_alias": null,
"network_data": [
{
"gateway": "172.17.0.1",
"ip_address": "172.17.0.2",
"ip_prefix_length": 16,
"network_name": "bridge"
}
],
"network_mode": "default",
"networks": null,
"networks_advanced": [],
"pid_mode": "",
"ports": [],
"privileged": false,
"publish_all_ports": false,
"read_only": false,
"restart": "no",
"rm": false,
"shm_size": 64,
"start": true,
"sysctls": null,
"tmpfs": null,
"ulimit": [],
"upload": [],
"user": "",
"userns_mode": "",
"volumes": [
{
"container_path": "/var/lib/mysql",
"from_container": "",
"host_path": "/Users/nacho/terraform/files/mariadb/lib",
"read_only": false,
"volume_name": ""
}
],
"working_dir": ""
},
"private": "eyJzY2hlbWFfdmVyc2lvbiI6IjIifQ=="
}
]
}
]
}
#Vamos definir el proveedor. En este caso, el Docker es local, pero para hacerlo hacia a un Docker remoto, deberíamos especificar la conexión SSH hacia nuestro servidor.
local = "unix:///var/run/docker.sock"
#Vamos a especificar con variables el contenedor de mariadb
contenedor_maria = "cduser_mariadb"
imagen_maria = "mariadb:10.5.1"
password-root = "123456"
#Vamos a especificar con variables el contenedor del wordpress
contenedor = "cduser_wordpress"
imagen = "wordpress:php7.4"
#Vamos a especificar las variables de entorno del wordpress con variables de Terraform, pero también vamos a usar estás variables para la config del mariaDB, esto se llama ser eficientes.
mariadb = "cduser_mariadb"
db-user = "user"
password = "pass"
db = "wordpress"
\ No newline at end of file
variable "contenedor" {}
variable "imagen" {}
variable "mariadb" {}
variable "db-user" {}
variable "password" {}
variable "db" {}
# Contenedor
resource "docker_container" "recurso" {
name = "${var.contenedor}"
image = "${var.imagen}"
env = ["WORDPRESS_DB=${var.mariadb}", "WORDPRESS_DB_USER=${var.db-user}", "WORDPRESS_DB_PASSWORD=${var.password}", "WORDPRESS_DB_NAME=${var.db}"]
ports {
internal = 80
external = 80
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment