forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from julienstroheker/upgrade_policy_rolling
Add test and documentation
- Loading branch information
Showing
5 changed files
with
386 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Linux VM Scale Set with Automatic OS upgrades and Rolling Upgrade Policy | ||
|
||
This template deploys a Linux (Ubuntu) VM Scale Set. Once the VMSS is deployed, the user can deploy an application inside each of the VMs (either by directly logging into the VMs or via a [`remote-exec` provisioner](https://www.terraform.io/docs/provisioners/remote-exec.html)). | ||
|
||
Please review the official documentation first : [Azure virtual machine scale set automatic OS upgrades](https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-automatic-upgrade) | ||
|
||
## main.tf | ||
The `main.tf` file contains the actual resources that will be deployed. It also contains the Azure Resource Group definition and any defined variables. | ||
|
||
## outputs.tf | ||
This data is outputted when `terraform apply` is called, and can be queried using the `terraform output` command. | ||
|
||
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` or any `.auto.tfvars` files are present in the current directory, Terraform automatically loads them 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 the `-var-file` flag or the `.auto.tfvars` extension to load it. | ||
|
||
## variables.tf | ||
The `variables.tf` file contains all of the input parameters that the user can specify when deploying this Terraform template. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
resource "azurerm_resource_group" "rg" { | ||
name = "${var.resource_group_name}" | ||
location = "${var.location}" | ||
} | ||
|
||
resource "azurerm_virtual_network" "vnet" { | ||
name = "${var.resource_group_name}vnet" | ||
location = "${azurerm_resource_group.rg.location}" | ||
address_space = ["10.0.0.0/16"] | ||
resource_group_name = "${azurerm_resource_group.rg.name}" | ||
} | ||
|
||
resource "azurerm_subnet" "subnet" { | ||
name = "subnet" | ||
address_prefix = "10.0.0.0/24" | ||
resource_group_name = "${azurerm_resource_group.rg.name}" | ||
virtual_network_name = "${azurerm_virtual_network.vnet.name}" | ||
} | ||
|
||
resource "azurerm_public_ip" "pip" { | ||
name = "${var.hostname}-pip" | ||
location = "${azurerm_resource_group.rg.location}" | ||
resource_group_name = "${azurerm_resource_group.rg.name}" | ||
public_ip_address_allocation = "Dynamic" | ||
domain_name_label = "${var.hostname}" | ||
} | ||
|
||
resource "azurerm_lb" "lb" { | ||
name = "LoadBalancer" | ||
location = "${azurerm_resource_group.rg.location}" | ||
resource_group_name = "${azurerm_resource_group.rg.name}" | ||
depends_on = ["azurerm_public_ip.pip"] | ||
|
||
frontend_ip_configuration { | ||
name = "LBFrontEnd" | ||
public_ip_address_id = "${azurerm_public_ip.pip.id}" | ||
} | ||
} | ||
|
||
resource "azurerm_lb_backend_address_pool" "backlb" { | ||
name = "BackEndAddressPool" | ||
resource_group_name = "${azurerm_resource_group.rg.name}" | ||
loadbalancer_id = "${azurerm_lb.lb.id}" | ||
} | ||
|
||
resource "azurerm_lb_probe" "prob" { | ||
resource_group_name = "${azurerm_resource_group.test.name}" | ||
loadbalancer_id = "${azurerm_lb.lb.id}" | ||
name = "ssh-running-probe" | ||
port = 22 | ||
protocol = "Tcp" | ||
} | ||
|
||
resource "azurerm_lb_rule" "lbr" { | ||
resource_group_name = "${azurerm_resource_group.rg.name}" | ||
loadbalancer_id = "${azurerm_lb.lb.id}" | ||
name = "LBRule" | ||
protocol = "Tcp" | ||
frontend_port = 22 | ||
backend_port = 22 | ||
frontend_ip_configuration_name = "LBFrontEnd" | ||
probe_id = "${azurerm_lb_probe.prob.id}" | ||
backend_address_pool_id = "${azurerm_lb_backend_address_pool.backlb.id}" | ||
} | ||
|
||
resource "azurerm_storage_account" "stor" { | ||
name = "${var.resource_group_name}stor" | ||
location = "${azurerm_resource_group.rg.location}" | ||
resource_group_name = "${azurerm_resource_group.rg.name}" | ||
account_tier = "${var.storage_account_tier}" | ||
account_replication_type = "${var.storage_replication_type}" | ||
} | ||
|
||
resource "azurerm_storage_container" "vhds" { | ||
name = "vhds" | ||
resource_group_name = "${azurerm_resource_group.rg.name}" | ||
storage_account_name = "${azurerm_storage_account.stor.name}" | ||
container_access_type = "blob" | ||
} | ||
|
||
resource "azurerm_virtual_machine_scale_set" "scaleset" { | ||
name = "autoscalewad" | ||
location = "${azurerm_resource_group.rg.location}" | ||
resource_group_name = "${azurerm_resource_group.rg.name}" | ||
upgrade_policy_mode = "Manual" | ||
overprovision = true | ||
depends_on = ["azurerm_lb.lb", "azurerm_virtual_network.vnet"] | ||
|
||
upgrade_policy_mode = "Rolling" | ||
|
||
automatic_os_upgrade = true | ||
|
||
rolling_upgrade_policy { | ||
max_batch_instance_percent = 20 | ||
max_unhealthy_instance_percent = 20 | ||
max_unhealthy_upgraded_instance_percent = 20 | ||
pause_time_between_batches = "PT0S" | ||
} | ||
|
||
health_probe_id = "${azurerm_lb_probe.prob.id}" | ||
|
||
sku { | ||
name = "${var.vm_sku}" | ||
tier = "Standard" | ||
capacity = "${var.instance_count}" | ||
} | ||
|
||
os_profile { | ||
computer_name_prefix = "${var.vmss_name_prefix}" | ||
admin_username = "${var.admin_username}" | ||
admin_password = "${var.admin_password}" | ||
} | ||
|
||
os_profile_linux_config { | ||
disable_password_authentication = false | ||
} | ||
|
||
network_profile { | ||
name = "${var.hostname}-nic" | ||
primary = true | ||
|
||
ip_configuration { | ||
primary = true | ||
name = "${var.hostname}ipconfig" | ||
subnet_id = "${azurerm_subnet.subnet.id}" | ||
load_balancer_backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.backlb.id}"] | ||
} | ||
} | ||
|
||
storage_profile_os_disk { | ||
name = "${var.hostname}" | ||
caching = "ReadWrite" | ||
create_option = "FromImage" | ||
vhd_containers = ["${azurerm_storage_account.stor.primary_blob_endpoint}${azurerm_storage_container.vhds.name}"] | ||
} | ||
|
||
storage_profile_image_reference { | ||
publisher = "${var.image_publisher}" | ||
offer = "${var.image_offer}" | ||
sku = "${var.ubuntu_os_version}" | ||
version = "latest" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "hostname" { | ||
value = "${var.vmss_name_prefix}" | ||
} |
Oops, something went wrong.