provider/azurerm: Example of Wordpress MySql Replication (#15260)
* initial commit - 101-vm-from-user-image * changed branch name * not deploying - storage problems * provisions vm but image not properly prepared * storage not correct * provisions properly * changed main.tf to azuredeploy.tf * added tfvars and info for README * tfvars ignored and corrected file ext * added CI config; added sane defaults for variables; updated deployment script, added mac specific deployment for local testing * deploy.sh to be executable * executable deploy files * added CI files; changed vars * prep for PR * removal of old folder * prep for PR * wrong args for travis * more PR prep * updated README * commented out variables in terraform.tfvars * Topic 101 vm from user image (#2) * initial commit - 101-vm-from-user-image * added tfvars and info for README * added CI config; added sane defaults for variables; updated deployment script, added mac specific deployment for local testing * prep for PR * added new template * oops, left off master * prep for PR * correct repository for destination * renamed scripts to be more intuitive; added check for docker * merge vm simple; vm from image * initial commit * deploys locally * updated deploy * consolidated deploy and after_deploy into a single script; simplified ci process; added os_profile_linux_config * added terraform show * changed to allow http & https (like ARM tmplt) * changed host_name & host_name variable desc * added az cli check * on this branch, only build test_dir; master will aggregate all the examples * merge master * added new constructs/naming for deploy scripts, etc. * suppress az login output * suppress az login output * forgot about line breaks * breaking build as an example * fixing broken build example * merge of CI config * fixed grammar in readme * prep for PR * took out armviz button and minor README changes * changed host_name * fixed merge conflicts * changed host_name variable * updating Hashicorp's changes to merged simple linux branch * updating files to merge w/master and prep for Hashicorp pr * Revert "updating files to merge w/master and prep for Hashicorp pr" This reverts commit b850cd5d2a858eff073fc5a1097a6813d0f8b362. * Revert "updating Hashicorp's changes to merged simple linux branch" This reverts commit dbaf8d14a9cdfcef0281919671357f6171ebd4e6. * removing vm from user image example from this branch * removed old branch * azure-2-vms-loadbalancer-lbrules (#13) * initial commit * need to change lb_rule & nic * deploys locally * updated README * updated travis and deploy scripts for Hari's repo * renamed deploy script * clean up * prep for PR * updated readme * fixing conflict in .travis.yml * initial commit; in progress * in progress * in progress; encryption fails * in progress * deploys successfully locally * clean up; deploy typo fixed * merging hashi master into this branch * troubleshooting deploy * added missing vars to deploy script * updated README, outputs, and added graph * simplified outputs * provisions locally * cleaned up vars * fixed chart on README * prepping for pr * fixed merge conflict * initial commit * provisions locally; but azuremysql.sh script fails * commented out provider * commenting out provider vars * tf fmt / uncommented Ext - will fail * testing other examples * changed os version for script compatability; changed command * removed ssh from output (no nsg) * changed travis to test only this topic's dir * added nsg * testing encrypt-running-linux * fixed IPs and validation * cleanup merge conflicts * updated validation cmd; reverted non-topic ci changes * reverting to Hashicorp's .travis.yml * removing return line * returned return lines to travis.yml * return lines * return lines * travis
This commit is contained in:
parent
62acef9611
commit
87be64b1ac
|
@ -0,0 +1,41 @@
|
||||||
|
# Deploys a WordPress web site backed by MySQL master-slave replication
|
||||||
|
|
||||||
|
This Terraform template was based on [this](https://github.com/Azure/azure-quickstart-templates/tree/master/wordpress-mysql-replication) Azure Quickstart Template. Changes to the ARM template that may have occurred since the creation of this example may not be reflected here.
|
||||||
|
|
||||||
|
This template deploys a WordPress site in Azure backed by MySQL replication with one master and one slave server. It has the following capabilities:
|
||||||
|
|
||||||
|
- Installs and configures GTID based MySQL replication on CentOS 6
|
||||||
|
- Deploys a load balancer in front of the 2 MySQL VMs
|
||||||
|
- MySQL, SSH, and MySQL probe ports are exposed through the load balancer using Network Security Group rules.
|
||||||
|
- WordPress accesses MySQL through the load balancer.
|
||||||
|
- Configures an http based health probe for each MySQL instance that can be used to monitor MySQL health.
|
||||||
|
- WordPress deployment starts immediately after MySQL deployment finishes.
|
||||||
|
- Details about MySQL management, including failover, can be found [here](https://github.com/Azure/azure-quickstart-templates/tree/master/mysql-replication).
|
||||||
|
|
||||||
|
If you would like to leverage an existing VNET, then please see the [documentation here](https://www.terraform.io/docs/import/index.html) to learn about importing existing resources into Terraform and bringing them under state management by this template. To import your existing VNET, you may use this command.
|
||||||
|
|
||||||
|
```
|
||||||
|
terraform import azurerm_virtual_network.testNetwork /subscriptions/<YOUR-SUB-ID-HERE>/resourceGroups/<existing-resource-group-name>/providers/Microsoft.Network/virtualNetworks/<existing-vnet-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
## main.tf
|
||||||
|
The `main.tf` file contains the resources necessary for the MySql replication deployment that will be created. It also contains the Azure Resource Group definition and any defined variables.
|
||||||
|
|
||||||
|
## website.tf
|
||||||
|
The `website.tf` contains an `azurerm_template_deployment` that will deploy the Wordpress website.
|
||||||
|
|
||||||
|
## outputs.tf
|
||||||
|
This data is outputted when `terraform apply` is called, and can be queried using the `terraform output` command.
|
||||||
|
|
||||||
|
## provider.tf
|
||||||
|
You may leave the provider block in the `main.tf`, as it is in this template, or you can create a file called `provider.tf` and add it to your `.gitignore` file.
|
||||||
|
|
||||||
|
Azure requires that an application is added to Azure Active Directory to generate the `client_id`, `client_secret`, and `tenant_id` needed by Terraform (`subscription_id` can be recovered from your Azure account details). Please go [here](https://www.terraform.io/docs/providers/azurerm/) for full instructions on how to create this to populate your `provider.tf` file.
|
||||||
|
|
||||||
|
## terraform.tfvars
|
||||||
|
If a `terraform.tfvars` file is present in the current directory, Terraform automatically loads it to populate variables. We don't recommend saving usernames and password to version control, but you can create a local secret variables file and use `-var-file` to load it.
|
||||||
|
|
||||||
|
If you are committing this template to source control, please insure that you add this file to your `.gitignore` file.
|
||||||
|
|
||||||
|
## variables.tf
|
||||||
|
The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template.
|
|
@ -0,0 +1,56 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -o errexit -o nounset
|
||||||
|
|
||||||
|
docker run --rm -it \
|
||||||
|
-e ARM_CLIENT_ID \
|
||||||
|
-e ARM_CLIENT_SECRET \
|
||||||
|
-e ARM_SUBSCRIPTION_ID \
|
||||||
|
-e ARM_TENANT_ID \
|
||||||
|
-v $(pwd):/data \
|
||||||
|
--workdir=/data \
|
||||||
|
--entrypoint "/bin/sh" \
|
||||||
|
hashicorp/terraform:light \
|
||||||
|
-c "/bin/terraform get; \
|
||||||
|
/bin/terraform validate; \
|
||||||
|
/bin/terraform plan -out=out.tfplan \
|
||||||
|
-var resource_group=$KEY \
|
||||||
|
-var unique_prefix=$KEY \
|
||||||
|
-var site_name=$KEY \
|
||||||
|
-var dns_name=$KEY \
|
||||||
|
-var hosting_plan_name=$KEY \
|
||||||
|
-var mysql_root_password=$PASSWORD \
|
||||||
|
-var mysql_replication_password=$PASSWORD \
|
||||||
|
-var mysql_probe_password=$PASSWORD \
|
||||||
|
-var vm_admin_username=$KEY \
|
||||||
|
-var vm_admin_password=$PASSWORD; \
|
||||||
|
/bin/terraform apply out.tfplan"
|
||||||
|
|
||||||
|
# cleanup deployed azure resources via azure-cli
|
||||||
|
docker run --rm -it \
|
||||||
|
azuresdk/azure-cli-python \
|
||||||
|
sh -c "az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID > /dev/null; \
|
||||||
|
az vm list -g $KEY; \
|
||||||
|
az webapp show -n $KEY -g $KEY"
|
||||||
|
|
||||||
|
# cleanup deployed azure resources via terraform
|
||||||
|
docker run --rm -it \
|
||||||
|
-e ARM_CLIENT_ID \
|
||||||
|
-e ARM_CLIENT_SECRET \
|
||||||
|
-e ARM_SUBSCRIPTION_ID \
|
||||||
|
-e ARM_TENANT_ID \
|
||||||
|
-v $(pwd):/data \
|
||||||
|
--workdir=/data \
|
||||||
|
--entrypoint "/bin/sh" \
|
||||||
|
hashicorp/terraform:light \
|
||||||
|
-c "/bin/terraform destroy -force \
|
||||||
|
-var resource_group=$KEY \
|
||||||
|
-var unique_prefix=$KEY \
|
||||||
|
-var site_name=$KEY \
|
||||||
|
-var dns_name=$KEY \
|
||||||
|
-var hosting_plan_name=$KEY \
|
||||||
|
-var mysql_root_password=$PASSWORD \
|
||||||
|
-var mysql_replication_password=$PASSWORD \
|
||||||
|
-var mysql_probe_password=$PASSWORD \
|
||||||
|
-var vm_admin_username=$KEY \
|
||||||
|
-var vm_admin_password=$PASSWORD;"
|
|
@ -0,0 +1,15 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -o errexit -o nounset
|
||||||
|
|
||||||
|
if docker -v; then
|
||||||
|
|
||||||
|
# generate a unique string for CI deployment
|
||||||
|
export KEY=$(cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-z' | head -c 12)
|
||||||
|
export PASSWORD=$KEY$(cat /dev/urandom | env LC_CTYPE=C tr -cd 'A-Z' | head -c 2)$(cat /dev/urandom | env LC_CTYPE=C tr -cd '0-9' | head -c 2)
|
||||||
|
|
||||||
|
/bin/sh ./deploy.ci.sh
|
||||||
|
|
||||||
|
else
|
||||||
|
echo "Docker is used to run terraform commands, please install before run: https://docs.docker.com/docker-for-mac/install/"
|
||||||
|
fi
|
|
@ -0,0 +1,244 @@
|
||||||
|
# provider "azurerm" {
|
||||||
|
# subscription_id = "${var.subscription_id}"
|
||||||
|
# client_id = "${var.client_id}"
|
||||||
|
# client_secret = "${var.client_secret}"
|
||||||
|
# tenant_id = "${var.tenant_id}"
|
||||||
|
# }
|
||||||
|
|
||||||
|
# ********************** MYSQL REPLICATION ********************** #
|
||||||
|
|
||||||
|
resource "azurerm_resource_group" "rg" {
|
||||||
|
name = "${var.resource_group}"
|
||||||
|
location = "${var.location}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ********************** VNET / SUBNET ********************** #
|
||||||
|
resource "azurerm_virtual_network" "vnet" {
|
||||||
|
name = "${var.virtual_network_name}"
|
||||||
|
resource_group_name = "${azurerm_resource_group.rg.name}"
|
||||||
|
location = "${azurerm_resource_group.rg.location}"
|
||||||
|
address_space = ["${var.vnet_address_prefix}"]
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_subnet" "db_subnet" {
|
||||||
|
name = "${var.db_subnet_name}"
|
||||||
|
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
|
||||||
|
resource_group_name = "${azurerm_resource_group.rg.name}"
|
||||||
|
network_security_group_id = "${azurerm_network_security_group.nsg.id}"
|
||||||
|
address_prefix = "${var.db_subnet_address_prefix}"
|
||||||
|
depends_on = ["azurerm_virtual_network.vnet"]
|
||||||
|
}
|
||||||
|
|
||||||
|
# ********************** STORAGE ACCOUNTS ********************** #
|
||||||
|
resource "azurerm_storage_account" "stor" {
|
||||||
|
name = "${var.unique_prefix}${var.storage_account_name}"
|
||||||
|
resource_group_name = "${azurerm_resource_group.rg.name}"
|
||||||
|
location = "${azurerm_resource_group.rg.location}"
|
||||||
|
account_type = "${var.storage_account_type}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ********************** NETWORK SECURITY GROUP ********************** #
|
||||||
|
resource "azurerm_network_security_group" "nsg" {
|
||||||
|
name = "${var.unique_prefix}-nsg"
|
||||||
|
resource_group_name = "${azurerm_resource_group.rg.name}"
|
||||||
|
location = "${azurerm_resource_group.rg.location}"
|
||||||
|
|
||||||
|
security_rule {
|
||||||
|
name = "allow-ssh"
|
||||||
|
description = "Allow SSH"
|
||||||
|
priority = 100
|
||||||
|
direction = "Inbound"
|
||||||
|
access = "Allow"
|
||||||
|
protocol = "Tcp"
|
||||||
|
source_port_range = "*"
|
||||||
|
destination_port_range = "22"
|
||||||
|
source_address_prefix = "Internet"
|
||||||
|
destination_address_prefix = "*"
|
||||||
|
}
|
||||||
|
|
||||||
|
security_rule {
|
||||||
|
name = "MySQL"
|
||||||
|
description = "MySQL"
|
||||||
|
priority = 110
|
||||||
|
direction = "Inbound"
|
||||||
|
access = "Allow"
|
||||||
|
protocol = "Tcp"
|
||||||
|
source_port_range = "*"
|
||||||
|
destination_port_range = "3306"
|
||||||
|
source_address_prefix = "*"
|
||||||
|
destination_address_prefix = "*"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# ********************** PUBLIC IP ADDRESSES ********************** #
|
||||||
|
resource "azurerm_public_ip" "pip" {
|
||||||
|
name = "${var.public_ip_name}"
|
||||||
|
location = "${azurerm_resource_group.rg.location}"
|
||||||
|
resource_group_name = "${azurerm_resource_group.rg.name}"
|
||||||
|
public_ip_address_allocation = "Static"
|
||||||
|
domain_name_label = "${var.dns_name}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ********************** AVAILABILITY SET ********************** #
|
||||||
|
resource "azurerm_availability_set" "availability_set" {
|
||||||
|
name = "${var.dns_name}-set"
|
||||||
|
location = "${azurerm_resource_group.rg.location}"
|
||||||
|
resource_group_name = "${azurerm_resource_group.rg.name}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ********************** NETWORK INTERFACES ********************** #
|
||||||
|
resource "azurerm_network_interface" "nic" {
|
||||||
|
name = "${var.nic_name}${count.index}"
|
||||||
|
location = "${azurerm_resource_group.rg.location}"
|
||||||
|
resource_group_name = "${azurerm_resource_group.rg.name}"
|
||||||
|
network_security_group_id = "${azurerm_network_security_group.nsg.id}"
|
||||||
|
count = "${var.node_count}"
|
||||||
|
depends_on = ["azurerm_virtual_network.vnet", "azurerm_public_ip.pip", "azurerm_lb.lb"]
|
||||||
|
|
||||||
|
ip_configuration {
|
||||||
|
name = "ipconfig${count.index}"
|
||||||
|
subnet_id = "${azurerm_subnet.db_subnet.id}"
|
||||||
|
private_ip_address_allocation = "Static"
|
||||||
|
private_ip_address = "10.0.1.${count.index + 4}"
|
||||||
|
load_balancer_backend_address_pools_ids = ["${azurerm_lb_backend_address_pool.backend_pool.id}"]
|
||||||
|
|
||||||
|
load_balancer_inbound_nat_rules_ids = [
|
||||||
|
"${element(azurerm_lb_nat_rule.NatRule0.*.id, count.index)}",
|
||||||
|
"${element(azurerm_lb_nat_rule.MySQLNatRule0.*.id, count.index)}",
|
||||||
|
"${element(azurerm_lb_nat_rule.ProbeNatRule0.*.id, count.index)}",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# ********************** LOAD BALANCER ********************** #
|
||||||
|
resource "azurerm_lb" "lb" {
|
||||||
|
name = "${var.dns_name}-lb"
|
||||||
|
location = "${azurerm_resource_group.rg.location}"
|
||||||
|
resource_group_name = "${azurerm_resource_group.rg.name}"
|
||||||
|
depends_on = ["azurerm_public_ip.pip"]
|
||||||
|
|
||||||
|
frontend_ip_configuration {
|
||||||
|
name = "${var.dns_name}-sshIPCfg"
|
||||||
|
public_ip_address_id = "${azurerm_public_ip.pip.id}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_lb_backend_address_pool" "backend_pool" {
|
||||||
|
resource_group_name = "${azurerm_resource_group.rg.name}"
|
||||||
|
loadbalancer_id = "${azurerm_lb.lb.id}"
|
||||||
|
name = "${var.dns_name}-ilbBackendPool"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ********************** LOAD BALANCER INBOUND NAT RULES ********************** #
|
||||||
|
resource "azurerm_lb_nat_rule" "NatRule0" {
|
||||||
|
name = "${var.dns_name}-NatRule-${count.index}"
|
||||||
|
resource_group_name = "${azurerm_resource_group.rg.name}"
|
||||||
|
loadbalancer_id = "${azurerm_lb.lb.id}"
|
||||||
|
protocol = "tcp"
|
||||||
|
frontend_port = "6400${count.index + 1}"
|
||||||
|
backend_port = 22
|
||||||
|
frontend_ip_configuration_name = "${var.dns_name}-sshIPCfg"
|
||||||
|
count = "${var.node_count}"
|
||||||
|
depends_on = ["azurerm_lb.lb"]
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_lb_nat_rule" "MySQLNatRule0" {
|
||||||
|
name = "${var.dns_name}-MySQLNatRule-${count.index}"
|
||||||
|
resource_group_name = "${azurerm_resource_group.rg.name}"
|
||||||
|
loadbalancer_id = "${azurerm_lb.lb.id}"
|
||||||
|
protocol = "tcp"
|
||||||
|
frontend_port = "330${count.index + 6}"
|
||||||
|
backend_port = 3306
|
||||||
|
frontend_ip_configuration_name = "${var.dns_name}-sshIPCfg"
|
||||||
|
count = "${var.node_count}"
|
||||||
|
depends_on = ["azurerm_lb.lb"]
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_lb_nat_rule" "ProbeNatRule0" {
|
||||||
|
name = "${var.dns_name}-ProbeNatRule-${count.index}"
|
||||||
|
resource_group_name = "${azurerm_resource_group.rg.name}"
|
||||||
|
loadbalancer_id = "${azurerm_lb.lb.id}"
|
||||||
|
protocol = "tcp"
|
||||||
|
frontend_port = "920${count.index}"
|
||||||
|
backend_port = 9200
|
||||||
|
frontend_ip_configuration_name = "${var.dns_name}-sshIPCfg"
|
||||||
|
count = "${var.node_count}"
|
||||||
|
depends_on = ["azurerm_lb.lb"]
|
||||||
|
}
|
||||||
|
|
||||||
|
# ********************** VIRTUAL MACHINES ********************** #
|
||||||
|
resource "azurerm_virtual_machine" "vm" {
|
||||||
|
name = "${var.dns_name}${count.index}"
|
||||||
|
resource_group_name = "${azurerm_resource_group.rg.name}"
|
||||||
|
location = "${azurerm_resource_group.rg.location}"
|
||||||
|
vm_size = "${var.vm_size}"
|
||||||
|
network_interface_ids = ["${element(azurerm_network_interface.nic.*.id, count.index)}"]
|
||||||
|
count = "${var.node_count}"
|
||||||
|
availability_set_id = "${azurerm_availability_set.availability_set.id}"
|
||||||
|
depends_on = ["azurerm_availability_set.availability_set", "azurerm_network_interface.nic", "azurerm_storage_account.stor"]
|
||||||
|
|
||||||
|
storage_image_reference {
|
||||||
|
publisher = "${var.image_publisher}"
|
||||||
|
offer = "${var.image_offer}"
|
||||||
|
sku = "${var.os_version}"
|
||||||
|
version = "latest"
|
||||||
|
}
|
||||||
|
|
||||||
|
storage_os_disk {
|
||||||
|
name = "osdisk${count.index}"
|
||||||
|
vhd_uri = "https://${azurerm_storage_account.stor.name}.blob.core.windows.net/vhds/${var.dns_name}${count.index}-osdisk.vhd"
|
||||||
|
create_option = "FromImage"
|
||||||
|
caching = "ReadWrite"
|
||||||
|
}
|
||||||
|
|
||||||
|
os_profile {
|
||||||
|
computer_name = "${var.dns_name}${count.index}"
|
||||||
|
admin_username = "${var.vm_admin_username}"
|
||||||
|
admin_password = "${var.vm_admin_password}"
|
||||||
|
}
|
||||||
|
|
||||||
|
storage_data_disk {
|
||||||
|
name = "datadisk1"
|
||||||
|
vhd_uri = "https://${azurerm_storage_account.stor.name}.blob.core.windows.net/vhds/${var.dns_name}${count.index}-datadisk1.vhd"
|
||||||
|
disk_size_gb = "1000"
|
||||||
|
create_option = "Empty"
|
||||||
|
lun = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
storage_data_disk {
|
||||||
|
name = "datadisk2"
|
||||||
|
vhd_uri = "https://${azurerm_storage_account.stor.name}.blob.core.windows.net/vhds/${var.dns_name}${count.index}-datadisk2.vhd"
|
||||||
|
disk_size_gb = "1000"
|
||||||
|
create_option = "Empty"
|
||||||
|
lun = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
os_profile_linux_config {
|
||||||
|
disable_password_authentication = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "azurerm_virtual_machine_extension" "setup_mysql" {
|
||||||
|
name = "${var.dns_name}-${count.index}-setupMySQL"
|
||||||
|
resource_group_name = "${azurerm_resource_group.rg.name}"
|
||||||
|
location = "${azurerm_resource_group.rg.location}"
|
||||||
|
virtual_machine_name = "${element(azurerm_virtual_machine.vm.*.name, count.index)}"
|
||||||
|
publisher = "Microsoft.Azure.Extensions"
|
||||||
|
type = "CustomScript"
|
||||||
|
type_handler_version = "2.0"
|
||||||
|
auto_upgrade_minor_version = true
|
||||||
|
count = "${var.node_count}"
|
||||||
|
depends_on = ["azurerm_virtual_machine.vm", "azurerm_lb_nat_rule.ProbeNatRule0"]
|
||||||
|
|
||||||
|
settings = <<SETTINGS
|
||||||
|
{
|
||||||
|
"fileUris": ["${var.artifacts_location}${var.azuremysql_script}"]
|
||||||
|
}
|
||||||
|
SETTINGS
|
||||||
|
|
||||||
|
protected_settings = <<SETTINGS
|
||||||
|
{
|
||||||
|
"commandToExecute": "bash azuremysql.sh ${count.index + 1} 10.0.1.${count.index + 4} ${var.artifacts_location}${var.mysql_cfg_file_path} '${var.mysql_replication_password}' '${var.mysql_root_password}' '${var.mysql_probe_password}' 10.0.1.4 ${var.unique_prefix}wordpress"
|
||||||
|
}
|
||||||
|
SETTINGS
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
output "resource_group" {
|
||||||
|
value = "${var.resource_group}"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "fqdn" {
|
||||||
|
value = "${azurerm_public_ip.pip.fqdn}"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "azure_website" {
|
||||||
|
value = "http://${var.dns_name}.azurewebsites.net"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "ip_address" {
|
||||||
|
value = "${azurerm_public_ip.pip.ip_address}"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "ssh_command_master" {
|
||||||
|
value = "ssh ${var.vm_admin_username}@${azurerm_public_ip.pip.ip_address} -p 64001"
|
||||||
|
}
|
||||||
|
|
||||||
|
output "ssh_command_slave" {
|
||||||
|
value = "ssh ${var.vm_admin_username}@${azurerm_public_ip.pip.ip_address} -p 64002"
|
||||||
|
}
|
|
@ -0,0 +1,210 @@
|
||||||
|
# variable "client_id" {}
|
||||||
|
# variable "client_secret" {}
|
||||||
|
# variable "tenant_id" {}
|
||||||
|
# variable "subscription_id" {}
|
||||||
|
|
||||||
|
variable "resource_group" {
|
||||||
|
description = "Resource group name into which your Spark and Cassandra deployment will go."
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "location" {
|
||||||
|
description = "The location/region where the virtual network is created. Changing this forces a new resource to be created."
|
||||||
|
default = "southcentralus"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "unique_prefix" {
|
||||||
|
description = "This prefix is used for names which need to be globally unique."
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "vm_admin_username" {
|
||||||
|
description = "Specify an admin username that should be used to login to the VM. Min length: 1"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "vm_admin_password" {
|
||||||
|
description = "Specify an admin password that should be used to login to the VM. Must be between 6-72 characters long and must satisfy at least 3 of password complexity requirements from the following: 1) Contains an uppercase character 2) Contains a lowercase character 3) Contains a numeric digit 4) Contains a special character"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "os_image_publisher" {
|
||||||
|
description = "name of the publisher of the image (az vm image list)"
|
||||||
|
default = "OpenLogic"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "os_image_offer" {
|
||||||
|
description = "the name of the offer (az vm image list)"
|
||||||
|
default = "CentOS"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "os_version" {
|
||||||
|
description = "version of the image to apply (az vm image list)"
|
||||||
|
default = "6.5"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "api_version" {
|
||||||
|
default = "2015-06-15"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "artifacts_location" {
|
||||||
|
description = "The base URI where artifacts required by this template are located."
|
||||||
|
default = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/wordpress-mysql-replication/"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "azuremysql_script" {
|
||||||
|
description = "The directory and script which will configure MySQL"
|
||||||
|
default = "scripts/azuremysql.sh"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "mysql_cfg_file_path" {
|
||||||
|
description = "The directory and script which will be called in the extension for the MySQL config"
|
||||||
|
default = "scripts/my.cnf.template"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "site_name" {
|
||||||
|
description = "wordpress site name"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "hosting_plan_name" {
|
||||||
|
description = "website host plan"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "sku" {
|
||||||
|
description = "Website sku. Allowed values: Basic, Standard, Premium"
|
||||||
|
default = "Standard"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "worker_size" {
|
||||||
|
description = "Website worker size. Allowed values: 0, 1, 2"
|
||||||
|
default = "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "dns_name" {
|
||||||
|
description = "Connect to your cluster using dnsName.location.cloudapp.azure.com"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "public_ip_name" {
|
||||||
|
description = "public IP name for MySQL loadbalancer"
|
||||||
|
default = "mysqlIP01"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "mysql_root_password" {
|
||||||
|
description = "mysql root user password"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "mysql_replication_password" {
|
||||||
|
description = "mysql replication user password"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "mysql_probe_password" {
|
||||||
|
description = "mysql probe password"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "vm_size" {
|
||||||
|
description = "size for the VMs"
|
||||||
|
default = "Standard_D2"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "storage_account_type" {
|
||||||
|
description = "Storage account type for the cluster"
|
||||||
|
default = "Standard_LRS"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "virtual_network_name" {
|
||||||
|
description = "New or Existing Virtual network name for the cluster"
|
||||||
|
default = "mysqlvnet"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "vnet_new_or_existing" {
|
||||||
|
description = "Identifies whether to use new or existing Virtual Network"
|
||||||
|
default = "new"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "vnet_existing_resource_group_name" {
|
||||||
|
description = "If using existing VNet, specifies the resource group for the existing VNet"
|
||||||
|
default = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "db_subnet_name" {
|
||||||
|
description = "subnet name for the MySQL nodes"
|
||||||
|
default = "default"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "vnet_address_prefix" {
|
||||||
|
description = "IP address in CIDR for virtual network"
|
||||||
|
default = "10.0.0.0/16"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "db_subnet_address_prefix" {
|
||||||
|
description = "IP address in CIDR for db subnet"
|
||||||
|
default = "10.0.1.0/24"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "db_subnet_start_address" {
|
||||||
|
description = "Start IP address for the VMs in db subnet"
|
||||||
|
default = "10.0.1.4"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "image_publisher" {
|
||||||
|
description = "publisher for the VM OS image"
|
||||||
|
default = "OpenLogic"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "image_offer" {
|
||||||
|
description = "VM OS name"
|
||||||
|
default = "CentOS"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "image_sku" {
|
||||||
|
description = "VM OS version. Allowed values: 6.5, 6.6"
|
||||||
|
default = "6.5"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "mysql_front_end_port_0" {
|
||||||
|
description = "MySQL public port"
|
||||||
|
default = "3306"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "mysql_front_end_port_1" {
|
||||||
|
description = "MySQL public port"
|
||||||
|
default = "3307"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ssh_nat_rule_front_end_port_0" {
|
||||||
|
description = "public ssh port for VM1"
|
||||||
|
default = "64001"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "ssh_nat_rule_front_end_port_1" {
|
||||||
|
description = "public ssh port for VM2"
|
||||||
|
default = "64002"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "mysql_probe_port_0" {
|
||||||
|
description = "MySQL public port master"
|
||||||
|
default = "9200"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "mysql_probe_port_1" {
|
||||||
|
description = "MySQL public port slave"
|
||||||
|
default = "9201"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "storage_account_name" {
|
||||||
|
description = "Name of the Storage Account"
|
||||||
|
default = "storagesa"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "template_api_version" {
|
||||||
|
default = "2015-01-01"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "wpdbname" {
|
||||||
|
default = "wordpress"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "node_count" {
|
||||||
|
default = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "nic_name" {
|
||||||
|
description = "Name of the Network Interface"
|
||||||
|
default = "nic"
|
||||||
|
}
|
|
@ -0,0 +1,140 @@
|
||||||
|
# ********************** WEBSITE DEPLOYMENT TEMPLATE ********************** #
|
||||||
|
|
||||||
|
resource "azurerm_template_deployment" "website" {
|
||||||
|
name = "website"
|
||||||
|
resource_group_name = "${azurerm_resource_group.rg.name}"
|
||||||
|
depends_on = ["azurerm_virtual_machine_extension.setup_mysql"]
|
||||||
|
|
||||||
|
template_body = <<DEPLOY
|
||||||
|
{
|
||||||
|
"$schema":"http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
|
||||||
|
"contentVersion":"1.0.0.0",
|
||||||
|
"parameters":{
|
||||||
|
"siteName":{
|
||||||
|
"type":"string",
|
||||||
|
"defaultValue":"${var.site_name}"
|
||||||
|
},
|
||||||
|
"hostingPlanName":{
|
||||||
|
"type":"string",
|
||||||
|
"defaultValue":"${var.hosting_plan_name}"
|
||||||
|
},
|
||||||
|
"sku":{
|
||||||
|
"type":"string",
|
||||||
|
"allowedValues":[
|
||||||
|
"Free",
|
||||||
|
"Shared",
|
||||||
|
"Basic",
|
||||||
|
"Standard",
|
||||||
|
"Premium"
|
||||||
|
],
|
||||||
|
"defaultValue":"${var.sku}"
|
||||||
|
},
|
||||||
|
"workerSize":{
|
||||||
|
"type":"string",
|
||||||
|
"allowedValues":[
|
||||||
|
"0",
|
||||||
|
"1",
|
||||||
|
"2"
|
||||||
|
],
|
||||||
|
"defaultValue":"${var.worker_size}"
|
||||||
|
},
|
||||||
|
"dbServer":{
|
||||||
|
"type":"string",
|
||||||
|
"defaultValue":"${var.dns_name}.${azurerm_resource_group.rg.location}.cloudapp.azure.com:${var.mysql_front_end_port_0}"
|
||||||
|
},
|
||||||
|
"dbName":{
|
||||||
|
"type":"string",
|
||||||
|
"defaultValue":"${var.unique_prefix}wordpress"
|
||||||
|
},
|
||||||
|
"dbAdminPassword":{
|
||||||
|
"type":"string",
|
||||||
|
"defaultValue":"${var.mysql_root_password}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"variables":{
|
||||||
|
"connectionString":"[concat('Database=', parameters('dbName'), ';Data Source=', parameters('dbServer'), ';User Id=admin;Password=', parameters('dbAdminPassword'))]",
|
||||||
|
"repoUrl":"https://github.com/azureappserviceoss/wordpress-azure",
|
||||||
|
"branch":"master",
|
||||||
|
"workerSize":"[parameters('workerSize')]",
|
||||||
|
"sku":"[parameters('sku')]",
|
||||||
|
"hostingPlanName":"[parameters('hostingPlanName')]"
|
||||||
|
},
|
||||||
|
"resources":[
|
||||||
|
{
|
||||||
|
"apiVersion":"2014-06-01",
|
||||||
|
"name":"[variables('hostingPlanName')]",
|
||||||
|
"type":"Microsoft.Web/serverfarms",
|
||||||
|
"location":"[resourceGroup().location]",
|
||||||
|
"properties":{
|
||||||
|
"name":"[variables('hostingPlanName')]",
|
||||||
|
"sku":"[variables('sku')]",
|
||||||
|
"workerSize":"[variables('workerSize')]",
|
||||||
|
"hostingEnvironment":"",
|
||||||
|
"numberOfWorkers":0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"apiVersion":"2015-02-01",
|
||||||
|
"name":"[parameters('siteName')]",
|
||||||
|
"type":"Microsoft.Web/sites",
|
||||||
|
"location":"[resourceGroup().location]",
|
||||||
|
"tags":{
|
||||||
|
"[concat('hidden-related:', '/subscriptions/', subscription().subscriptionId,'/resourcegroups/', resourceGroup().name, '/providers/Microsoft.Web/serverfarms/', variables('hostingPlanName'))]":"empty"
|
||||||
|
},
|
||||||
|
"dependsOn":[
|
||||||
|
"[concat('Microsoft.Web/serverfarms/', variables('hostingPlanName'))]"
|
||||||
|
],
|
||||||
|
"properties":{
|
||||||
|
"name":"[parameters('siteName')]",
|
||||||
|
"serverFarmId":"[concat('/subscriptions/', subscription().subscriptionId,'/resourcegroups/', resourceGroup().name, '/providers/Microsoft.Web/serverfarms/', variables('hostingPlanName'))]",
|
||||||
|
"hostingEnvironment":""
|
||||||
|
},
|
||||||
|
"resources":[
|
||||||
|
{
|
||||||
|
"apiVersion":"2015-04-01",
|
||||||
|
"name":"connectionstrings",
|
||||||
|
"type":"config",
|
||||||
|
"dependsOn":[
|
||||||
|
"[concat('Microsoft.Web/Sites/', parameters('siteName'))]"
|
||||||
|
],
|
||||||
|
"properties":{
|
||||||
|
"defaultConnection":{
|
||||||
|
"value":"[variables('connectionString')]",
|
||||||
|
"type":"MySQL"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"apiVersion":"2015-04-01",
|
||||||
|
"name":"web",
|
||||||
|
"type":"config",
|
||||||
|
"dependsOn":[
|
||||||
|
"[concat('Microsoft.Web/Sites/', parameters('siteName'))]"
|
||||||
|
],
|
||||||
|
"properties":{
|
||||||
|
"phpVersion":"5.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"apiVersion":"2015-08-01",
|
||||||
|
"name":"web",
|
||||||
|
"type":"sourcecontrols",
|
||||||
|
"dependsOn":[
|
||||||
|
"[resourceId('Microsoft.Web/Sites', parameters('siteName'))]",
|
||||||
|
"[concat('Microsoft.Web/Sites/', parameters('siteName'), '/config/connectionstrings')]",
|
||||||
|
"[concat('Microsoft.Web/Sites/', parameters('siteName'), '/config/web')]"
|
||||||
|
],
|
||||||
|
"properties":{
|
||||||
|
"RepoUrl":"[variables('repoUrl')]",
|
||||||
|
"branch":"[variables('branch')]",
|
||||||
|
"IsManualIntegration":true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
DEPLOY
|
||||||
|
|
||||||
|
deployment_mode = "Incremental"
|
||||||
|
}
|
Loading…
Reference in New Issue