From db91b325a360ff97cdc1f7a0a2ddb545ea1f1121 Mon Sep 17 00:00:00 2001 From: mcruanes Date: Sat, 29 May 2021 18:40:17 +0200 Subject: [PATCH] Devops: Terraform updates --- README.md | 48 ++-- docker/2/docker-compose.scope.yml | 23 ++ docker/2/docker-compose.yml | 34 +++ docker/2/readme.md | 0 kubernetes/2/nginx-deploy.yaml | 21 ++ kubernetes/2/nginx-svc.yaml | 13 + references.md | 41 +++ terraform/1/container.tf | 4 +- terraform/1/readme.md | 4 +- terraform/2/provider.tf | 14 + terraform/3/provider.tf | 13 + terraform/4/provider.tf | 14 + terraform/4/readme.md | 6 + terraform/4/traefik.tf | 2 +- terraform/5/01-container-ghost-rp.tf | 69 +++++ terraform/5/01-container-ghost.tf | 54 ---- terraform/7/gron.txt | 259 ++++++++++++++++++ terraform/7/main.tf | 26 ++ terraform/7/modules/docker_install/main.tf | 29 ++ .../docker_install/startup-options.conf | 3 + .../7/modules/docker_install/variables.tf | 3 + terraform/7/modules/docker_run/main.tf | 15 + terraform/7/modules/docker_run/variables.tf | 1 + terraform/7/modules/docker_wordpress/main.tf | 74 +++++ .../7/modules/docker_wordpress/outputs.tf | 12 + .../7/modules/docker_wordpress/variables.tf | 4 + terraform/7/show.txt | 176 ++++++++++++ terraform/7/terraform.tfvars | 4 + 28 files changed, 888 insertions(+), 78 deletions(-) create mode 100644 docker/2/docker-compose.scope.yml create mode 100644 docker/2/docker-compose.yml create mode 100644 docker/2/readme.md create mode 100644 kubernetes/2/nginx-deploy.yaml create mode 100644 kubernetes/2/nginx-svc.yaml create mode 100644 references.md create mode 100644 terraform/5/01-container-ghost-rp.tf delete mode 100644 terraform/5/01-container-ghost.tf create mode 100644 terraform/7/gron.txt create mode 100644 terraform/7/main.tf create mode 100644 terraform/7/modules/docker_install/main.tf create mode 100644 terraform/7/modules/docker_install/startup-options.conf create mode 100644 terraform/7/modules/docker_install/variables.tf create mode 100644 terraform/7/modules/docker_run/main.tf create mode 100644 terraform/7/modules/docker_run/variables.tf create mode 100644 terraform/7/modules/docker_wordpress/main.tf create mode 100644 terraform/7/modules/docker_wordpress/outputs.tf create mode 100644 terraform/7/modules/docker_wordpress/variables.tf create mode 100644 terraform/7/show.txt create mode 100644 terraform/7/terraform.tfvars diff --git a/README.md b/README.md index 0b2aadd..382ec8b 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # DevOps with examples by seomago -date: 3/5/2021 +Update: 29/5/2021 ## About the project -These are a list of self-study examples for my personal Devops roadmap learning path. +These is a list of self-study examples for my personal Devops roadmap learning path. DevOps is changing the way of developing web applications. We will be building several web applications using different technologies. We will be using debian distribution linux machines. @@ -22,12 +22,16 @@ git clone git@github.com/seomago/devops-examples If you like this project and you want to contribute, you're more than welcome to do it, See contribute section below. - -## 1. Sysadmin linux examples -Classic web app 3-tier installation - 1. [App Mono tier ghost - without ansible - the old non devops way](./sysadmin/1) - 2. [App Mono tier ghost install - with ansible](./sysadmin/2) - 3. [App 3-tier ghost install](./sysadmin/3) +## 1. Terraform examples (with docker) + 1. [Terraform and docker provider example 1](./terraform/1) + 2. [Terraform database container](./terraform/2) + 3. [wordpress container example](./terraform/3) + 4. [Reverse proxy Traefik with wordpress container](./terraform/4) + 5. [Nginx Ghost example](./terraform/5) + 6. [Minio S3 container](./terraform/6) + 7. [Terraform and modules](./terraform/7) + 8. [kubernetes kind provider](./terraform/8) + 9. Terraform AWS EKS cloud examples... ## 2. Docker examples 1. [Docker-compose App 3-tier install](./docker/1) @@ -40,16 +44,15 @@ Classic web app 3-tier installation 2. [arkade+kind+k9s+delete namespace+kubectl get nodes+k apply.Services and Load Balancers](./kubernetes/2) 3. [arkade+k9s+Deployments](./kubernetes/3) / [video](https://youtu.be/q-ZicDSb3Cc) 4. [App easy install with arkade](./kubernetes/4) - 5. more to come... + 5. [kubernetes and ingress example](./kubernetes/5) / + 6. [kubernetes and argo CD example](./kubernetes/6) / + 7. more to come... -## 4. Terraform examples (with docker) - 1. [Terraform and docker provider example 1](./terraform/1) / - 2. [Terraform database container](./terraform/2) / - 3. [wordpress container example](./terraform/3) / - 4. [Reverse proxy Traefik with wordpress container](./terraform/4) / - 5. [Nginx Ghost example](./terraform/5) - 6. [kubernetes and terraform](./terraform/6) - 7. Terraform AWS cloud examples +## 4. Sysadmin linux - ansible examples +Classic web app 3-tier installation + 1. [App Mono tier ghost - without ansible - the old non devops way](./sysadmin/1) + 2. [App Mono tier ghost install - with ansible](./sysadmin/2) + 3. [App 3-tier ghost install](./sysadmin/3) ## 5. Salt examples @@ -65,7 +68,7 @@ Classic web app 3-tier installation 2. [Portainer CE / weavescope and docker swarm](./mix/3) / 3. [Jupyter notebooks presentation and installation](./mix/4) / 4. [kubernetes cluster with kubeadm](./mix/5) / - 5. [argo CD](./mix/3) / + 6. [influxdb / telegraf](./mix/3) / 7. [Prometheus](./mix/3) 8. [App Mono tier ghost install - with bash jupyter notebook](./sysadmin/2) @@ -78,15 +81,22 @@ Classic web app 3-tier installation * https://github.com/alexellis/arkade * https://www.server-world.info/en/note?os=CentOS_7&p=salt&f=1 * https://www.server-world.info/en/note?os=CentOS_7&p=ansible&f=1 + * https://github.com/lokeshkamalay/DevOps-References * https://github.com/seomago/devops-examples * https://github.com/geerlingguy/ansible-for-devops +* https://github.com/geerlingguy/ansible-for-kubernetes + +## References Terraform +* https://gitlab.com/xavki/presentations-terraform-fr +* https://github.com/zealvora/terraform-beginner-to-advanced-resource + ## Feedback / Contribute I am sure all these exercises are can be improved/more academic. -If you like this project and you want to contribute, you're more than welcome to do it, just fork it and make a pull request when you're ready. Here, you can see the [To Do list](https://github.com/xe-nvdk/ezcompose/projects/1) and here the [Issues](https://github.com/xe-nvdk/ezcompose/issues). +If you like this project and you want to contribute, you're more than welcome to do it, just fork it and make a pull request when you're ready. Here, you can see the [To Do list](https://github.com/seomago/devops-examples/projects/1) and here the [Issues](https://github.com/seomago/devops-examples/issues). ## Acknowledgements diff --git a/docker/2/docker-compose.scope.yml b/docker/2/docker-compose.scope.yml new file mode 100644 index 0000000..c90962b --- /dev/null +++ b/docker/2/docker-compose.scope.yml @@ -0,0 +1,23 @@ +version: '2' +# sudo docker-compose -f docker-compose.scope.yml up -d +services: + nginx-proxy: + image: jwilder/nginx-proxy + ports: + - "80:80" + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro + # localhost:4040 + scope: + image: weaveworks/scope:1.13.2 + #network_mode: "host" + pid: "host" + privileged: true + labels: + - "works.weave.role=system" + volumes: + - "/var/run/docker.sock:/var/run/docker.sock:rw" + command: + - "--probe.docker=true" + environment: + - VIRTUAL_HOST=scope.aa.com \ No newline at end of file diff --git a/docker/2/docker-compose.yml b/docker/2/docker-compose.yml new file mode 100644 index 0000000..9d7e1af --- /dev/null +++ b/docker/2/docker-compose.yml @@ -0,0 +1,34 @@ +version: '2' +services: + #nginx-proxy: + # image: jwilder/nginx-proxy + # ports: + # - "80:80" + # volumes: + # - /var/run/docker.sock:/tmp/docker.sock:ro + + + whoami1: + image: jwilder/whoami + environment: + - VIRTUAL_HOST=preprod.aa.com,adminpre.aa.com + whoami2: + image: jwilder/whoami + environment: + - VIRTUAL_HOST=preprod.aa.com + + + adminer1: + image: adminer:4.8.0 + environment: + - VIRTUAL_HOST=prod.aa.com + #adminer2: + # image: adminer:4.8.0 + # environment: + # - VIRTUAL_HOST=prod.aa.com + + + + +#easymysql +#curl -is aa.com diff --git a/docker/2/readme.md b/docker/2/readme.md new file mode 100644 index 0000000..e69de29 diff --git a/kubernetes/2/nginx-deploy.yaml b/kubernetes/2/nginx-deploy.yaml new file mode 100644 index 0000000..065dd1f --- /dev/null +++ b/kubernetes/2/nginx-deploy.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + labels: + env: dev +spec: + replicas: 3 + selector: + matchLabels: + env: dev + template: + metadata: + labels: + env: dev + spec: + containers: + - name: nginx + image: nginx + ports: + - containerPort: 80 diff --git a/kubernetes/2/nginx-svc.yaml b/kubernetes/2/nginx-svc.yaml new file mode 100644 index 0000000..dd4c4ff --- /dev/null +++ b/kubernetes/2/nginx-svc.yaml @@ -0,0 +1,13 @@ +#https://github.com/seomago/Course_EKS-Basics/blob/master/nginx-svc.yaml +apiVersion: v1 +kind: Service +metadata: + name: nginx-svc + labels: + env: dev +spec: + type: LoadBalancer + ports: + - port: 80 + selector: + env: dev \ No newline at end of file diff --git a/references.md b/references.md new file mode 100644 index 0000000..7261ba2 --- /dev/null +++ b/references.md @@ -0,0 +1,41 @@ + +## socks +https://github.com/microservices-demo/microservices-demo +logging fluentd and elasticsearch +locust python load performance +## logging fluentd elasticsearch +https://github.com/microservices-demo/microservices-demo/blob/master/deploy/docker-compose/docker-compose.logging.yml +https://github.com/microservices-demo/microservices-demo/blob/master/deploy/docker-compose/docker-compose.yml +https://docs.bitnami.com/kubernetes/apps/fluentd/ + + +## References 2 +https://github.com/aminueza/terraform-provider-minio +https://github.com/severalnines/ansible-clustercontrol + +## references kube +devops tools k9s +https://www.golinuxcloud.com/kubernetes-pod/ + +https://github.com/gruntwork-io/infrastructure-as-code-training +https://github.com/xe-nvdk +https://github.com/PacktPublishing/Cloud-Native-with-Kubernetes +https://github.com/shashank-ssriva/WordPress-on-Minikube + + +## french youtube channels +https://gitlab.com/users/xavki/projects +https://gitlab.com/xavki/presentations-dockercompose + +https://www.youtube.com/c/xavki-linux + +https://www.youtube.com/watch?v=hMpGUy3hngc +les chaines francophones + +Xavki : https://www.youtube.com/channel/UCs_A...​ +Adrien D Linuxtricks : https://www.youtube.com/channel/UCDKP...​ +Cocadmin : https://www.youtube.com/channel/UCVRJ...​ +Yves Rougy : https://www.youtube.com/channel/UCfsE...​ +Tonton Jo : https://www.youtube.com/channel/UCnED + +@grafikart_fr @Cookieconnecte @KrustyHack (pas forcement 100% linux mais qui l'aborde un peu) \ No newline at end of file diff --git a/terraform/1/container.tf b/terraform/1/container.tf index 9cbbfbb..ad47668 100644 --- a/terraform/1/container.tf +++ b/terraform/1/container.tf @@ -10,7 +10,7 @@ #} -# Devops exercise container 2 +# Devops exercise container 1 resource "docker_container" "hello_world" { name = "de_hello_world" image = "tutum/hello-world" @@ -23,7 +23,7 @@ resource "docker_container" "hello_world" { } } -# Devops exercise container 3 +# Devops exercise container 2 resource "docker_container" "adminer" { name = "de_adminer" image = "adminer:4.8.0" diff --git a/terraform/1/readme.md b/terraform/1/readme.md index 1c750fc..d562ebc 100644 --- a/terraform/1/readme.md +++ b/terraform/1/readme.md @@ -1,5 +1,5 @@ ## intro terraform - +Terraform is a famous declarative infrastructure as code IAC tool. ## arkade terraform install @@ -23,7 +23,7 @@ ls terraform.tfstate* * terraform remote push (minio) S3 / consul from iac book -Terraform is a famous declarative infrastructure as code IAC tool. + ## reference diff --git a/terraform/2/provider.tf b/terraform/2/provider.tf index c97ffad..f0167c6 100644 --- a/terraform/2/provider.tf +++ b/terraform/2/provider.tf @@ -1,3 +1,17 @@ + +# Set the required provider and versions +terraform { + required_providers { + # We recommend pinning to the specific version of the Docker Provider you're using + # since new versions are released frequently + docker = { + source = "kreuzwerker/docker" + version = "2.11.0" + } + } +} + + # Configure the Docker provider provider "docker" { host = "unix:///var/run/docker.sock" diff --git a/terraform/3/provider.tf b/terraform/3/provider.tf index 55107cf..af44e53 100644 --- a/terraform/3/provider.tf +++ b/terraform/3/provider.tf @@ -4,4 +4,17 @@ variable "local" {} provider "docker" { host = "${var.local}" +} + + +# Set the required provider and versions +terraform { + required_providers { + # We recommend pinning to the specific version of the Docker Provider you're using + # since new versions are released frequently + docker = { + source = "kreuzwerker/docker" + version = "2.11.0" + } + } } \ No newline at end of file diff --git a/terraform/4/provider.tf b/terraform/4/provider.tf index c97ffad..f0167c6 100644 --- a/terraform/4/provider.tf +++ b/terraform/4/provider.tf @@ -1,3 +1,17 @@ + +# Set the required provider and versions +terraform { + required_providers { + # We recommend pinning to the specific version of the Docker Provider you're using + # since new versions are released frequently + docker = { + source = "kreuzwerker/docker" + version = "2.11.0" + } + } +} + + # Configure the Docker provider provider "docker" { host = "unix:///var/run/docker.sock" diff --git a/terraform/4/readme.md b/terraform/4/readme.md index 11af8f5..675fe62 100644 --- a/terraform/4/readme.md +++ b/terraform/4/readme.md @@ -7,3 +7,9 @@ En este ejemplo, un poco más complejo que el anterior, voy a desplegar con Terr Este ejemplo, te servirá de manera práctica para tener un wordpress, con su base de datos, ambos, por detrás de un Reverse Proxy con su configuración para que obtenga certificados SSL de Lets Encrypt. También te mostrará como usar una serie de recursos de Terraform, tales volumenes, labels, commandos y variables de entorno. Si ves que se puede mejorar, hacer un fork y luego hace un Pull Request. + + +Traefik + +a.com +c.com diff --git a/terraform/4/traefik.tf b/terraform/4/traefik.tf index 89323f9..268ac9c 100644 --- a/terraform/4/traefik.tf +++ b/terraform/4/traefik.tf @@ -1,6 +1,6 @@ # Contenedor Traefik resource "docker_container" "traefik" { - name = "cduser_traefik" + name = "my_traefik" image = "traefik:v2.1.4" command = ["--entrypoints.web.address=:80", "--entrypoints.websecure.address=:443", "--providers.docker", "--api", "--api.dashboard=true", "--log.level=ERROR", "--accesslog.filepath=/Users/nacho/terraform/files/traefik/log/access.log", "--accesslog.format=json", "--accesslog.filters.statuscodes=200,300-302", "--accesslog.filters.retryattempts", "--accesslog.filters.minduration=10ms", "--certificatesresolvers.leresolver.acme.httpchallenge=true", "--certificatesresolvers.leresolver.acme.email=nombre@email.com", "--certificatesresolvers.leresolver.acme.storage=/acme.json", "--certificatesresolvers.leresolver.acme.httpchallenge.entrypoint=web"] diff --git a/terraform/5/01-container-ghost-rp.tf b/terraform/5/01-container-ghost-rp.tf new file mode 100644 index 0000000..bc61a10 --- /dev/null +++ b/terraform/5/01-container-ghost-rp.tf @@ -0,0 +1,69 @@ + +# ghost app deploy with nginx +# with RP port 80 + + +# Set the required provider and versions +terraform { + required_providers { + # We recommend pinning to the specific version of the Docker Provider you're using + # since new versions are released frequently + docker = { + source = "kreuzwerker/docker" + version = "2.11.0" + } + } +} + +# Configure the Docker provider +provider "docker" { + host = "unix:///var/run/docker.sock" +} + +#data search image +data "docker_registry_image" "ghost" { + name = "ghost:0.10" +} + +data "docker_registry_image" "nginx-proxy" { + name = "jwilder/nginx-proxy:0.4.0" +} + +# pull image +resource "docker_image" "ghost" { + name = "data.docker_registry_image.ghost.name" + #name = "${data.docker_registry_image.ghost.name}" + pull_trigger = "data.docker_registry_image.ghost.sha256_digest" +} + +# pull image +resource "docker_image" "nginx-proxy" { + name = "data.docker_registry_image.nginx-proxy.name" + pull_trigger = "data.docker_registry_image.nginx-proxy.sha256_digest" +} + + + +resource "docker_container" "nginx-proxy" { + name = "nginx-proxy" + image = "${docker_image.nginx-proxy.latest}" + ports { + internal = 80 + external = 80 + protocol = "tcp" + } + volumes { + host_path = "/var/run/docker.sock" + container_path = "/tmp/docker.sock" + read_only = true + } +} + + + +resource "docker_container" "ghost" { + name = "ghost" + image = "${docker_image.ghost.latest}" + env = ["VIRTUAL_HOST=localhost"] +} +#Now let \ No newline at end of file diff --git a/terraform/5/01-container-ghost.tf b/terraform/5/01-container-ghost.tf deleted file mode 100644 index dbf875e..0000000 --- a/terraform/5/01-container-ghost.tf +++ /dev/null @@ -1,54 +0,0 @@ - -# ghost app deploy with nginx - -provider "docker" { -host = "tcp://1.2.3.4:2375" -} - - -data "docker_registry_image" "ghost" { -name = "ghost:0.10" -} - -data "docker_registry_image" "nginx-proxy" { -name = "jwilder/nginx-proxy:0.4.0" -} - -# pull image -resource "docker_image" "ghost" { -name = "${data.docker_registry_image.ghost.name}" -pull_trigger = "${data.docker_registry_image.ghost.sha256_digest}" -} - -# pull image -resource "docker_image" "nginx-proxy" { -name = "${data.docker_registry_image.nginx-proxy.name}" -pull_trigger = "${data.docker_registry_image.nginx-proxy.sha256_digest}" -} - - - -resource "docker_container" "nginx-proxy" { -name = "nginx-proxy" -image = "${docker_image.nginx-proxy.latest}" -ports { -internal = 80 -external = 80 -protocol = "tcp" -} -volumes { -host_path = "/var/run/docker.sock" -container_path = "/tmp/docker.sock" -read_only = true -} -} - - - -resource "docker_container" "ghost" { -name = "ghost" -image = "${docker_image.ghost.latest}" -env -= ["VIRTUAL_HOST=localhost"] -} -Now let' \ No newline at end of file diff --git a/terraform/7/gron.txt b/terraform/7/gron.txt new file mode 100644 index 0000000..0d8e418 --- /dev/null +++ b/terraform/7/gron.txt @@ -0,0 +1,259 @@ +json = {}; +json.format_version = "0.1"; +json.terraform_version = "0.13.1"; +json.values = {}; +json.values.outputs = {}; +json.values.outputs.docker_ip_db = {}; +json.values.outputs.docker_ip_db.sensitive = false; +json.values.outputs.docker_ip_db.value = "172.20.0.2"; +json.values.outputs.docker_ip_wordpress = {}; +json.values.outputs.docker_ip_wordpress.sensitive = false; +json.values.outputs.docker_ip_wordpress.value = "172.20.0.3"; +json.values.outputs.docker_volume = {}; +json.values.outputs.docker_volume.sensitive = false; +json.values.outputs.docker_volume.value = "/tt/wordpressdb/"; +json.values.root_module = {}; +json.values.root_module.child_modules = []; +json.values.root_module.child_modules[0] = {}; +json.values.root_module.child_modules[0].address = "module.docker_wordpress"; +json.values.root_module.child_modules[0].resources = []; +json.values.root_module.child_modules[0].resources[0] = {}; +json.values.root_module.child_modules[0].resources[0].address = "module.docker_wordpress.docker_container.db"; +json.values.root_module.child_modules[0].resources[0].depends_on = []; +json.values.root_module.child_modules[0].resources[0].depends_on[0] = "module.docker_wordpress.docker_network.wordpress"; +json.values.root_module.child_modules[0].resources[0].mode = "managed"; +json.values.root_module.child_modules[0].resources[0].name = "db"; +json.values.root_module.child_modules[0].resources[0].provider_name = "registry.terraform.io/kreuzwerker/docker"; +json.values.root_module.child_modules[0].resources[0].schema_version = 2; +json.values.root_module.child_modules[0].resources[0].type = "docker_container"; +json.values.root_module.child_modules[0].resources[0].values = {}; +json.values.root_module.child_modules[0].resources[0].values.attach = false; +json.values.root_module.child_modules[0].resources[0].values.bridge = ""; +json.values.root_module.child_modules[0].resources[0].values.capabilities = []; +json.values.root_module.child_modules[0].resources[0].values.command = []; +json.values.root_module.child_modules[0].resources[0].values.command[0] = "mysqld"; +json.values.root_module.child_modules[0].resources[0].values.container_logs = null; +json.values.root_module.child_modules[0].resources[0].values.cpu_set = ""; +json.values.root_module.child_modules[0].resources[0].values.cpu_shares = 0; +json.values.root_module.child_modules[0].resources[0].values.destroy_grace_seconds = null; +json.values.root_module.child_modules[0].resources[0].values.devices = []; +json.values.root_module.child_modules[0].resources[0].values.dns = null; +json.values.root_module.child_modules[0].resources[0].values.dns_opts = null; +json.values.root_module.child_modules[0].resources[0].values.dns_search = null; +json.values.root_module.child_modules[0].resources[0].values.domainname = ""; +json.values.root_module.child_modules[0].resources[0].values.entrypoint = []; +json.values.root_module.child_modules[0].resources[0].values.entrypoint[0] = "docker-entrypoint.sh"; +json.values.root_module.child_modules[0].resources[0].values.env = []; +json.values.root_module.child_modules[0].resources[0].values.env[0] = "MYSQL_DATABASE=wordpress"; +json.values.root_module.child_modules[0].resources[0].values.env[1] = "MYSQL_PASSWORD=wordpress"; +json.values.root_module.child_modules[0].resources[0].values.env[2] = "MYSQL_ROOT_PASSWORD=wordpress"; +json.values.root_module.child_modules[0].resources[0].values.env[3] = "MYSQL_USER=wordpress"; +json.values.root_module.child_modules[0].resources[0].values.exit_code = null; +json.values.root_module.child_modules[0].resources[0].values.gateway = "172.20.0.1"; +json.values.root_module.child_modules[0].resources[0].values.group_add = null; +json.values.root_module.child_modules[0].resources[0].values.healthcheck = null; +json.values.root_module.child_modules[0].resources[0].values.host = []; +json.values.root_module.child_modules[0].resources[0].values.hostname = "54b8f1043628"; +json.values.root_module.child_modules[0].resources[0].values.id = "54b8f1043628ab73368a2baa18aafddfa8520da78d2bd17f76b578443227ada5"; +json.values.root_module.child_modules[0].resources[0].values.image = "sha256:87eca374c0ed97f0f0b504174b0d22b0a0add454414c0dbf5ae43870369f6854"; +json.values.root_module.child_modules[0].resources[0].values.init = false; +json.values.root_module.child_modules[0].resources[0].values.ip_address = "172.20.0.2"; +json.values.root_module.child_modules[0].resources[0].values.ip_prefix_length = 16; +json.values.root_module.child_modules[0].resources[0].values.ipc_mode = "private"; +json.values.root_module.child_modules[0].resources[0].values.labels = []; +json.values.root_module.child_modules[0].resources[0].values.links = null; +json.values.root_module.child_modules[0].resources[0].values.log_driver = "json-file"; +json.values.root_module.child_modules[0].resources[0].values.log_opts = null; +json.values.root_module.child_modules[0].resources[0].values.logs = false; +json.values.root_module.child_modules[0].resources[0].values.max_retry_count = 0; +json.values.root_module.child_modules[0].resources[0].values.memory = 0; +json.values.root_module.child_modules[0].resources[0].values.memory_swap = 0; +json.values.root_module.child_modules[0].resources[0].values.mounts = []; +json.values.root_module.child_modules[0].resources[0].values.must_run = true; +json.values.root_module.child_modules[0].resources[0].values.name = "db"; +json.values.root_module.child_modules[0].resources[0].values.network_alias = null; +json.values.root_module.child_modules[0].resources[0].values.network_data = []; +json.values.root_module.child_modules[0].resources[0].values.network_data[0] = {}; +json.values.root_module.child_modules[0].resources[0].values.network_data[0].gateway = "172.20.0.1"; +json.values.root_module.child_modules[0].resources[0].values.network_data[0].global_ipv6_address = ""; +json.values.root_module.child_modules[0].resources[0].values.network_data[0].global_ipv6_prefix_length = 0; +json.values.root_module.child_modules[0].resources[0].values.network_data[0].ip_address = "172.20.0.2"; +json.values.root_module.child_modules[0].resources[0].values.network_data[0].ip_prefix_length = 16; +json.values.root_module.child_modules[0].resources[0].values.network_data[0].ipv6_gateway = ""; +json.values.root_module.child_modules[0].resources[0].values.network_data[0].network_name = "wordpress_net"; +json.values.root_module.child_modules[0].resources[0].values.network_mode = "wordpress_net"; +json.values.root_module.child_modules[0].resources[0].values.networks = null; +json.values.root_module.child_modules[0].resources[0].values.networks_advanced = []; +json.values.root_module.child_modules[0].resources[0].values.networks_advanced[0] = {}; +json.values.root_module.child_modules[0].resources[0].values.networks_advanced[0].aliases = []; +json.values.root_module.child_modules[0].resources[0].values.networks_advanced[0].ipv4_address = ""; +json.values.root_module.child_modules[0].resources[0].values.networks_advanced[0].ipv6_address = ""; +json.values.root_module.child_modules[0].resources[0].values.networks_advanced[0].name = "wordpress_net"; +json.values.root_module.child_modules[0].resources[0].values.pid_mode = ""; +json.values.root_module.child_modules[0].resources[0].values.ports = []; +json.values.root_module.child_modules[0].resources[0].values.privileged = false; +json.values.root_module.child_modules[0].resources[0].values.publish_all_ports = false; +json.values.root_module.child_modules[0].resources[0].values.read_only = false; +json.values.root_module.child_modules[0].resources[0].values.remove_volumes = true; +json.values.root_module.child_modules[0].resources[0].values.restart = "always"; +json.values.root_module.child_modules[0].resources[0].values.rm = false; +json.values.root_module.child_modules[0].resources[0].values.security_opts = []; +json.values.root_module.child_modules[0].resources[0].values.shm_size = 64; +json.values.root_module.child_modules[0].resources[0].values.start = true; +json.values.root_module.child_modules[0].resources[0].values.stdin_open = false; +json.values.root_module.child_modules[0].resources[0].values.sysctls = null; +json.values.root_module.child_modules[0].resources[0].values.tmpfs = null; +json.values.root_module.child_modules[0].resources[0].values.tty = false; +json.values.root_module.child_modules[0].resources[0].values.ulimit = []; +json.values.root_module.child_modules[0].resources[0].values.upload = []; +json.values.root_module.child_modules[0].resources[0].values.user = ""; +json.values.root_module.child_modules[0].resources[0].values.userns_mode = ""; +json.values.root_module.child_modules[0].resources[0].values.volumes = []; +json.values.root_module.child_modules[0].resources[0].values.volumes[0] = {}; +json.values.root_module.child_modules[0].resources[0].values.volumes[0].container_path = "/var/lib/mysql/"; +json.values.root_module.child_modules[0].resources[0].values.volumes[0].from_container = ""; +json.values.root_module.child_modules[0].resources[0].values.volumes[0].host_path = "/tt/wordpressdb/"; +json.values.root_module.child_modules[0].resources[0].values.volumes[0].read_only = null; +json.values.root_module.child_modules[0].resources[0].values.volumes[0].volume_name = "db_data"; +json.values.root_module.child_modules[0].resources[0].values.working_dir = ""; +json.values.root_module.child_modules[0].resources[1] = {}; +json.values.root_module.child_modules[0].resources[1].address = "module.docker_wordpress.docker_container.wordpress"; +json.values.root_module.child_modules[0].resources[1].depends_on = []; +json.values.root_module.child_modules[0].resources[1].depends_on[0] = "module.docker_wordpress.docker_network.wordpress"; +json.values.root_module.child_modules[0].resources[1].mode = "managed"; +json.values.root_module.child_modules[0].resources[1].name = "wordpress"; +json.values.root_module.child_modules[0].resources[1].provider_name = "registry.terraform.io/kreuzwerker/docker"; +json.values.root_module.child_modules[0].resources[1].schema_version = 2; +json.values.root_module.child_modules[0].resources[1].type = "docker_container"; +json.values.root_module.child_modules[0].resources[1].values = {}; +json.values.root_module.child_modules[0].resources[1].values.attach = false; +json.values.root_module.child_modules[0].resources[1].values.bridge = ""; +json.values.root_module.child_modules[0].resources[1].values.capabilities = []; +json.values.root_module.child_modules[0].resources[1].values.command = []; +json.values.root_module.child_modules[0].resources[1].values.command[0] = "apache2-foreground"; +json.values.root_module.child_modules[0].resources[1].values.container_logs = null; +json.values.root_module.child_modules[0].resources[1].values.cpu_set = ""; +json.values.root_module.child_modules[0].resources[1].values.cpu_shares = 0; +json.values.root_module.child_modules[0].resources[1].values.destroy_grace_seconds = null; +json.values.root_module.child_modules[0].resources[1].values.devices = []; +json.values.root_module.child_modules[0].resources[1].values.dns = null; +json.values.root_module.child_modules[0].resources[1].values.dns_opts = null; +json.values.root_module.child_modules[0].resources[1].values.dns_search = null; +json.values.root_module.child_modules[0].resources[1].values.domainname = ""; +json.values.root_module.child_modules[0].resources[1].values.entrypoint = []; +json.values.root_module.child_modules[0].resources[1].values.entrypoint[0] = "docker-entrypoint.sh"; +json.values.root_module.child_modules[0].resources[1].values.env = []; +json.values.root_module.child_modules[0].resources[1].values.env[0] = "WORDPRESS_DB_HOST=db:3306"; +json.values.root_module.child_modules[0].resources[1].values.env[1] = "WORDPRESS_DB_NAME=wordpress"; +json.values.root_module.child_modules[0].resources[1].values.env[2] = "WORDPRESS_DB_PASSWORD=wordpress"; +json.values.root_module.child_modules[0].resources[1].values.env[3] = "WORDPRESS_DB_USER=wordpress"; +json.values.root_module.child_modules[0].resources[1].values.exit_code = null; +json.values.root_module.child_modules[0].resources[1].values.gateway = "172.20.0.1"; +json.values.root_module.child_modules[0].resources[1].values.group_add = null; +json.values.root_module.child_modules[0].resources[1].values.healthcheck = null; +json.values.root_module.child_modules[0].resources[1].values.host = []; +json.values.root_module.child_modules[0].resources[1].values.hostname = "a3ace04e6c60"; +json.values.root_module.child_modules[0].resources[1].values.id = "a3ace04e6c60b0a23421f917d691625e0e58dbdd6afcdd8ec9ab0f0e03b10145"; +json.values.root_module.child_modules[0].resources[1].values.image = "sha256:c01290f258b3507784b95c9c163a56015ca5bd3978877b84c64887df3cfdb6e1"; +json.values.root_module.child_modules[0].resources[1].values.init = false; +json.values.root_module.child_modules[0].resources[1].values.ip_address = "172.20.0.3"; +json.values.root_module.child_modules[0].resources[1].values.ip_prefix_length = 16; +json.values.root_module.child_modules[0].resources[1].values.ipc_mode = "private"; +json.values.root_module.child_modules[0].resources[1].values.labels = []; +json.values.root_module.child_modules[0].resources[1].values.links = null; +json.values.root_module.child_modules[0].resources[1].values.log_driver = "json-file"; +json.values.root_module.child_modules[0].resources[1].values.log_opts = null; +json.values.root_module.child_modules[0].resources[1].values.logs = false; +json.values.root_module.child_modules[0].resources[1].values.max_retry_count = 0; +json.values.root_module.child_modules[0].resources[1].values.memory = 0; +json.values.root_module.child_modules[0].resources[1].values.memory_swap = 0; +json.values.root_module.child_modules[0].resources[1].values.mounts = []; +json.values.root_module.child_modules[0].resources[1].values.must_run = true; +json.values.root_module.child_modules[0].resources[1].values.name = "wordpress"; +json.values.root_module.child_modules[0].resources[1].values.network_alias = null; +json.values.root_module.child_modules[0].resources[1].values.network_data = []; +json.values.root_module.child_modules[0].resources[1].values.network_data[0] = {}; +json.values.root_module.child_modules[0].resources[1].values.network_data[0].gateway = "172.20.0.1"; +json.values.root_module.child_modules[0].resources[1].values.network_data[0].global_ipv6_address = ""; +json.values.root_module.child_modules[0].resources[1].values.network_data[0].global_ipv6_prefix_length = 0; +json.values.root_module.child_modules[0].resources[1].values.network_data[0].ip_address = "172.20.0.3"; +json.values.root_module.child_modules[0].resources[1].values.network_data[0].ip_prefix_length = 16; +json.values.root_module.child_modules[0].resources[1].values.network_data[0].ipv6_gateway = ""; +json.values.root_module.child_modules[0].resources[1].values.network_data[0].network_name = "wordpress_net"; +json.values.root_module.child_modules[0].resources[1].values.network_mode = "default"; +json.values.root_module.child_modules[0].resources[1].values.networks = null; +json.values.root_module.child_modules[0].resources[1].values.networks_advanced = []; +json.values.root_module.child_modules[0].resources[1].values.networks_advanced[0] = {}; +json.values.root_module.child_modules[0].resources[1].values.networks_advanced[0].aliases = []; +json.values.root_module.child_modules[0].resources[1].values.networks_advanced[0].ipv4_address = ""; +json.values.root_module.child_modules[0].resources[1].values.networks_advanced[0].ipv6_address = ""; +json.values.root_module.child_modules[0].resources[1].values.networks_advanced[0].name = "wordpress_net"; +json.values.root_module.child_modules[0].resources[1].values.pid_mode = ""; +json.values.root_module.child_modules[0].resources[1].values.ports = []; +json.values.root_module.child_modules[0].resources[1].values.ports[0] = {}; +json.values.root_module.child_modules[0].resources[1].values.ports[0].external = 8080; +json.values.root_module.child_modules[0].resources[1].values.ports[0].internal = 80; +json.values.root_module.child_modules[0].resources[1].values.ports[0].ip = "0.0.0.0"; +json.values.root_module.child_modules[0].resources[1].values.ports[0].protocol = "tcp"; +json.values.root_module.child_modules[0].resources[1].values.privileged = false; +json.values.root_module.child_modules[0].resources[1].values.publish_all_ports = false; +json.values.root_module.child_modules[0].resources[1].values.read_only = false; +json.values.root_module.child_modules[0].resources[1].values.remove_volumes = true; +json.values.root_module.child_modules[0].resources[1].values.restart = "always"; +json.values.root_module.child_modules[0].resources[1].values.rm = false; +json.values.root_module.child_modules[0].resources[1].values.security_opts = []; +json.values.root_module.child_modules[0].resources[1].values.shm_size = 64; +json.values.root_module.child_modules[0].resources[1].values.start = true; +json.values.root_module.child_modules[0].resources[1].values.stdin_open = false; +json.values.root_module.child_modules[0].resources[1].values.sysctls = null; +json.values.root_module.child_modules[0].resources[1].values.tmpfs = null; +json.values.root_module.child_modules[0].resources[1].values.tty = false; +json.values.root_module.child_modules[0].resources[1].values.ulimit = []; +json.values.root_module.child_modules[0].resources[1].values.upload = []; +json.values.root_module.child_modules[0].resources[1].values.user = ""; +json.values.root_module.child_modules[0].resources[1].values.userns_mode = ""; +json.values.root_module.child_modules[0].resources[1].values.volumes = []; +json.values.root_module.child_modules[0].resources[1].values.working_dir = "/var/www/html"; +json.values.root_module.child_modules[0].resources[2] = {}; +json.values.root_module.child_modules[0].resources[2].address = "module.docker_wordpress.docker_network.wordpress"; +json.values.root_module.child_modules[0].resources[2].mode = "managed"; +json.values.root_module.child_modules[0].resources[2].name = "wordpress"; +json.values.root_module.child_modules[0].resources[2].provider_name = "registry.terraform.io/kreuzwerker/docker"; +json.values.root_module.child_modules[0].resources[2].schema_version = 1; +json.values.root_module.child_modules[0].resources[2].type = "docker_network"; +json.values.root_module.child_modules[0].resources[2].values = {}; +json.values.root_module.child_modules[0].resources[2].values.attachable = false; +json.values.root_module.child_modules[0].resources[2].values.check_duplicate = null; +json.values.root_module.child_modules[0].resources[2].values.driver = "bridge"; +json.values.root_module.child_modules[0].resources[2].values.id = "012f4699aee26f0be16c36a8d31e9be5f74f66615470c39673063570741ff384"; +json.values.root_module.child_modules[0].resources[2].values.ingress = false; +json.values.root_module.child_modules[0].resources[2].values.internal = false; +json.values.root_module.child_modules[0].resources[2].values.ipam_config = []; +json.values.root_module.child_modules[0].resources[2].values.ipam_config[0] = {}; +json.values.root_module.child_modules[0].resources[2].values.ipam_config[0].aux_address = {}; +json.values.root_module.child_modules[0].resources[2].values.ipam_config[0].gateway = "172.20.0.1"; +json.values.root_module.child_modules[0].resources[2].values.ipam_config[0].ip_range = ""; +json.values.root_module.child_modules[0].resources[2].values.ipam_config[0].subnet = "172.20.0.0/16"; +json.values.root_module.child_modules[0].resources[2].values.ipam_driver = "default"; +json.values.root_module.child_modules[0].resources[2].values.ipv6 = false; +json.values.root_module.child_modules[0].resources[2].values.labels = []; +json.values.root_module.child_modules[0].resources[2].values.name = "wordpress_net"; +json.values.root_module.child_modules[0].resources[2].values.options = {}; +json.values.root_module.child_modules[0].resources[2].values.scope = "local"; +json.values.root_module.child_modules[0].resources[3] = {}; +json.values.root_module.child_modules[0].resources[3].address = "module.docker_wordpress.docker_volume.db_data"; +json.values.root_module.child_modules[0].resources[3].mode = "managed"; +json.values.root_module.child_modules[0].resources[3].name = "db_data"; +json.values.root_module.child_modules[0].resources[3].provider_name = "registry.terraform.io/kreuzwerker/docker"; +json.values.root_module.child_modules[0].resources[3].schema_version = 1; +json.values.root_module.child_modules[0].resources[3].type = "docker_volume"; +json.values.root_module.child_modules[0].resources[3].values = {}; +json.values.root_module.child_modules[0].resources[3].values.driver = "local"; +json.values.root_module.child_modules[0].resources[3].values.driver_opts = {}; +json.values.root_module.child_modules[0].resources[3].values.driver_opts.device = "/tt/wordpressdb/"; +json.values.root_module.child_modules[0].resources[3].values.driver_opts.o = "bind"; +json.values.root_module.child_modules[0].resources[3].values.driver_opts.type = "none"; +json.values.root_module.child_modules[0].resources[3].values.id = "db_data"; +json.values.root_module.child_modules[0].resources[3].values.labels = []; +json.values.root_module.child_modules[0].resources[3].values.mountpoint = "/var/lib/docker/volumes/db_data/_data"; +json.values.root_module.child_modules[0].resources[3].values.name = "db_data"; diff --git a/terraform/7/main.tf b/terraform/7/main.tf new file mode 100644 index 0000000..efe9148 --- /dev/null +++ b/terraform/7/main.tf @@ -0,0 +1,26 @@ +#docker remote ssh IP +variable "ssh_host" {} +variable "ssh_user" {} +variable "ssh_key" {} +variable "wordpress_port" {} + +module "docker_wordpress" { + source = "./modules/docker_wordpress" + #ssh_host = var.ssh_host + #ssh_user = var.ssh_user + #ssh_key = var.ssh_key + wordpress_port = var.wordpress_port +} + +output "docker_ip_db" { + value = module.docker_wordpress.docker_ip_db +} +output "docker_ip_wordpress" { + value = module.docker_wordpress.docker_ip_wordpress +} +output "docker_volume" { + value = module.docker_wordpress.docker_volume +} +output "docker_volume_mountpoint" { + value = module.docker_wordpress.docker_volume_mountpoint +} diff --git a/terraform/7/modules/docker_install/main.tf b/terraform/7/modules/docker_install/main.tf new file mode 100644 index 0000000..eaae4cb --- /dev/null +++ b/terraform/7/modules/docker_install/main.tf @@ -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" + ] + } +} diff --git a/terraform/7/modules/docker_install/startup-options.conf b/terraform/7/modules/docker_install/startup-options.conf new file mode 100644 index 0000000..e45bda2 --- /dev/null +++ b/terraform/7/modules/docker_install/startup-options.conf @@ -0,0 +1,3 @@ +[Service] +ExecStart= +ExecStart=/usr/bin/dockerd -H tcp://192.168.21.103:2375 -H unix:///var/run/docker.sock diff --git a/terraform/7/modules/docker_install/variables.tf b/terraform/7/modules/docker_install/variables.tf new file mode 100644 index 0000000..35bfd2a --- /dev/null +++ b/terraform/7/modules/docker_install/variables.tf @@ -0,0 +1,3 @@ +variable "ssh_host" {} +variable "ssh_user" {} +variable "ssh_key" {} diff --git a/terraform/7/modules/docker_run/main.tf b/terraform/7/modules/docker_run/main.tf new file mode 100644 index 0000000..725249e --- /dev/null +++ b/terraform/7/modules/docker_run/main.tf @@ -0,0 +1,15 @@ +provider "docker" { + host = "tcp://${var.ssh_host}:2375" +} + +resource "docker_image" "nginx" { + name = "nginx:latest" +} +resource "docker_container" "nginx" { + image = docker_image.nginx.latest + name = "enginecks" + ports { + internal = 80 + external = 80 + } +} diff --git a/terraform/7/modules/docker_run/variables.tf b/terraform/7/modules/docker_run/variables.tf new file mode 100644 index 0000000..1367ac3 --- /dev/null +++ b/terraform/7/modules/docker_run/variables.tf @@ -0,0 +1 @@ +variable "ssh_host" {} diff --git a/terraform/7/modules/docker_wordpress/main.tf b/terraform/7/modules/docker_wordpress/main.tf new file mode 100644 index 0000000..edde57b --- /dev/null +++ b/terraform/7/modules/docker_wordpress/main.tf @@ -0,0 +1,74 @@ + +# Set the required provider and versions +terraform { + required_providers { + # We recommend pinning to the specific version of the Docker Provider you're using + # since new versions are released frequently + docker = { + source = "kreuzwerker/docker" + version = "2.11.0" + } + } +} + +# Configure the Docker provider +provider "docker" { + host = "unix:///var/run/docker.sock" +} + +# Volume database +resource "docker_volume" "db_data" { + name = "db_data" + driver = "local" + driver_opts = { + o = "bind" + type = "none" + device = "/tt/wordpressdb/" + } +} + +resource "docker_network" "wordpress" { + name = "wordpress_net" +} + +resource "docker_container" "db" { + name = "db" + image = "mysql:5.7" + restart = "always" + network_mode = "wordpress_net" + env = [ + "MYSQL_ROOT_PASSWORD=wordpress", + "MYSQL_PASSWORD=wordpress", + "MYSQL_USER=wordpress", + "MYSQL_DATABASE=wordpress" + ] + networks_advanced { + name = docker_network.wordpress.name + } + volumes { + host_path = "/tt/wordpressdb/" + container_path = "/var/lib/mysql/" + volume_name = "db_data" + } +} + + +# No volume data is used for wordpress +resource "docker_container" "wordpress" { + name = "wordpress" + image = "wordpress:latest" + restart = "always" + networks_advanced { + name = docker_network.wordpress.name + } + env = [ + "WORDPRESS_DB_HOST=db:3306", + "WORDPRESS_DB_USER=wordpress", + "WORDPRESS_DB_PASSWORD=wordpress", + "WORDPRESS_DB_NAME=wordpress" + ] + ports { + internal = 80 + external = var.wordpress_port + } +} diff --git a/terraform/7/modules/docker_wordpress/outputs.tf b/terraform/7/modules/docker_wordpress/outputs.tf new file mode 100644 index 0000000..5278262 --- /dev/null +++ b/terraform/7/modules/docker_wordpress/outputs.tf @@ -0,0 +1,12 @@ +output "docker_ip_db" { + value = docker_container.db.ip_address +} +output "docker_ip_wordpress" { + value = docker_container.wordpress.ip_address +} +output "docker_volume" { + value = docker_volume.db_data.driver_opts.device +} +output "docker_volume_mountpoint" { + value = docker_volume.db_data.mountpoint +} diff --git a/terraform/7/modules/docker_wordpress/variables.tf b/terraform/7/modules/docker_wordpress/variables.tf new file mode 100644 index 0000000..6649752 --- /dev/null +++ b/terraform/7/modules/docker_wordpress/variables.tf @@ -0,0 +1,4 @@ +#variable "ssh_host"{} +#variable "ssh_user"{} +#variable "ssh_key"{} +variable "wordpress_port"{} diff --git a/terraform/7/show.txt b/terraform/7/show.txt new file mode 100644 index 0000000..8a96cee --- /dev/null +++ b/terraform/7/show.txt @@ -0,0 +1,176 @@ + +# module.docker_wordpress.docker_container.db: +resource "docker_container" "db" { + attach = false + command = [ + "mysqld", + ] + cpu_shares = 0 + entrypoint = [ + "docker-entrypoint.sh", + ] + env = [ + "MYSQL_DATABASE=wordpress", + "MYSQL_PASSWORD=wordpress", + "MYSQL_ROOT_PASSWORD=wordpress", + "MYSQL_USER=wordpress", + ] + gateway = "172.20.0.1" + hostname = "54b8f1043628" + id = "54b8f1043628ab73368a2baa18aafddfa8520da78d2bd17f76b578443227ada5" + image = "sha256:87eca374c0ed97f0f0b504174b0d22b0a0add454414c0dbf5ae43870369f6854" + init = false + ip_address = "172.20.0.2" + ip_prefix_length = 16 + ipc_mode = "private" + log_driver = "json-file" + logs = false + max_retry_count = 0 + memory = 0 + memory_swap = 0 + must_run = true + name = "db" + network_data = [ + { + gateway = "172.20.0.1" + global_ipv6_address = "" + global_ipv6_prefix_length = 0 + ip_address = "172.20.0.2" + ip_prefix_length = 16 + ipv6_gateway = "" + network_name = "wordpress_net" + }, + ] + network_mode = "wordpress_net" + privileged = false + publish_all_ports = false + read_only = false + remove_volumes = true + restart = "always" + rm = false + security_opts = [] + shm_size = 64 + start = true + stdin_open = false + tty = false + + networks_advanced { + aliases = [] + name = "wordpress_net" + } + + volumes { + container_path = "/var/lib/mysql/" + host_path = "/tt/wordpressdb/" + volume_name = "db_data" + } +} + +# module.docker_wordpress.docker_container.wordpress: +resource "docker_container" "wordpress" { + attach = false + command = [ + "apache2-foreground", + ] + cpu_shares = 0 + entrypoint = [ + "docker-entrypoint.sh", + ] + env = [ + "WORDPRESS_DB_HOST=db:3306", + "WORDPRESS_DB_NAME=wordpress", + "WORDPRESS_DB_PASSWORD=wordpress", + "WORDPRESS_DB_USER=wordpress", + ] + gateway = "172.20.0.1" + hostname = "a3ace04e6c60" + id = "a3ace04e6c60b0a23421f917d691625e0e58dbdd6afcdd8ec9ab0f0e03b10145" + image = "sha256:c01290f258b3507784b95c9c163a56015ca5bd3978877b84c64887df3cfdb6e1" + init = false + ip_address = "172.20.0.3" + ip_prefix_length = 16 + ipc_mode = "private" + log_driver = "json-file" + logs = false + max_retry_count = 0 + memory = 0 + memory_swap = 0 + must_run = true + name = "wordpress" + network_data = [ + { + gateway = "172.20.0.1" + global_ipv6_address = "" + global_ipv6_prefix_length = 0 + ip_address = "172.20.0.3" + ip_prefix_length = 16 + ipv6_gateway = "" + network_name = "wordpress_net" + }, + ] + network_mode = "default" + privileged = false + publish_all_ports = false + read_only = false + remove_volumes = true + restart = "always" + rm = false + security_opts = [] + shm_size = 64 + start = true + stdin_open = false + tty = false + working_dir = "/var/www/html" + + networks_advanced { + aliases = [] + name = "wordpress_net" + } + + ports { + external = 8080 + internal = 80 + ip = "0.0.0.0" + protocol = "tcp" + } +} + +# module.docker_wordpress.docker_network.wordpress: +resource "docker_network" "wordpress" { + attachable = false + driver = "bridge" + id = "012f4699aee26f0be16c36a8d31e9be5f74f66615470c39673063570741ff384" + ingress = false + internal = false + ipam_driver = "default" + ipv6 = false + name = "wordpress_net" + options = {} + scope = "local" + + ipam_config { + aux_address = {} + gateway = "172.20.0.1" + subnet = "172.20.0.0/16" + } +} + +# module.docker_wordpress.docker_volume.db_data: +resource "docker_volume" "db_data" { + driver = "local" + driver_opts = { + "device" = "/tt/wordpressdb/" + "o" = "bind" + "type" = "none" + } + id = "db_data" + mountpoint = "/var/lib/docker/volumes/db_data/_data" + name = "db_data" +} + + +Outputs: + +docker_ip_db = "172.20.0.2" +docker_ip_wordpress = "172.20.0.3" +docker_volume = "/tt/wordpressdb/" diff --git a/terraform/7/terraform.tfvars b/terraform/7/terraform.tfvars new file mode 100644 index 0000000..8fa5f8c --- /dev/null +++ b/terraform/7/terraform.tfvars @@ -0,0 +1,4 @@ +ssh_host = "192.168.21.103" +ssh_user = "vagrant" +ssh_key = "/home/vagrant/.ssh/id_rsa" +wordpress_port = 8080