"builders": [
{
"type": "azure-arm",
"client_id": "{{user `client_id`}}",
"client_secret": "{{user `client_secret`}}",
"tenant_id": "{{user `tenant_id`}}",
"subscription_id": "{{user `subscription_id`}}",
"managed_image_resource_group_name": "GoldenImages",
"managed_image_name": "Golden-SQL2016SP2",
"os_type": "Windows",
"image_publisher": "MicrosoftSQLServer",
"image_offer": "SQL2016SP2-WS2016",
"image_sku": "Enterprise",
"virtual_network_name": "{{user `virtual_network_name`}}",
"virtual_network_subnet_name": "{{user `virtual_network_subnet_name`}}",
"virtual_network_resource_group_name": "{{user `virtual_network_resource_group_name`}}",
"communicator": "winrm",
"winrm_use_ssl": true,
"winrm_insecure": true,
"winrm_timeout": "6m",
"winrm_username": "{{user `winrm_username`}}",
"azure_tags": {
"BAC" : "",
"ResourceContact" : "",
"Environment" : "{{user `environment`}}"
},
"location": "{{user `location`}}",
"vm_size": "Standard_DS3_v2"
}
],
"provisioners": [
{
"type": "powershell",
"environment_vars":
[
"ARTIFACTORYCREDS={{user `artifactory_creds`}}"
],
"scripts": [
"./scripts/sql2016/install_java.ps1"
]
},
{
"type": "powershell",
"environment_vars":
[
"ARTIFACTORYCREDS={{user `artifactory_creds`}}"
],
"scripts":
[
"./scripts/sql2016/install_cis_cat.ps1"
]
},
{
"type": "powershell",
"scripts":
[
"./scripts/sql2016/install_pscp.ps1"
]
},
{
"type": "file",
"source": "./scripts/sql2016",
"destination": "c:\\Users\\packer\\",
"direction" : "upload"
},
{
"type": "windows-restart",
"restart_check_command": "powershell -command \"& {Write-Output 'restarted.'}\""
},
{
"type": "powershell",
"environment_vars": [
"WINRMUSER= {{user `winrm_username`}}"
],
"scripts": [
"./scripts/sql2016/harden_image.ps1"
]
}
]
}
This is what it looks at the moment.
I need to be able to add at least one more powershell script in Provisioners that will create a test database in the VM that packer creates, as well as get the connection string that I can pass to CIS-CAT for the scan.
When run locally this is how the cis-cat command looks like, ".\CIS-CAT.BAT -b benchmarks\CIS_Microsoft_SQL_Server_2016_Benchmark_v1.0.0-xccdf.xml -p ""Level 1 - Database Engine"" -D xccdf_org.cisecurity_value_jdbc.url=jdbc:jtds:sqlserver://localhost:1433/master;domain=SQLSERVER;user=testadmin;password=password -a -r ."
How can I pass the username and password when using winrm and packer?
I'm confused as to how I can achieve this using Packer. Just need some direction.