hashicorp / packer-plugin-googlecompute

Packer plugin for Google Compute Builder
https://www.packer.io/docs/builders/googlecompute
Mozilla Public License 2.0
24 stars 54 forks source link

Add support to windows-startup-script-ps1 on Packer GCP (Terraform already supports this feature) #27

Open hc-github-team-packer opened 3 years ago

hc-github-team-packer commented 3 years ago

This issue was originally opened by @lmayorga1980 in https://github.com/hashicorp/packer/issues/10342 and has been migrated to this repository. The original issue description is below.


Description

According to https://www.packer.io/docs/builders/googlecompute.html#windows, is only possible to use the windows-startup-script-cmd when using GCP as the builder. Would it be possible to use an existing powershell script?

Use Case(s)

Powershell script uses a combination of cmdlets and native windows executables.

Potential configuration

metadata": { "windows-startup-script-ps1":  "scripts/user_data.ps1" },
TigerC10 commented 3 years ago

This confuses me. Both windows-startup-script-ps1 and windows-startup-script-cmd are VM custom metadata. When packer creates the VM, you can assign any metadata that you want. Why wouldn't windows-startup-script-ps1 already work?

lmayorga1980 commented 2 years ago

@SwampDragons,

Any news about this?

smartyr73 commented 1 year ago

I can comment on this. I can confirm windows-startup-script-ps1 does work, as I am already using this successfully. I just reference it in a local file and not inline.

I just use the following block (In HCL) and this works just fine. Whether it is by accident or design I am not sure.

metadata_files = { "winows-startup-script-ps1" = "file_path" } I am happy to provide evidence/logs if needed.

lmayorga1980 commented 9 months ago

I can comment on this. I can confirm windows-startup-script-ps1 does work, as I am already using this successfully. I just reference it in a local file and not inline.

I just use the following block (In HCL) and this works just fine. Whether it is by accident or design I am not sure.

metadata_files = { "winows-startup-script-ps1" = "file_path" } I am happy to provide evidence/logs if needed.

    metadata_files = {
    "sysprep-specialize-script-ps1" = "${path.root}/boot.ps1"
  }

I have this issue

2023/11/30 13:25:35 GCEMetadataScripts: Found sysprep-specialize-script-ps1 in metadata.
2023/11/30 13:25:35 GCEMetadataScripts: sysprep-specialize-script-ps1: 'b' is not recognized as an internal or external command,
2023/11/30 13:25:35 GCEMetadataScripts: sysprep-specialize-script-ps1: operable program or batch file.
2023/11/30 13:25:36 GCEMetadataScripts: sysprep-specialize-script-ps1: There is no such global user or group: packer_user.
2023/11/30 13:25:36 GCEMetadataScripts: sysprep-specialize-script-ps1:
2023/11/30 13:25:36 GCEMetadataScripts: sysprep-specialize-script-ps1: More help is available by typing NET HELPMSG 3783.
2023/11/30 13:25:36 GCEMetadataScripts: sysprep-specialize-script-ps1:
2023/11/30 13:25:36 GCEMetadataScripts: sysprep-specialize-script-ps1: ERROR:
2023/11/30 13:25:36 GCEMetadataScripts: sysprep-specialize-script-ps1: Description = Invalid query
2023/11/30 13:25:36 GCEMetadataScripts: sysprep-specialize-script-ps1 exit status 0
2023/11/30 13:25:36 GCEMetadataScripts: Finished running specialize scripts.

boot.ps1

cmd.exe /c net user /add packer "*****"
cmd.exe /c net localgroup administrators packer /add
cmd.exe /c wmic UserAccount where Name="packer" set PasswordExpires=False