-
-
Save nikhilv/74a107af7e44866e3f14 to your computer and use it in GitHub Desktop.
terraform scripts to spin up a wildfly domain controller, 2 wildfly host controller and a security group via AWS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
access_key = "YOUR_KEY_HERE" | |
secret_key = "YOUR_KEY_HERE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "access_key" {} | |
variable "secret_key" {} | |
variable "region" { | |
default = "us-east-1" | |
} | |
variable "wildfly-version" { | |
default = "9.0.1.Final" | |
} | |
variable "url" { | |
default = "https://download.jboss.org/wildfly/9.0.1.Final/wildfly-9.0.1.Final.zip" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "aws" { | |
access_key = "${var.access_key}" | |
secret_key = "${var.secret_key}" | |
region = "us-east-1" | |
} | |
resource "aws_instance" "domain" { | |
ami = "ami-01065968" | |
instance_type = "m3.large" | |
key_name = "${var.key_name}" | |
security_groups = [ "${aws_security_group.wildflyCluster.name}"] | |
tags { | |
Name = "${var.name}-wildfly-domain" | |
} | |
connection { | |
user = "ubuntu" | |
type = "ssh" | |
key_file = "${var.key_path}" | |
timeout = "2m" | |
} | |
provisioner "remote-exec" { | |
inline = [ | |
"export PATH=$PATH:/usr/bin:/opt/electriccloud/electriccommander/jre/bin", | |
"sudo apt-get install wget unzip -y", | |
"wget ${var.url}", | |
"unzip wildfly-${var.wildfly-version}.zip -d wildfly-${var.wildfly-version}", | |
"sudo mv wildfly-${var.wildfly-version}/wildfly-${var.wildfly-version}/ /usr/local/share/", | |
"export JAVA_HOME=/opt/electriccloud/electriccommander/jre", | |
"/usr/local/share/wildfly-${var.wildfly-version}/bin/add-user.sh --silent=true --user app1 --password password1!", | |
"/usr/local/share/wildfly-${var.wildfly-version}/bin/add-user.sh --silent=true --user host1 --password password1!", | |
"/usr/local/share/wildfly-${var.wildfly-version}/bin/add-user.sh --silent=true --user host2 --password password1!", | |
"export LAUNCH_JBOSS_IN_BACKGROUND=1", | |
"nohup /usr/local/share/wildfly-${var.wildfly-version}/bin/domain.sh --host-config=host-master.xml -b 0.0.0.0 -bmanagement 0.0.0.0 > output.log 2>&1 &", | |
"sleep 5" | |
] | |
} | |
} | |
resource "aws_instance" "host1" { | |
ami = "ami-01065968" | |
instance_type = "m3.large" | |
key_name = "${var.key_name}" | |
security_groups = [ "${aws_security_group.wildflyCluster.name}"] | |
tags { | |
Name = "${var.name}-wildfly-host1" | |
} | |
connection { | |
user = "ubuntu" | |
type = "ssh" | |
key_file = "${var.key_path}" | |
timeout = "2m" | |
} | |
provisioner "remote-exec" { | |
inline = [ | |
"export PATH=$PATH:/usr/bin:/opt/electriccloud/electriccommander/jre/bin", | |
# | |
"sudo apt-get install wget unzip -y", | |
"wget ${var.url}", | |
"unzip wildfly-${var.wildfly-version}.zip -d wildfly-${var.wildfly-version}", | |
"sudo mv wildfly-${var.wildfly-version}/wildfly-${var.wildfly-version}/ /usr/local/share/", | |
"export JAVA_HOME=/opt/electriccloud/electriccommander/jre", | |
"export LAUNCH_JBOSS_IN_BACKGROUND=1", | |
"sed -i 's/<host/<host name=\"host1\"/' /usr/local/share/wildfly-${var.wildfly-version}/domain/configuration/host-slave.xml", | |
"sed -i 's/c2xhdmVfdXNlcl9wYXNzd29yZA==/cGFzc3dvcmQxIQ==/' /usr/local/share/wildfly-${var.wildfly-version}/domain/configuration/host-slave.xml", | |
"nohup /usr/local/share/wildfly-${var.wildfly-version}/bin/domain.sh --host-config=host-slave.xml --master-address=${aws_instance.domain.public_ip} -Djboss.bind.address=0.0.0.0 2>&1 &", | |
"sleep 5" | |
] | |
} | |
} | |
resource "aws_instance" "host2" { | |
ami = "ami-01065968" | |
instance_type = "m3.large" | |
key_name = "${var.key_name}" | |
security_groups = [ "${aws_security_group.wildflyCluster.name}"] | |
tags { | |
Name = "${var.name}-wildfly-host2" | |
} | |
connection { | |
user = "ubuntu" | |
type = "ssh" | |
key_file = "${var.key_path}" | |
timeout = "2m" | |
} | |
provisioner "remote-exec" { | |
inline = [ | |
"export PATH=$PATH:/usr/bin:/opt/electriccloud/electriccommander/jre/bin", | |
# | |
"sudo apt-get install wget unzip -y", | |
"wget ${var.url}", | |
"unzip wildfly-${var.wildfly-version}.zip -d wildfly-${var.wildfly-version}", | |
"sudo mv wildfly-${var.wildfly-version}/wildfly-${var.wildfly-version}/ /usr/local/share/", | |
"export JAVA_HOME=/opt/electriccloud/electriccommander/jre", | |
"export LAUNCH_JBOSS_IN_BACKGROUND=1", | |
"sed -i 's/<host/<host name=\"host2\"/' /usr/local/share/wildfly-${var.wildfly-version}/domain/configuration/host-slave.xml", | |
"sed -i 's/c2xhdmVfdXNlcl9wYXNzd29yZA==/cGFzc3dvcmQxIQ==/' /usr/local/share/wildfly-${var.wildfly-version}/domain/configuration/host-slave.xml", | |
"nohup /usr/local/share/jboss-eap-6.2/bin/domain.sh --host-config=host-slave.xml --master-address=${aws_instance.domain.public_ip} -Djboss.bind.address=0.0.0.0 2>&1 &", | |
"sleep 5" | |
] | |
} | |
} | |
// The AWS Security group that these instances use | |
resource "aws_security_group" "wildflyCluster" { | |
name = "${var.name}-wildfly-cluster" | |
description = "For ${var.name}'s wildfly cluster" | |
// Admin port | |
ingress { | |
from_port = 9999 | |
to_port = 9999 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
// Management console | |
ingress { | |
from_port = 9990 | |
to_port = 9990 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
// server-one is served on port 8080 | |
ingress { | |
from_port = 8080 | |
to_port = 8080 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
// server-two is served on port 8230 | |
ingress { | |
from_port = 8230 | |
to_port = 8230 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
// commander agent | |
ingress { | |
from_port = 7800 | |
to_port = 7800 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
// commander agent | |
ingress { | |
from_port = 22 | |
to_port = 22 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
} | |
// Variables, these must be specified at run time or a prompt will appear | |
variable "name" { | |
description = "What is your name? (Used to identify instances in AWS)" | |
} | |
variable "key_name" { | |
description = "SSH key name in your AWS account for AWS instances." | |
} | |
variable "key_path" { | |
description = "Path to the private key specified by key_name." | |
} | |
// Output Variables, these appear after all the instances have been spun up and configured | |
output "domain.controller.ip" { | |
value = "${aws_instance.domain.public_ip}" | |
} | |
output "host1.controller.ip" { | |
value = "${aws_instance.host1.public_ip}" | |
} | |
output "host2.controller.ip" { | |
value = "${aws_instance.host2.public_ip}" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment