Creates a new google cloud compute instance using google apis and a simple golang app to provide authentication via service account key file.
An example workflow that creates an example instance named example-instance-name in the us-central1-a zone.
id: gcloud-new-compute-instance
description: "Creates new gcp project instance"
functions:
- id: gcp-new-intance
image: direktiv/gcloud-instance-create:v1
size: medium
states:
- id: createInstance
type: action
action:
function: gcp-new-intance
input: jq(.)
The input needed to run the above workflow properly is the following:
input:
project: "GCP_PROJECT"
serviceAccountKey: "SERVICE_ACCOUNT_KEY"
name: "example-instance-name"
zone: "us-central1-a"
machineType: "e2-medium"
image: "example_image"
When authenticating with the gcloud nothing will be logged to the stdout of the container.
The SERVICE_ACCOUNT_KEY is a string of a Google Cloud service account json key.
To generate a service account key please refer to Google Clouds documentation.
There are additional fields that can be also used in the input for more control over the created instance.
| Field | Description | Type | Default Value |
|---|---|---|---|
| diskType | Specify what Google Compute Engine disk type to use | String | pd-balanced |
| externalIP | Whether if instance should be created with an external IP | Boolean | false |
| tags | Tags for the created instance | String Array | [] |
| imageProject | GCP project where image is stored. | String | same as "project" field |
The output will be in JSON format if successful, otherwise an error will be outputed to the logs.
Below is an example output of a successful instance creations with sensitive information removed:
{
"return": {
"id": "**********************",
"insertTime": "2021-04-06T17:36:11.511-07:00",
"kind": "compute#operation",
"name": "**************************************",
"operationType": "insert",
"progress": 0,
"selfLink": "https://www.googleapis.com/compute/v1/projects/****/zones/us-central1-a/operations/******************************",
"startTime": "2021-04-06T17:36:11.513-07:00",
"status": "RUNNING",
"targetId": "**************************",
"targetLink": "https://www.googleapis.com/compute/v1/projects/****/zones/us-central1-a/instances/********************",
"user": "********************************************",
"zone": "https://www.googleapis.com/compute/v1/projects/****/zones/us-central1-a"
}
}
In the case that an error is encountered, it will present in the following format:
{
"errorCode": "com.gcloud-instance-create.error",
"errorMsg": "Something went wrong"
}
Content type
Image
Digest
sha256:ea1bf6bc1…
Size
2.9 MB
Last updated
about 4 years ago
docker pull westwind027/gcloud-instance-create