GoogleCloudPlatform / google-cloud-powershell

PowerShell cmdlets for the Google Cloud Platform
http://googlecloudplatform.github.io/google-cloud-powershell/
Apache License 2.0
135 stars 61 forks source link

Someone Letme know how to pass a service account in Powershell #573

Closed cmreddyv closed 6 years ago

cmreddyv commented 6 years ago

Hi,

I am using PowerShell to create the gcloud environment, i have a startup script in bucket storage and when creating an instance the script is not able to download because of lack of permissions to the service account. I am not sure how to pass the service account parameter in the PowerShell.

Here is the snippet of my code:

$disk = Get-GceImage "windows-cloud" -Family "windows-2016" | New-GceDisk $diskname -SizeGb 100 -DiskType pd-standard

$config = New-GceInstanceConfig $machinename -MachineType $machinetype -BootDisk $disk -

$config | Add-GceInstance -ServiceAccount <what to pass here?>

Set-GceInstance $machinename -AddMetadata @{"windows-startup-script-url" = "storage url"

quoctruong commented 6 years ago

@cmreddyv Please use New-GceServiceAccountConfig to create a service account object. You can then pass that object to the Add-GceInstance cmdlet.

cmreddyv commented 6 years ago

@quoctruong , every time i should create a newservice account config? can't i use the one which is already created, if you see when you run gcloud compute it will automatically selects the service account, similarly i want it in Powershell

cmreddyv commented 6 years ago

able to fix it.

cmreddyv commented 6 years ago

$serviceaccount = New-GceServiceAccountConfig -Email 'XXXXX' -Storage ReadWrite

Add-GceInstance -Name $machinename -BootDisk $disk -MachineType $machinetype -ServiceAccount $serviceaccount