Skip to content

Instantly share code, notes, and snippets.

View mesmacosta's full-sized avatar
🏠
Working from home

Marcelo Costa mesmacosta

🏠
Working from home
View GitHub Profile
{
"kind": "compute#instance",
"name": "instance-1",
"zone": "projects/your-project/zones/us-central1-a",
"machineType": "projects/your-project/zones/us-central1-a/machineTypes/f1-micro",
"displayDevice": {
"enableDisplay": false
},
"metadata": {
"kind": "compute#metadata",
gcloud logging write batch-execution "Hello world from $(hostname)."
gcp_zone=$(curl -H Metadata-Flavor:Google http://metadata.google.internal/computeMetadata/v1/instance/zone -s | cut -d/ -f4)
gcloud compute instances delete $(hostname) --zone ${gcp_zone}
const Buffer = require('safe-buffer').Buffer;
const Compute = require('@google-cloud/compute');
const compute = new Compute();
// Change this const value to your project
const projectId = 'your-project';
const zone = 'us-central1-a';
const vmConfig = {
kind: 'compute#instance',
{
"name": "cloud-functions-create-batch-workload-vm",
"version": "0.0.1",
"private": true,
"license": "Apache-2.0",
"author": "Marcelo Costa",
"main": "index.js",
"engines": {
"node": ">=8.13.0"
},
@mesmacosta
mesmacosta / compute_vm.js
Last active August 13, 2019 23:38
Files used in the medium series
{
"kind": "compute#instance",
"name": "instance-1",
"zone": "projects/your-project/zones/us-central1-a",
"machineType": "projects/your-project/zones/us-central1-a/machineTypes/f1-micro",
"displayDevice": {
"enableDisplay": false
},
"metadata": {
"kind": "compute#metadata",
@mesmacosta
mesmacosta / create_service_account.sh
Last active March 30, 2020 12:57
Shows how to create a service account that uses a custom role
# If you receive any error while running the commands bellow, create the Service Account using the Cloud Console UI.
# The Roles and Permissions are the same in the UI.
# Change the PROJECT_ID value to your project
PROJECT_ID=your-project-id
SERVICE_ACCOUNT_NAME=compute-execute-batch-job
# Create the service account
gcloud beta iam service-accounts create ${SERVICE_ACCOUNT_NAME} \
--description "SA that will be used by the Compute Engine VM" \
@mesmacosta
mesmacosta / Billing
Created August 31, 2019 22:08
Cloud Functions
https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/functions/billing/main.py
import json
with open('data.json', 'w') as outfile:
json.dump(obj, outfile)
#!/bin/bash
echo "Beginning Entrypoint script execution."
output=$(behave ./features --tags=-wip)
status=$?
echo "Behave finished executing."
# Change this to your project
@mesmacosta
mesmacosta / create_instance_function_with_container_image.js
Created September 7, 2019 18:37
create_compute_vm_with_container_image
const Buffer = require('safe-buffer').Buffer;
const Compute = require('@google-cloud/compute');
const compute = new Compute();
// Change this const value to your project
const projectId = 'my-project';
const zone = 'us-central1-a';
const vmConfig = {
kind: 'compute#instance',