Skip to content

Instantly share code, notes, and snippets.

@divgo
Created January 21, 2018 17:28
Show Gist options
  • Select an option

  • Save divgo/01d5e008251f04e101bfb761de8de533 to your computer and use it in GitHub Desktop.

Select an option

Save divgo/01d5e008251f04e101bfb761de8de533 to your computer and use it in GitHub Desktop.

Revisions

  1. divgo created this gist Jan 21, 2018.
    62 changes: 62 additions & 0 deletions OnboardVM_ToAzureAutomation_WithTerraform.tf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    variable "dsc_key" {
    default = "your_azure_automation_key"
    }
    variable "dsc_endpoint" {
    default= "your_azure_automation_endpoint_url"
    }
    variable "storage_account_key" {
    default = "your_storage_account_key_where_scripts_saved"
    }
    variable dsc_config {
    default = ""
    }

    resource "azurerm_virtual_machine_extension" "dsc" {
    name = "DevOpsDSC"
    location = "${var.location}"
    resource_group_name = "${var.resource_group_name}"
    virtual_machine_name = "${var.vm_name}"
    publisher = "Microsoft.Powershell"
    type = "DSC"
    type_handler_version = "2.73"
    depends_on = ["azurerm_virtual_machine.virtual_machine"]
    settings = <<SETTINGS
    {
    "ModulesUrl":"",
    "SasToken":"",
    "WmfVersion": "latest",
    "Privacy": {
    "DataCollection": ""
    },
    "ConfigurationFunction":""
    }
    SETTINGS
    }

    resource "azurerm_virtual_machine_extension" "register_for_dsc" {
    name = "register_for_dsc"
    location = "${var.location}"
    resource_group_name = "${var.resource_group_name}"
    virtual_machine_name = "${var.vm_name}"
    publisher = "Microsoft.Compute"
    type = "CustomScriptExtension"
    type_handler_version = "1.8"
    depends_on = ["azurerm_virtual_machine_extension.dsc"]

    settings = <<SETTINGS
    {
    "fileUris": [
    "https://your_storage_account.blob.core.windows.net/scripts/DscMetaConfigs.ps1",
    "https://your_storage_account.blob.core.windows.net/scripts/Execute_DscScripts.ps1"
    ]
    }
    SETTINGS

    protected_settings = <<PROTECTED_SETTINGS
    {
    "commandToExecute": "powershell.exe -ExecutionPolicy Bypass -File ./Execute_DscScripts.ps1 ${var.dsc_key} ${var.dsc_endpoint} ${var.dsc_config}",
    "storageAccountName": "your_storage_account",
    "storageAccountKey": "${var.storage_account_key}"
    }
    PROTECTED_SETTINGS
    }