hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.52k stars 4.6k forks source link

Unable to add extension to VM Scale Set to enable Memory Consumption Metrics #4695

Closed anaik91 closed 4 years ago

anaik91 commented 4 years ago

Community Note

Terraform (and AzureRM Provider) Version

Affected Resource(s)

Terraform Configuration Files

data "azurerm_image" "custom" {
  name                = "${var.custom_image_name}"
  resource_group_name = "${var.custom_image_resource_group_name}"
}

data "azurerm_virtual_network" "test" {
  name                = "${var.vnet}"
  resource_group_name = "${var.resource_group_name}"
}

data "azurerm_subnet" "test" {
  name                 = "${var.subnet}"
  virtual_network_name = "${var.vnet}"
  resource_group_name  = "${var.resource_group_name}"
}

data "azurerm_lb" "test" {
  name                = "concourse-runtim-westeurope-v1-shared_lb"
  resource_group_name = "${var.resource_group_name}"
}

data "azurerm_lb_backend_address_pool" "test" {
  name            = "SHARED-Pool"
  loadbalancer_id = "${data.azurerm_lb.test.id}"
}

resource "azurerm_virtual_machine_scale_set" "test" {
  name                = "${var.projectName}-scaleset-1"
  location            = "${var.location}"
  resource_group_name = "${var.resource_group_name}"

  automatic_os_upgrade = false
  upgrade_policy_mode  = "Manual"

  sku {
    name     = "Standard_F8"
    tier     = "Standard"
    capacity = "${var.default_instance_count}"
  }

  storage_profile_image_reference {
    id = "${data.azurerm_image.custom.id}"
  }

  storage_profile_os_disk  {
    caching           = "ReadWrite"
    create_option     = "FromImage"
    managed_disk_type = "Standard_LRS"
  }

  os_profile {
    computer_name_prefix  = "${var.projectName}"
    admin_username = "testadmin"
    admin_password = "SampleP@ssword@1234!"
    custom_data = "${file("cloud-config.yaml")}"
  }

  os_profile_linux_config {
    disable_password_authentication = false
  }

  network_profile {
    name    = "networkprofile"
    primary = true

    ip_configuration {
      name                                   = "TestIPConfiguration"
      primary                                = true
      subnet_id                              = "${data.azurerm_subnet.test.id}"
      load_balancer_backend_address_pool_ids = ["${data.azurerm_lb_backend_address_pool.test.id}"]
      #load_balancer_inbound_nat_rules_ids    = ["${element(azurerm_lb_nat_pool.lbnatpool.*.id, count.index)}"]
    }
  }

  extension {
    name = "LinuxDiagnosticExtension"
    publisher = "Microsoft.Azure.Diagnostics"
    type = "LinuxDiagnostic"
    type_handler_version = "3.0"
    protected_settings = <<PROTECTED_SETTINGS
      {
        "storageAccountName": "${azurerm_storage_account.testsa.name}",
        "storageAccountSasToken": "${data.azurerm_storage_account_sas.test.sas}"
      }
    PROTECTED_SETTINGS
    settings = <<SETTINGS
    {
      "autoUpgradeMinorVersion": true,
      "forceUpdateTag": null,
      "id": null,
      "name": "LinuxDiagnostic",
      "protectedSettings": null,
      "provisionAfterExtensions": null,
      "provisioningState": null,
      "publisher": "Microsoft.Azure.Diagnostics",
      "settings": {
        "StorageAccount": "runtimwesteuropev1",
        "ladCfg": {
          "diagnosticMonitorConfiguration": {
            "eventVolume": "Medium",
            "metrics": {
              "metricAggregation": [{
                  "scheduledTransferPeriod": "PT1H"
                },
                {
                  "scheduledTransferPeriod": "PT1M"
                }
              ],
              "resourceId": "${azurerm_virtual_machine_scale_set.test.id}"
            },
            "performanceCounters": {
              "performanceCounterConfiguration": [{
                  "annotation": [
                {
                  "annotation": [{
                    "displayName": "Memory percentage",
                    "locale": "en-us"
                  }],
                  "class": "memory",
                  "counter": "percentusedmemory",
                  "counterSpecifier": "/builtin/memory/percentusedmemory",
                  "type": "builtin",
                  "unit": "Percent"
                }
              ]
            },
            "syslogEvents": {
              "syslogEventConfiguration": {
                "LOG_AUTH": "LOG_DEBUG",
                "LOG_AUTHPRIV": "LOG_DEBUG",
                "LOG_CRON": "LOG_DEBUG",
                "LOG_DAEMON": "LOG_DEBUG",
                "LOG_FTP": "LOG_DEBUG",
                "LOG_KERN": "LOG_DEBUG",
                "LOG_LOCAL0": "LOG_DEBUG",
                "LOG_LOCAL1": "LOG_DEBUG",
                "LOG_LOCAL2": "LOG_DEBUG",
                "LOG_LOCAL3": "LOG_DEBUG",
                "LOG_LOCAL4": "LOG_DEBUG",
                "LOG_LOCAL5": "LOG_DEBUG",
                "LOG_LOCAL6": "LOG_DEBUG",
                "LOG_LOCAL7": "LOG_DEBUG",
                "LOG_LPR": "LOG_DEBUG",
                "LOG_MAIL": "LOG_DEBUG",
                "LOG_NEWS": "LOG_DEBUG",
                "LOG_SYSLOG": "LOG_DEBUG",
                "LOG_USER": "LOG_DEBUG",
                "LOG_UUCP": "LOG_DEBUG"
              }
            }
          },
          "sampleRateInSeconds": 15
        }
      },
      "type": "LinuxDiagnostic",
      "typeHandlerVersion": "3.0"
    }
    SETTINGS

  }

  tags = {
    Project = "${var.projectName}"
    Name = "${var.projectName}_ScaleSet_Routers"
    Type = "runtime"
    Subtype = "router"
  }
}

Debug Output

C:\MyProjects\azure-test\vm-scale-set>terraform apply -auto-approve

Error: azurerm_virtual_machine_scale_set.test: azurerm_virtual_machine_scale_set.test: self reference not allowed: "azurerm_virtual_machine_scale_set.test.id"

Panic Output

Expected Behavior

I should be able to see the "Memory percentage" metric upon enabling the Extension

Actual Behavior

Cannot reference the scale set resource ID to the extension .

Steps to Reproduce

  1. terraform apply -auto-approve

References

I was able to achieve it using azure cli as mentioned in blog

I have checked the below links :

tombuildsstuff commented 4 years ago

hi @anaik91

Thanks for opening this issue.

We're currently working through writing replacements for the Virtual Machine and Virtual Machine Scale Set resources that we previously outlined in #2807 - as a part of this we're introducing a new resource for Virtual Machine Scale Set Extensions - azurerm_virtual_machine_scale_set_extension which should enable this scenario once version 2.0 of the Azure Provider becomes available.

Since this'll be fixed by #4679 which introduces the new Virtual Machine Scale Set Extension resource this'll get closed when that PR's merged - but the new resources will be available in 2.0 when that's released in the coming months. We plan to make it possible to opt into the new resources outlined in #2807 in a future 1.x version of the Azure Provider - however at this time these aren't yet supported/available.

Whilst the fix coming in #4679 won't solve the immediate issue - it should be possible to work around it in the interim by hard-coding the Virtual Machine ID (or building it up dynamically in a local variable) and then referencing this rather than the Virtual Machine Scale Set ID; and later switch to using the new VMSS / VMSS Extension resources once they become available in 2.0.

Thanks!

anaik91 commented 4 years ago

Hi @tombuildsstuff

Thank you for quick response. Do we have an ETA on the release of 2.0?

Thanks!!

tombuildsstuff commented 4 years ago

@anaik91 nothing concrete since there's a few things still up in the air unfortunately - that said we're targeting this side of the end of the year - I'd suggest subscribing to #2807 for updates :)

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error πŸ€– πŸ™‰ , please reach out to my human friends πŸ‘‰ hashibot-feedback@hashicorp.com. Thanks!

ghost commented 4 years ago

This has been released in version 2.0.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.0.0"
}
# ... other configuration ...