Skip to content

Commit

Permalink
added multi tier in azure
Browse files Browse the repository at this point in the history
  • Loading branch information
magicalbob committed Jan 30, 2021
1 parent 5f7a900 commit c9e021e
Show file tree
Hide file tree
Showing 20 changed files with 458 additions and 125 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,6 @@ I had to import my azure resource group into terraform:
terraform import azurerm_resource_group.allinonerg /subscriptions/{your-subscription-id}/resourceGroups/NetworkWatcherRG
```

The script `./scripts/build-terraform-allinone-azure.sh` stands up the allinone instance in azure. Multi-tier has not been attempted in azure yet.
The script `./scripts/build-terraform-allinone-azure.sh` stands up the allinone instance in azure.

The script `./scripts/build-terraform-azure.sh` stands up the multi-tier stack.
1 change: 1 addition & 0 deletions puppet/modules/profile/manifests/allinone.pp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@
content => epp('profile/install_dynamics_multi.epp',{
config_file => 'c:\scripts\dynamics_config.xml',
sql_server => $sql_server,
admin_user => $admin_user,
admin_pass => $admin_pass,
fe_server => $fe_server,
be_server => $be_server,
Expand Down
21 changes: 0 additions & 21 deletions scripts/build-terraform-allinone-azure.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
#!/usr/bin/env bash

function createMachine {
# arg 1 = machine name
# arg 2 = prefix
# arg 3 = redis_ip
# arg 4 = redis_pass
echo "Create Machine: ${1}"

aws_id=$(terraform show -json|jq ".values.root_module.resources[]|select(.name|test(\"${1}\"))"|jq .values.id|cut -d\" -f2)

# # Set instance-id of machine in redis
# resp=1
# while [ $resp -ne 0 ]
# do
# echo -e "AUTH ${4}\r\nSET ${2}_${aws_id:1} ${1}\r\n" | nc -w1 ${3} 6379
# resp=$?
# done

echo "Set ${1} instance-id ${aws_id}"
}

# make sure we are in right dir
BASE_PATH=$(dirname $0)
cd ${BASE_PATH}/../terraform-allinone-azure
Expand Down Expand Up @@ -96,4 +76,3 @@ done

# Bring up the cluster
terraform apply --auto-approve
createMachine allinone ${prefix} ${redis_ip} ${redis_pass}
78 changes: 78 additions & 0 deletions scripts/build-terraform-azure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash

# make sure we are in right dir
BASE_PATH=$(dirname $0)
cd ${BASE_PATH}/../terraform-azure

if [ "$OS" == "Windows_NT" ]
then
PROVIDER_EXT=".exe"
PATH=$PATH:/c/tools/ruby27/bin:"/c/Program Files/Oracle/VirtualBox"
else
PROVIDER_EXT=""
fi

# Terraform initialise
terraform init

# Get redis details from puppet hiera
redis_name=$(grep redis_ip ../puppet/hieradata/common.yaml |cut -d: -f2)
redis_ip=$(nslookup -querytype=A ${redis_name} 2> /dev/null | grep ^Address:|tail -n1|cut -d: -f2)
redis_pass=$(grep redis_pass ../puppet/hieradata/common.yaml |cut -d: -f2)

# LOCK loop checking no lock more recent than X minutes ago
LOCKED=1

while [ ${LOCKED} -eq 1 ]
do
resp=1
while [ $resp -ne 0 ]
do
LOCK=$(echo -e "AUTH ${redis_pass}\r\nGET LOCK\r\n" | nc -w1 ${redis_ip} 6379|tail -n1|tr -d "[:cntrl:]")
echo -e "AUTH ${redis_pass}\r\nGET LOCK\r\n" | nc -w1 ${redis_ip} 6379 2>/dev/null
resp=$?
done
if [ "${LOCK}" == '$-1' ]
then
LOCKED=0
else
NOW=$(date +"%s")
let DIFF=$NOW-$LOCK
if [ $DIFF -gt 600 ]
then
LOCKED=0
else
echo "Build is locked by previous build. Last lock was ${DIFF} seconds ago. Waiting for it to finish"
sleep 60
fi
fi
done

LOCK=$(date +"%s")
resp=1
while [ $resp -ne 0 ]
do
echo -e "AUTH ${redis_pass}\r\nSET LOCK ${LOCK}\r\n" | nc -w1 ${redis_ip} 6379
resp=$?
done

# Setup prefix in redis for this build
prefix=$(date +%s)
echo ${prefix} > prefix
echo ${prefix} > ../prefix

../scripts/clear-flags-for-build.sh ${prefix} ${redis_ip} ${redis_pass}

export TF_VAR_admin_user=$(grep admin_username ../puppet/hieradata/account/account.yaml |cut -d: -f2|sed 's/ //g')
export TF_VAR_admin_pass=$(grep admin_password ../puppet/hieradata/account/account.yaml |cut -d: -f2|sed 's/ //g')

LOCK=$(date +"%s")
resp=1
while [ $resp -ne 0 ]
do
echo -e "AUTH ${redis_pass}\r\nSET LOCK ${LOCK}\r\n" | nc -w1 ${redis_ip} 6379
resp=$?
done

# Bring up the cluster
terraform apply --auto-approve
2 changes: 1 addition & 1 deletion scripts/check_redis-allinone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ allinone_ssrs_done=$(echo -e "AUTH ${redis_pass}\r\nGET ${prefix}_allinone_ssrs

echo " Prefix is: ${prefix}."
echo " AD IP is: ${ad_ip}."
echo " Allinone Started: ${allinone_started}."
echo " SQL Ready: ${sql_ready}."
echo " Allinone Started: ${allinone_started}."
echo " Allinone Ready: ${allinone_ready}."
echo " Allinone 365 Start: ${allinone_365_start}."
echo " Allinone 365 Done: ${allinone_365_done}."
Expand Down
31 changes: 26 additions & 5 deletions scripts/test-build-allinone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ display_lock_msg=1
display_msg1=1
display_msg2=1
display_msg3=1
display_msg4=1
display_msg5=1
display_msg6=1
display_msg7=1
Expand Down Expand Up @@ -62,21 +63,39 @@ do
MSG1="SQL Server Not Installed"
fi

allinone_ready=$(echo -e "AUTH ${redis_pass}\r\nGET ${prefix}_allinone_ready\r\n" | nc -w1 ${redis_ip} 6379 2>/dev/null|tail -n1)
if [[ ${allinone_ready} =~ 'true' ]]
allinone_started=$(echo -e "AUTH ${redis_pass}\r\nGET ${prefix}_allinone_started\r\n" | nc -w1 ${redis_ip} 6379 2>/dev/null|tail -n1)
if [[ ${allinone_started} =~ 'true' ]]
then
MSG3="Dynamics AllInOne Installed at $(date)"
MSG3="Dynamics AllInOne Started Install at $(date)"
if [ ${display_msg3} -eq 1 ]
then
echo ${MSG3}
display_msg3=0
fi
else
MSG3="Dynamics AllInOne Not Installed"
MSG3="Dynamics AllInOne Not Started"
fi
if [[ ${allinone_started} =~ 'error' ]]
then
MSG3="Dynamics AllInOne Install Failed at $(date)"
failed='true'
fi

allinone_ready=$(echo -e "AUTH ${redis_pass}\r\nGET ${prefix}_allinone_ready\r\n" | nc -w1 ${redis_ip} 6379 2>/dev/null|tail -n1)
if [[ ${allinone_ready} =~ 'true' ]]
then
MSG4="Dynamics AllInOne Installed at $(date)"
if [ ${display_msg4} -eq 1 ]
then
echo ${MSG4}
display_msg4=0
fi
else
MSG4="Dynamics AllInOne Not Installed"
fi
if [[ ${allinone_ready} =~ 'error' ]]
then
MSG3="Dynamics AllInOne Failed at $(date)"
MSG4="Dynamics AllInOne Failed at $(date)"
failed='true'
fi

Expand Down Expand Up @@ -140,6 +159,7 @@ do
echo ${MSG1}
echo ${MSG2}
echo ${MSG3}
echo ${MSG4}
echo ${MSG5}
echo ${MSG6}
echo ${MSG7}
Expand All @@ -153,6 +173,7 @@ do
echo ${MSG1}
echo ${MSG2}
echo ${MSG3}
echo ${MSG4}
echo ${MSG5}
echo ${MSG6}
echo ${MSG7}
Expand Down
96 changes: 45 additions & 51 deletions scripts/test-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ redis_name=$(grep redis_ip puppet/hieradata/common.yaml |cut -d: -f2)
redis_ip=$(nslookup -querytype=A ${redis_name} 2> /dev/null | grep ^Address:|tail -n1|cut -d: -f2)
redis_pass=$(grep redis_pass puppet/hieradata/common.yaml |cut -d: -f2)

virtualenv .py > /dev/null 2>&1

. .py/bin/activate > /dev/null 2>&1

pip install pywinrm > /dev/null 2>&1

export admin_password=$(grep admin_password ./puppet/hieradata/account/account.yaml |cut -d: -f2|sed 's/ //g')

# read prefix for redis keys for this build
Expand Down Expand Up @@ -80,51 +74,51 @@ do
done
fi

ad_machines=$($(dirname $0)/check_winrm.py)
if [[ "$ad_machines" =~ "DYNADIR," ]]
then
if [ ${display_msgAD} -eq 1 ]
then
echo "Domain set up on DYNADIR at $(date)"
display_msgAD=0
fi
fi

if [[ "$ad_machines" =~ "DYNSQL," ]]
then
if [ ${display_msgSQL} -eq 1 ]
then
echo "Domain joined by DYNSQL at $(date)"
display_msgSQL=0
fi
fi

if [[ "$ad_machines" =~ "DYNFE," ]]
then
if [ ${display_msgFE} -eq 1 ]
then
echo "Domain joined by DYNFE at $(date)"
display_msgFE=0
fi
fi

if [[ "$ad_machines" =~ "DYNBE," ]]
then
if [ ${display_msgBE} -eq 1 ]
then
echo "Domain joined by DYNBE at $(date)"
display_msgBE=0
fi
fi

if [[ "$ad_machines" =~ "DYNADM," ]]
then
if [ ${display_msgADM} -eq 1 ]
then
echo "Domain joined by DYNADM at $(date)"
display_msgADM=0
fi
fi
# ad_machines=$($(dirname $0)/check_winrm.py)
# if [[ "$ad_machines" =~ "DYNADIR," ]]
# then
# if [ ${display_msgAD} -eq 1 ]
# then
# echo "Domain set up on DYNADIR at $(date)"
# display_msgAD=0
# fi
# fi
#
# if [[ "$ad_machines" =~ "DYNSQL," ]]
# then
# if [ ${display_msgSQL} -eq 1 ]
# then
# echo "Domain joined by DYNSQL at $(date)"
# display_msgSQL=0
# fi
# fi
#
# if [[ "$ad_machines" =~ "DYNFE," ]]
# then
# if [ ${display_msgFE} -eq 1 ]
# then
# echo "Domain joined by DYNFE at $(date)"
# display_msgFE=0
# fi
# fi
#
# if [[ "$ad_machines" =~ "DYNBE," ]]
# then
# if [ ${display_msgBE} -eq 1 ]
# then
# echo "Domain joined by DYNBE at $(date)"
# display_msgBE=0
# fi
# fi
#
# if [[ "$ad_machines" =~ "DYNADM," ]]
# then
# if [ ${display_msgADM} -eq 1 ]
# then
# echo "Domain joined by DYNADM at $(date)"
# display_msgADM=0
# fi
# fi

sql_ready=$(echo -e "AUTH ${redis_pass}\r\nGET ${prefix}_sql_ready\r\n" | nc -w1 ${redis_ip} 6379 2>/dev/null|tail -n1)
if [[ ${sql_ready} =~ 'true' ]]
Expand Down
53 changes: 7 additions & 46 deletions terraform-allinone-azure/allinone.tf
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
resource "azurerm_resource_group" "allinonerg" {
name = "NetworkWatcherRG"
location = "UK South"
}

//data "azurerm_image" "allinone" {
// name = "dynamics"
// resource_group_name = "allinonerg"
//}

resource "azurerm_virtual_network" "allinonenet" {
name = "allinone-network"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.allinonerg.location
resource_group_name = azurerm_resource_group.allinonerg.name
}

resource "azurerm_subnet" "allinonesubnet" {
name = "internal"
resource_group_name = azurerm_resource_group.allinonerg.name
virtual_network_name = azurerm_virtual_network.allinonenet.name
address_prefixes = ["10.0.2.0/24"]
resource "azurerm_public_ip" "allinone" {
name = "allinone"
location = azurerm_resource_group.allinonerg.location
resource_group_name = azurerm_resource_group.allinonerg.name
allocation_method = "Dynamic"
idle_timeout_in_minutes = 30
}

resource "azurerm_network_interface" "allinonenetwork" {
Expand All @@ -31,17 +15,10 @@ resource "azurerm_network_interface" "allinonenetwork" {
name = "internal"
subnet_id = azurerm_subnet.allinonesubnet.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = azurerm_public_ip.allinone.id
}
}

resource "azurerm_public_ip" "allinone" {
name = "allinone"
location = azurerm_resource_group.allinonerg.location
resource_group_name = azurerm_resource_group.allinonerg.name
allocation_method = "Dynamic"
idle_timeout_in_minutes = 30
}

resource "azurerm_windows_virtual_machine" "allinone" {
name = "allinone"
location = azurerm_resource_group.allinonerg.location
Expand All @@ -58,26 +35,10 @@ resource "azurerm_windows_virtual_machine" "allinone" {
admin_username = "${var.admin_user}"
admin_password = "${var.admin_pass}"

//source_image_id = data.azurerm_image.allinone.id
source_image_id = "/subscriptions/${var.subscription_id}/resourceGroups/NetworkWatcherRG/providers/Microsoft.Compute/images/dynamics"

additional_unattend_content {
//pass = "oobeSystem"
//component = "Microsoft-Windows-Shell-Setup"
setting = "AutoLogon"
content = "<AutoLogon><Password><Value>${var.admin_pass}</Value></Password><Enabled>true</Enabled><Username>${var.admin_user}</Username></AutoLogon>"
}
}

//data "azurerm_public_ip" "allinone-pip" {
//// name = azurerm_public_ip.allinonerg.name
//// resource_group_name = azurerm_windows_virtual_machine.allinone.resource_group_name
//// resource_group_name = "allinonerg"
// name = "allinone-pip"
// resource_group_name = azurerm_resource_group.allinonerg.name
// allocation_method = "Dynamic"
//}

//output "public_ip_address" {
// value = data.azurerm_public_ip.allinone-pip.ip_address
//}
Loading

0 comments on commit c9e021e

Please sign in to comment.