Search code examples
google-cloud-platformjinja2google-deployment-manager

Setting Username and Password to Windows VM from GCP deployment manager with Jinja2


I am new to GCP and trying to create a Windows VM instance from GCP deployment manager.

I want to set username and password for the VM instance through deployment manager. Here I am using Jinja2 as deployment language.


Solution

  • GCP does not set the username and passwords on GCP. The best way to get a user and password set at VM creation is through the use of metadata startup scripts

    Since you just want to create the user, you will likely want to use the sysprep-specialize-script-ps1 field so that the command only runs on creation (not on every startup). For the value, write a powershell script that will create a user add it to the appropriate group (likely administrators) Here is an example:

    sysprep-specialize-script-ps1 = "$Password = ConvertTo-SecureString -String {{ password }} -AsPlainText -Force\n\nNew-LocalUser -name {{ user }} -Password $Password\n\nAdd-LocalGroupMember -Group Administrators -Member {{ user }}"