Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/azure automation state configuration #242

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion solutions/azure-automation-state-configuration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ Run the following command to initiate the deployment. If you would like to adjus

```bash
curl -o azuredeploy.bicep https://raw.githubusercontent.com/mspnp/samples/main/solutions/azure-automation-state-configuration/azuredeploy.bicep
az deployment group create --resource-group ${RESOURCEGROUP} -f ./azuredeploy.bicep

# Generate ssh key and get public data.
ssh-keygen -t rsa -b 2048

export SSH_KEY=$(cat ~/.ssh/id_rsa.pub)
v-fearam marked this conversation as resolved.
Show resolved Hide resolved

az deployment group create --resource-group ${RESOURCEGROUP} -f ./azuredeploy.bicep --parameters sshKey="${SSH_KEY}"
```

Once complete, click on the **Automation Account** resource and then **State configuration (DSC)** and notice that all virtual machines have been added to the system and are compliant. These machines have all had the PowerShell DSC configuration applied, which has installed a web server on each.
Expand Down
84 changes: 77 additions & 7 deletions solutions/azure-automation-state-configuration/azuredeploy.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ param location string = resourceGroup().location

param adminUserName string

@description('your public key. Authentication to Linux machines should require SSH keys.')
param sshKey string
@secure()
param adminPassword string
param emailAddress string
param windowsVMCount int = 1
param linuxVMCount int = 1
param vmSize string = 'Standard_A1_v2'
param vmSize string = 'Standard_DS1_v2'
param windowsConfiguration object = {
name: 'windowsfeatures'
description: 'A configuration for installing IIS.'
Expand Down Expand Up @@ -134,8 +136,6 @@ resource automationAccountName_linuxConfiguration_name 'Microsoft.Automation/aut
properties: {
logVerbose: false
description: linuxConfiguration.description
state: 'Published'
overwrite: 'true'
source: {
type: 'uri'
value: linuxConfiguration.script
Expand Down Expand Up @@ -165,8 +165,6 @@ resource automationAccountName_windowsConfiguration_name 'Microsoft.Automation/a
properties: {
logVerbose: false
description: windowsConfiguration.description
state: 'Published'
overwrite: 'true'
source: {
type: 'uri'
value: windowsConfiguration.script
Expand Down Expand Up @@ -325,6 +323,9 @@ resource windowsVM 'Microsoft.Compute/virtualMachines@2023-09-01' = [
for i in range(0, windowsVMCount): {
name: '${windowsVMName}${i}'
location: location
identity: {
type: 'SystemAssigned'
}
properties: {
hardwareProfile: {
vmSize: vmSize
Expand All @@ -333,6 +334,14 @@ resource windowsVM 'Microsoft.Compute/virtualMachines@2023-09-01' = [
computerName: '${windowsVMName}${i}'
adminUsername: adminUserName
adminPassword: adminPassword
windowsConfiguration: {
enableAutomaticUpdates: true
patchSettings: {
//Machines should be configured to periodically check for missing system updates
assessmentMode: 'AutomaticByPlatform'
patchMode: 'AutomaticByPlatform'
}
}
}
storageProfile: {
imageReference: {
Expand All @@ -352,13 +361,34 @@ resource windowsVM 'Microsoft.Compute/virtualMachines@2023-09-01' = [
}
]
}
securityProfile: {
//Virtual machines and virtual machine scale sets should have encryption at host enabled
encryptionAtHost: true
}
}
dependsOn: [
windowsNic
]
}
]

resource guestConfigExtensionWindows 'Microsoft.Compute/virtualMachines/extensions@2021-03-01' = [
for i in range(0, windowsVMCount): {
parent: windowsVM[i]
name: 'Microsoft.GuestConfiguration${windowsVM[i].name}'
location: location
properties: {
publisher: 'Microsoft.GuestConfiguration'
type: 'ConfigurationforWindows'
typeHandlerVersion: '1.0'
autoUpgradeMinorVersion: true
enableAutomaticUpgrade: true
settings: {}
protectedSettings: {}
}
}
]

resource windowsVMName_Microsoft_Powershell_DSC 'Microsoft.Compute/virtualMachines/extensions@2023-09-01' = [
for i in range(0, windowsVMCount): {
name: '${windowsVMName}${i}/Microsoft.Powershell.DSC'
Expand All @@ -385,7 +415,7 @@ resource windowsVMName_Microsoft_Powershell_DSC 'Microsoft.Compute/virtualMachin
}
{
Name: 'RegistrationUrl'
#disable-next-line BCP053
#disable-next-line BCP053
Value: automationAccount.properties.registrationUrl
TypeName: 'System.String'
}
Expand Down Expand Up @@ -473,14 +503,33 @@ resource linuxVMN 'Microsoft.Compute/virtualMachines@2023-09-01' = [
for i in range(0, linuxVMCount): {
name: '${linuxVMNAme}${i}'
location: location
identity: {
type: 'SystemAssigned'
}
properties: {
hardwareProfile: {
vmSize: vmSize
}
osProfile: {
computerName: '${linuxVMNAme}${i}'
adminUsername: adminUserName
adminPassword: adminPassword
linuxConfiguration: {
patchSettings: {
//Machines should be configured to periodically check for missing system updates
assessmentMode: 'AutomaticByPlatform'
patchMode: 'AutomaticByPlatform '
}
disablePasswordAuthentication: true
ssh: {
publicKeys: [
{
path: '/home/${adminUserName}/.ssh/authorized_keys'
keyData: sshKey
}
]
}
provisionVMAgent: true
}
}
storageProfile: {
imageReference: {
Expand All @@ -500,13 +549,34 @@ resource linuxVMN 'Microsoft.Compute/virtualMachines@2023-09-01' = [
}
]
}
securityProfile: {
//Virtual machines and virtual machine scale sets should have encryption at host enabled
encryptionAtHost: true
}
}
dependsOn: [
linuxNic
]
}
]

resource guestConfigExtensionLinux 'Microsoft.Compute/virtualMachines/extensions@2021-03-01' = [
for i in range(0, linuxVMCount): {
parent: linuxVMN[i]
name: 'Microsoft.GuestConfiguration${linuxVMN[i].name}'
location: location
properties: {
publisher: 'Microsoft.GuestConfiguration'
type: 'ConfigurationforLinux'
typeHandlerVersion: '1.0'
autoUpgradeMinorVersion: true
enableAutomaticUpgrade: true
settings: {}
protectedSettings: {}
}
}
]

resource linuxVMNAme_enabledsc 'Microsoft.Compute/virtualMachines/extensions@2023-09-01' = [
for i in range(0, linuxVMCount): {
name: '${linuxVMNAme}${i}/enabledsc'
Expand Down