Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save divgo/b0a35c9b3a2e995905c2fb045079a304 to your computer and use it in GitHub Desktop.
Save divgo/b0a35c9b3a2e995905c2fb045079a304 to your computer and use it in GitHub Desktop.
variable "dsc_key" {
default = "dsc_registration_key_from_portal"
}
variable "dsc_endpoint" {
default = "dsc_registration_url_from_portal"
}
variable dsc_config {
default = "node_configuration_you_want_applied__can_leave_blank"
}
variable dsc_mode {
default = "applyAndMonitor"
}
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
{
"WmfVersion": "latest",
"ModulesUrl": "https://eus2oaasibizamarketprod1.blob.core.windows.net/automationdscpreview/RegistrationMetaConfigV2.zip",
"ConfigurationFunction": "RegistrationMetaConfigV2.ps1\\RegistrationMetaConfigV2",
"Privacy": {
"DataCollection": ""
},
"Properties": {
"RegistrationKey": {
"UserName": "PLACEHOLDER_DONOTUSE",
"Password": "PrivateSettingsRef:registrationKeyPrivate"
},
"RegistrationUrl": "${var.dsc_endpoint}",
"NodeConfigurationName": "${var.dsc_config}",
"ConfigurationMode": "${var.dsc_mode}",
"ConfigurationModeFrequencyMins": 15,
"RefreshFrequencyMins": 30,
"RebootNodeIfNeeded": false,
"ActionAfterReboot": "continueConfiguration",
"AllowModuleOverwrite": false
}
}
SETTINGS
protected_settings = <<PROTECTED_SETTINGS
{
"Items": {
"registrationKeyPrivate" : "${var.dsc_key}"
}
}
PROTECTED_SETTINGS
}
@rb-cloud-guru
Copy link

The one thing i would like to add is the following:
depends_on = ["azurerm_virtual_machine.virtual_machine"] is only if you are creating a VM at the same time of adding the extension,
type_handler_version = "2.77" is the latest DSC --ver
and in the variable dsc_config { } it is better to specify a config name cos it defies the purpose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment