Terraform-provider-azurerm: Azure Automation DSC

Created on 30 Dec 2017  ·  7Comments  ·  Source: terraform-providers/terraform-provider-azurerm

Terraform v0.11.1

  • provider.azurerm v0.2.2

I am having 2 issues with the below DSC VM extension:

1) The extension is installing (showing as installed on each of the VMs, however my node configuration is not registering with my Azure Automation account defined.

2) I have to run my tf file twice on first provisioning the VMs as it states the VM does not yet exists yet, I would think there is an automatic dependency on the VM being created prior to installing any VM extensions?

resource "azurerm_virtual_machine_extension" "dsc" {
 count                = 2
 name                 = "${var.vm_hostname}${count.index}"
 location             = "${var.location}"
 resource_group_name  = "${azurerm_resource_group.vm.name}"
 virtual_machine_name = "${var.vm_hostname}${count.index}"
 publisher            = "Microsoft.Powershell"
 type                 = "DSC"
 type_handler_version = "2.73"

 settings = <<SETTINGS
   {
       "configuration": {
           "registrationKey": "XXXX-Removed-XXXX",
           "registrationUrl": "https://scus-agentservice-prod-1.azure-automation.net/accounts/xxxxxx-removed-xxxxx",
           "ConfigurationNames": "FileResource.locahost"
       }
   }
SETTINGS
}

anyone successfully bootstrap the Azure Automation DSC extension?

question

All 7 comments

try adding a depends_on to your resource to stop the "VM does not exist" error;

depends_on = ["azurerm_virtual_machine.virtual_machine"]

hey @catz423

Thanks for opening this issue :)

To answer both questions in-line:

The extension is installing (showing as installed on each of the VMs, however my node configuration is not registering with my Azure Automation account defined.

Unfortunately Azure VM Extensions are fairly complex to configure - my bet would be this is an issue with the casing of the JSON.

Checking the history it appears we've previously had an issue opened about DSC here (albeit for the VMSS Extension, they should be similar) - https://github.com/terraform-providers/terraform-provider-azurerm/issues/248#issuecomment-322748489 which may provide some pointers. My suggestion would be that the field registrationKey needs to become RegistrationKey and the field registrationUrl needs to become RegistrationKey.

I have to run my tf file twice on first provisioning the VMs as it states the VM does not yet exists yet, I would think there is an automatic dependency on the VM being created prior to installing any VM extensions?

As @divgo has suggested this is because there's no dependency between the azurerm_virtual_machine resource and the azurerm_virtual_machine_extension resource, so Terraform believes it can execute them in Parallel / out of order. It's possible to specify either an Explicit Dependency (by referencing the name of the VM via something like ${azurerm_virtual_machine.test.name}) or an implicit dependency using a depends_on as @divgo has suggested.

There's more information on this here and I'd recommend using an Explicit Dependency where possible, by referencing the resource through the interpolation syntax as shown above.


Given the remaining issue doesn't appear to be a bug with Terraform (and is instead a configuration issue with the VM Extension Resource) - I'm going to close this issue for the moment, but please feel free to follow up here and we'll try and work through this :)

Hope that helps?

Thanks!

I think the problem is we are expecting the DSC Extension to be able to register a VM with Azure Automation, but that is not what the extension actually does. Looking at the list of properties available when installing an extension, none of the properties are for Azure Automation DSC registration.

image

I got this to work today and just committed the scripts\terraform files that worked for me;
https://github.com/divgo/terraform/tree/master/bootstrap_azure_automation

The trick was to use the DSCExtension to update the VM to WMF5.1 and PowerShell 5.1. Once this was completed, I could use LocalConfigurationManager to onboard the machine to Azure Automation. The LCM configuration can be found here: https://docs.microsoft.com/en-us/azure/automation/automation-dsc-onboarding#generating-dsc-metaconfigurations as well as in the repo posted.

Thanks, I will try this in a few days to confirm.

@catz423 did this work for you? I am trying to get this to work myself, I need to set up a VMSS set.

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 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings