Skip to content

Instantly share code, notes, and snippets.

@StephenWeatherford
Created June 28, 2017 18:54
Show Gist options
  • Save StephenWeatherford/c236ae8c3f61efcbfd153b6d58f3049a to your computer and use it in GitHub Desktop.
Save StephenWeatherford/c236ae8c3f61efcbfd153b6d58f3049a to your computer and use it in GitHub Desktop.
terraform thinks this always needs changes
Always wants to make these changes:
~ azurerm_virtual_machine_scale_set.test
sku.2127356410.capacity: "4" => "0"
sku.2127356410.name: "Standard_A0" => ""
sku.680937084.capacity: "" => "2"
sku.680937084.name: "" => "Standard_A0"
sku.680937084.tier: "" => "Standard"
--------
variable "time_zone" {
type = "string"
default = "Pacific Standard Time"
}
variable "adminPwd" {
type = "string"
default = "^l&f_ZwX2L4C"
}
resource "azurerm_resource_group" "test" {
name = "stephwe-autoscalingTest2"
location = "West US"
}
resource "azurerm_autoscale_setting" "test" {
name = "myAutoscaleSetting"
enabled = true
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
target_resource_uri = "${azurerm_virtual_machine_scale_set.test.id}"
profile {
name = "defaultProfile"
capacity {
default = 1
minimum = 1
maximum = 10
}
/* rule {
"metric_trigger" {
"metric_name" = "Percentage CPU"
"metric_resource_uri" = "${azurerm_virtual_machine_scale_set.test.id}"
"time_grain" = "PT30S" //"PT1M"
"statistic" = "Average"
"time_window" = "PT5M"
"time_aggregation" = "Average"
"operator" = "GreaterThan"
"threshold" = 2
}
"scale_action" {
"direction" = "Increase"
"type" = "ChangeCount"
"value" = "2"
"cooldown" = "PT1M"
}
}*/
rule {
"metric_trigger" {
"metric_name" = "Percentage CPU"
"metric_resource_uri" = "${azurerm_virtual_machine_scale_set.test.id}"
"time_grain" = "PT1M"
"statistic" = "Average"
"time_window" = "PT5M"
"time_aggregation" = "Average"
"operator" = "GreaterThan"
"threshold" = 3
}
"scale_action" {
"direction" = "Increase"
"type" = "ChangeCount"
"value" = "3"
"cooldown" = "PT1M"
}
}
rule {
"metric_trigger" {
"metric_name" = "Percentage CPU"
"metric_resource_uri" = "${azurerm_virtual_machine_scale_set.test.id}"
"time_grain" = "PT1M"
"statistic" = "Average"
"time_window" = "PT5M"
"time_aggregation" = "Average"
"operator" = "LessThan"
"threshold" = "1"
}
"scale_action" {
"direction" = "Increase"
"type" = "ChangeCount"
"value" = "2"
"cooldown" = "PT1M"
}
}
}
notification {
"operation" = "Scale"
"email" {
"send_to_subscription_administrator" = true
"send_to_subscription_co_administrator" = true
}
}
}
resource "azurerm_virtual_network" "test" {
name = "acctvn"
address_space = ["10.0.0.0/16"]
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
resource "azurerm_subnet" "test" {
name = "acctsub"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
}
resource "azurerm_public_ip" "test" {
name = "acctPublicIp"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
public_ip_address_allocation = "static"
}
resource "azurerm_lb" "test" {
name = "acctlb"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
frontend_ip_configuration {
name = "PublicIPAddress"
public_ip_address_id = "${azurerm_public_ip.test.id}"
}
}
resource "azurerm_lb_backend_address_pool" "bpepool" {
name = "BackEndAddressPool"
resource_group_name = "${azurerm_resource_group.test.name}"
loadbalancer_id = "${azurerm_lb.test.id}"
}
resource "azurerm_lb_nat_pool" "lbnatpool" {
count = 3
resource_group_name = "${azurerm_resource_group.test.name}"
name = "ssh"
loadbalancer_id = "${azurerm_lb.test.id}"
protocol = "Tcp"
frontend_port_start = 50000
frontend_port_end = 50119
backend_port = 22
frontend_ip_configuration_name = "PublicIPAddress"
}
resource "azurerm_virtual_machine_scale_set" "test" {
name = "myTestScaleset-1"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
upgrade_policy_mode = "Manual"
sku {
name = "Standard_A0"
tier = "Standard"
capacity = 2
}
storage_profile_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "14.04.2-LTS"
version = "latest"
}
storage_profile_os_disk {
name = ""
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}
storage_profile_data_disk {
lun = 0
caching = "ReadWrite"
create_option = "Empty"
disk_size_gb = 10
}
os_profile {
computer_name_prefix = "testvm"
admin_username = "myadmin"
admin_password = "${var.adminPwd}"
}
os_profile_linux_config {
disable_password_authentication = false
}
network_profile {
name = "terraformnetworkprofile"
primary = true
ip_configuration {
name = "TestIPConfiguration"
subnet_id = "${azurerm_subnet.test.id}"
load_balancer_backend_address_pool_ids = ["${azurerm_lb_backend_address_pool.bpepool.id}"]
load_balancer_inbound_nat_rules_ids = ["${element(azurerm_lb_nat_pool.lbnatpool.*.id, count.index)}"]
}
}
tags {
environment = "staging"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment