90DaysOfDevOps/2022/ja/Days/IaC/Docker-Wordpress/docker-wordpress.tf

57 lines
1.0 KiB
Terraform
Raw Normal View History

2022-10-23 23:38:19 +07:00
terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "2.16.0"
}
}
}
provider "docker" {}
variable wordpress_port {
default = "8080"
}
resource "docker_volume" "db_data" {
name = "db_data"
}
resource "docker_network" "wordpress_net" {
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"
]
mounts {
type = "volume"
target = "/var/lib/mysql"
source = "db_data"
}
}
resource "docker_container" "wordpress" {
name = "wordpress"
image = "wordpress:latest"
restart = "always"
network_mode = "wordpress_net"
env = [
"WORDPRESS_DB_HOST=db:3306",
"WORDPRESS_DB_USER=wordpress",
"WORDPRESS_DB_NAME=wordpress",
"WORDPRESS_DB_PASSWORD=wordpress"
]
ports {
internal = "80"
external = "${var.wordpress_port}"
}
}