profile for Gajendra D Ambi on Stack Exchange, a network of free, community-driven Q&A sites

Wednesday, April 4, 2018

Deploying instances on gcp (google cloud platform) via powershell

This is that time. That time where I put my hands inside the gcp cookie jar and try to see what I find.
Make sure you have done this https://www.cloudishes.com/2018/04/setting-up-your-machine-for-gcp-google.html first though.
You also have to log into your gcp and enable google compute API. I think is a nice touch by gcp. You decide which of your services should have API access and which shouldnt. May be you can have some people or applications have API access and some don't. In this way you can get this configured. More on that later. May be... Below is a screen grab of my API board.

and ya...wait for a while btw after this, otherwise you will get this.

Add-GceInstance : Google.Apis.Requests.RequestError
Access Not Configured. Compute Engine API has not been used in project 1234567 before or it is disabled. Enable it by visiting 
https://console.developers.google.com/apis/api/compute.googleapis.com/overview?project=1234567 then retry. If you enabled this API 
recently, wait a few minutes for the action to propagate to our systems and retry. [403]
Errors [
 Message[Access Not Configured. Compute Engine API has not been used in project 1234567 before or it is disabled. Enable it by visiting 
https://console.developers.google.com/apis/api/compute.googleapis.com/overview?project=1234567 then retry. If you enabled this API 
recently, wait a few minutes for the action to propagate to our systems and retry.] Location[ - ] Reason[accessNotConfigured] 
Domain[usageLimits]
]
At line:16 char:20
+ ... ta_Config | Add-GceInstance -Project $project -Zone $zone -Region $re ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-GceInstance], GoogleApiException
    + FullyQualifiedErrorId : Google.GoogleApiException,Google.PowerShell.ComputeEngine.AddGceInstanceCmdlet
Now let us list out the images that we have there first. We want to deploy a tiny one first since I can't afford to pay for games, cloud costs :|.

PS C:\WINDOWS\system32> Get-GceImage | select Family

Family                          
------                          
centos-6                        
centos-7                        
coreos-alpha                    
coreos-beta                     
coreos-stable                   
debian-8                        
debian-9                        
debian-8                        
debian-9                        
rhel-6                          
rhel-7                          
sles-11                         
sles-12                         
ubuntu-1404-lts                 
ubuntu-1604-lts                 
ubuntu-1710                     
windows-1709-core-for-containers
windows-1709-core               
windows-2008-r2                 
windows-2012-r2-core            
windows-2012-r2                 
windows-2016-core               
windows-2016                    
sql-ent-2012-win-2012-r2        
sql-std-2012-win-2012-r2        
sql-web-2012-win-2012-r2        
sql-ent-2014-win-2012-r2        
sql-ent-2014-win-2016           
sql-std-2014-win-2012-r2        
sql-web-2014-win-2012-r2        
sql-ent-2016-win-2012-r2        
sql-ent-2016-win-2016           
sql-std-2016-win-2012-r2        
sql-std-2016-win-2016           
sql-web-2016-win-2012-r2        
sql-web-2016-win-2016           
sql-ent-2017-win-2016           
sql-exp-2017-win-2012-r2        
sql-exp-2017-win-2016           
sql-std-2017-win-2016           
sql-web-2017-win-2016           
Let us select the one which is highlighted.
I also needed to choose a zone and a region associated with that. Check this out.
https://cloud.google.com/compute/docs/regions-zones/


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
$vm_name = 'ubuntuDummy' # name of the instance
$machine_type = 'Linux' # Description of the instance
$project = 'dummies' # name of my project which i created from the gcp console

# go here https://cloud.google.com/compute/docs/regions-zones/ and choose
$zone = 'us-east1-b' 
$region = 'us-east1'

# choosing an image from the list of google images
$myImage = Get-GceImage | where Family -Match 'ubuntu-1404-lts'
# create a configuration for our instance
$my_insta_Config = New-GceInstanceConfig $vm_name -MachineType $machine_type -DiskImage $myImage -Region $region

# deploy our instance
$my_insta_Config | Add-GceInstance -Project $project -Zone $zone -Region $region

Good luck.

Resources:
https://cloud.google.com/compute/docs/regions-zones/
https://support.google.com/cloud/answer/6158841?hl=en
http://googlecloudplatform.github.io/google-cloud-powershell/#/

No comments:

Post a Comment