Error installing sql server enterprise using packer

I am getting below error while doing the installation on ec2 instance and trying to install sql server 2019 enterprise edition. I am able to install it on ec2 manually. but its throwing error while installation from packer.

Below is the summary of error messages I am getting in the logs:

  1. The directory monitor thread is interrupted due to the following exception while monitoring the notifications for directory ‘C:\Program Files (x86)’

  2. Error: Action “Microsoft.SqlServer.Configuration.SmartSetupExtension.SearchUpdatesAction” threw an exception during execution.e[0m
    2023-07-03T16:42:46.0622412Z e[0;32m amazon-ebs.windows: Microsoft.SqlServer.Setup.Chainer.Workflow.ActionExecutionException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) —> System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005

  3. Attempting to write hklm registry key Microsoft SQL Server to file C:\Program Files\Microsoft SQL Server\150\Setup Bootstrap\Log\20230703_163831\Registry_SOFTWARE_Microsoft_Microsoft SQL Server.reg_e[0m
    2023-07-03T16:42:46.0679497Z e[0;32m amazon-ebs.windows: Sco: Attempting to write hklm registry key Uninstall to file C:\Program Files\Microsoft SQL Server\150\Setup Bootstrap\Log\20230703_163831\Registry_SOFTWARE_Microsoft_Windows_CurrentVersion_Uninstall.reg_e[0m
    2023-07-03T16:42:46.0681120Z e[0;32m amazon-ebs.windows: Sco: Unable to open hklm registry key SOFTWARE\Microsoft\MSSQLServer, error The system cannot find the file specified.

  4. Exception type: Microsoft.SqlServer.Chainer.ExtensionCommon.JobExecutionExceptione[0m
    2023-07-03T16:42:46.1048104Z e[0;32m amazon-ebs.windows: Message:e[0m
    2023-07-03T16:42:46.1049818Z e[0;32m amazon-ebs.windows: Setup encountered a failure while running job UpdateResult.e[0m
    2023-07-03T16:42:46.1050751Z e[0;32m amazon-ebs.windows: HResult : 0x876e0003e[0m
    2023-07-03T16:42:46.1051575Z e[0;32m amazon-ebs.windows: FacilityCode : 1902 (76e)e[0m
    2023-07-03T16:42:46.1052375Z e[0;32m amazon-ebs.windows: ErrorCode : 3 (0003)e[0m

  5. Attempting to write hklm registry key Microsoft SQL Server to file C:\Program Files\Microsoft SQL Server\150\Setup Bootstrap\Log\20230703_163831\Registry_SOFTWARE_Microsoft_Microsoft SQL Server.reg_e[0m
    2023-07-03T16:42:46.1244632Z e[0;32m amazon-ebs.windows: Sco: Attempting to write hklm registry key Uninstall to file C:\Program Files\Microsoft SQL Server\150\Setup Bootstrap\Log\20230703_163831\Registry_SOFTWARE_Microsoft_Windows_CurrentVersion_Uninstall.reg_e[0m
    2023-07-03T16:42:46.1245405Z e[0;32m amazon-ebs.windows: Sco: Unable to open hklm registry key SOFTWARE\Microsoft\MSSQLServer, error The system cannot find the file specified.

I am provisioning an ec2 system → downloading the setup files from our jfrog artifactory → executing setup.exe with configuration present in Configuration.ini file. → creating an ami with this and using this ami setting up another ec2 instance

It completed successfully but I am getting above mentioned errors in the logs and also when creating final ec2 instance for my use I could not see complete installation.

With manual installation I could find below packages in add\remove programs:

  1. Microsoft Visual Studio Tools for Applications 2019
  2. Microsoft SQL Server 2019 Setup (English)
  3. Microsoft SQL Server 2019 (64-bit)
  4. Browser for SQL Server 2019
  5. Microsoft SQL Server 2019 T-SQL Language Service
  6. Microsoft VSS Writer for SQL Server 2019

and with packer only getting on packe installed:

  1. Microsoft Visual Studio Tools for Applications 2019

Complete error details:

sql-server-packer error details.txt (28.7 KB)