Hi all,
Now I am trying to learn terraform and started using it with docker container. I wanted to create a lamp stack. So the requirement is as below
Below is my code for this :
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"]
}
Using the above I am able to create the container but now I am confused how to put a logic to forward the relevant ports to host vm. Again how to assign static IP to the containers?
Now I am trying to learn terraform and started using it with docker container. I wanted to create a lamp stack. So the requirement is as below
Using the above I am able to create the container but now I am confused how to put a logic to forward the relevant ports to host vm.
Again how to assign static IP to the containers?
Is there a way to assign a static ip to a container via terraform? I see I can add extra hosts, but is there a way to set the ip_address attribute?