There are few manual steps to setup Azure Automation which can not be handled by TF currently which is compiling the powershell DSC script.
Note, I read this may be added later to az automation resource list of TF, but no guarantees as this is not creating any resources, its more about your script and compiling to generate the MOF file.
Steps are performed on Windows (can be done on Linux or Mac, but have to download and setup powershell, az modules etc)
1) Launch powershell (Run-> powershell ->select powershell(x86)
2) $PSVersionTable (make sure this is not version 5.1, we need PowerShell version 6.x.x)
3) Upgrade powershell to v6
( Execute the command below -> Should launch a window to install new version - follow the steps
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"
)
PS C:\Program Files (x86)\PowerShell\6> $PSVersionTable
Name Value
---- -----
PSVersion 6.2.3
PSEdition Core
GitCommitId 6.2.3
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PS C:\Program Files (x86)\PowerShell\6>
4) You have to install the modules to compile your script. There are default modules, but if you don't find in default, then install it
To check on the modules available ( note the folder where it stores the modules)
PS C:\windows\system32> Get-Module -ListAvailable
Directory: C:\Program Files\WindowsPowerShell\Modules
5) The above module path should be part of your powershell environment, if it;s not, thenyou have to add it to the environment.
PS C:\Program Files (x86)\PowerShell\6> $env:PSModulePath
C:\Users\testadmin\Documents\PowerShell\Modules;C:\Program Files (x86)\PowerShell\Modules;c:\program files (x86)\powershell\6\Modules;C:\windows\system32\WindowsPowerShell\v1.0\Modules
PS C:\Program Files (x86)\PowerShell\6>
Add the path to the environment
PS C:\Program Files (x86)\PowerShell\6> $env:PSModulePath=$env:PSModulePath + ";C:\Program Files\WindowsPowerShell\Modules"
6) Install the modules needed.
PS C:\Program Files (x86)\PowerShell\6> Install-Module WindowsPSModulePath
PS C:\Program Files (x86)\PowerShell\6> Install-Module -name ComputerManagementDSC -MinimumVersion 6.0
7) Write the script
time-conf.ps1
configuration timezone {
Import-DscResource -ModuleName ComputerManagementDsc -ModuleVersion 7.0.0.0
Write-Output 'Hi'
TimeZone westeustandard {
IsSingleInstance = 'Yes'
TimeZone = 'W. Europe Standard Time'
}
}
timezone
8) Let's compile the ps1 script
ps> . ./time-conf.ps1
The compile should create a folder called timezone. This folder should have a mof file called localhost.mof
9) Copy the ps1 script (time-conf.ps1) and the timezone folder to the terraform code directory and use it in the terraform code.
Note, I read this may be added later to az automation resource list of TF, but no guarantees as this is not creating any resources, its more about your script and compiling to generate the MOF file.
Steps are performed on Windows (can be done on Linux or Mac, but have to download and setup powershell, az modules etc)
1) Launch powershell (Run-> powershell ->select powershell(x86)
2) $PSVersionTable (make sure this is not version 5.1, we need PowerShell version 6.x.x)
3) Upgrade powershell to v6
( Execute the command below -> Should launch a window to install new version - follow the steps
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"
)
PS C:\Program Files (x86)\PowerShell\6> $PSVersionTable
Name Value
---- -----
PSVersion 6.2.3
PSEdition Core
GitCommitId 6.2.3
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PS C:\Program Files (x86)\PowerShell\6>
4) You have to install the modules to compile your script. There are default modules, but if you don't find in default, then install it
To check on the modules available ( note the folder where it stores the modules)
PS C:\windows\system32> Get-Module -ListAvailable
Directory: C:\Program Files\WindowsPowerShell\Modules
5) The above module path should be part of your powershell environment, if it;s not, thenyou have to add it to the environment.
PS C:\Program Files (x86)\PowerShell\6> $env:PSModulePath
C:\Users\testadmin\Documents\PowerShell\Modules;C:\Program Files (x86)\PowerShell\Modules;c:\program files (x86)\powershell\6\Modules;C:\windows\system32\WindowsPowerShell\v1.0\Modules
PS C:\Program Files (x86)\PowerShell\6>
Add the path to the environment
PS C:\Program Files (x86)\PowerShell\6> $env:PSModulePath=$env:PSModulePath + ";C:\Program Files\WindowsPowerShell\Modules"
6) Install the modules needed.
PS C:\Program Files (x86)\PowerShell\6> Install-Module WindowsPSModulePath
PS C:\Program Files (x86)\PowerShell\6> Install-Module -name ComputerManagementDSC -MinimumVersion 6.0
7) Write the script
time-conf.ps1
configuration timezone {
Import-DscResource -ModuleName ComputerManagementDsc -ModuleVersion 7.0.0.0
Write-Output 'Hi'
TimeZone westeustandard {
IsSingleInstance = 'Yes'
TimeZone = 'W. Europe Standard Time'
}
}
timezone
8) Let's compile the ps1 script
ps> . ./time-conf.ps1
The compile should create a folder called timezone. This folder should have a mof file called localhost.mof
9) Copy the ps1 script (time-conf.ps1) and the timezone folder to the terraform code directory and use it in the terraform code.
No comments:
Post a Comment