现在我正在尝试学习Terraform并开始在docker容器中使用它。我想制作一个灯堆。所以要求如下
以下是此要求的代码:
vi main.tf
module "db_server_vm" {
source = "./module"
server_name = "db-server"
servers = "1"
}
module "app_server_vm" {
source = "./module"
server_name = "app-server"
servers = "1"
}
module "proxy_server_vm" {
source = "./module"
server_name = "proxy-server"
servers = "1"
}
模块文件如下:
vi module/docker_container.tf
variable "container_image" {
type = "string"
default = "containers.dev.int/redhat:6.7_latest"
}
resource "docker_container" "container" {
image = "${var.container_image}"
name = "${var.server_name}-${count.index}"
hostname = "${var.server_name}"
domainname = "example.int"
count = "${var.servers}"
must_run = true
restart = "always"
privileged = true
env = ["env=test", "role=test"]
command = ["/usr/sbin/sshd", "-D", "-o", "UseDNS=no", "-o", "PasswordAuthentication=yes", "-o", "UsePrivilegeSeparation=no", "-o", "UsePAM=no", "-o", "PidFile=/tmp/sshd.pid"]
}
使用上面我能够创建容器,但现在我很困惑如何将逻辑转发给主机vm的相关端口。再次如何为容器分配静态IP?因为我要求IP使用应用程序配置数据库,使用应用程序配置代理