Skip to content

Instantly share code, notes, and snippets.

@minherz
minherz / gist:ed59b2bac559ae8b66e1ccefd087f524
Last active June 3, 2019 05:31
TF_LOG=trace terraform init output
2019/06/03 08:29:00 [INFO] Terraform version: 0.11.14
2019/06/03 08:29:00 [INFO] Go runtime version: go1.12.4
2019/06/03 08:29:00 [INFO] CLI args: []string{"/usr/bin/terraform", "init"}
2019/06/03 08:29:00 [DEBUG] Attempting to open CLI config file: /home/acme/.terraformrc
2019/06/03 08:29:00 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2019/06/03 08:29:00 [INFO] CLI command args: []string{"init"}
2019/06/03 08:29:00 [DEBUG] command: loading backend config file: /home/acme/workdir/terraform-labs/getting-started
Initializing the backend...
2019/06/03 08:29:00 [TRACE] Preserving existing state lineage "c7d18213-da77-bbef-ed78-34740d2651f5"
@minherz
minherz / main.py
Created January 22, 2021 16:42
call Kubernetes API get nodes
resp = requests.get(url='https://kubernetes.default.svc/api/v1/nodes/' + node_name,
headers={'Authorization': 'Bearer ' + auth_token}, verify=False)
@minherz
minherz / main.py
Created January 22, 2021 16:43
initialize Google client library in Python
creds, project_id = google.auth.default(scopes=['https://www.googleapis.com/auth/compute'])
compute = googleapiclient.discovery.build('compute', 'v1', credentials=creds)
@minherz
minherz / main.py
Created January 22, 2021 16:45
set GCE instance labels using Google client library in Python
resp = compute.instances().get(project=project_id, zone=zone, instance=instance_name).execute()
if 'error' in resp:
print('Failed to get GCE instance info')
exit(1)
fingerprint = resp['labelFingerprint']
resp = compute.instances().setLabels(project=project_id, zone=zone, instance=instance_name,
body={'labelFingerprint': fingerprint,
'labels': labels}).execute()
@minherz
minherz / rbac.yml
Created January 22, 2021 16:52
example of rbac setting
apiVersion: v1
kind: ServiceAccount
metadata:
name: node-labeling-robot
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: node-info-reader
@minherz
minherz / daemonset.yml
Created January 22, 2021 16:55
Deploy solution as a daemonset
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: node-labeling
labels:
app: node-labeling
spec:
selector:
matchLabels:
app: node-labeling
@minherz
minherz / wait_startup_script_to_exit.sh
Last active May 4, 2021 14:15
Bash script function to wait until the startup script finishes execution and logs it into /var/log/syslog
wait_startup_script_to_finish() {
vm_name=$1
vm_zone=$2
echo -n "Wait for \"$vm_name\" startup script to exit."
status=""
while [[ -z "$status" ]]
do
sleep 3;
echo -n "."
status=$(gcloud compute ssh $vm_name --zone=$vm_zone --ssh-flag="-q" --command 'grep -m 1 "startup-script exit status" /var/log/syslog' 2>&-)
@minherz
minherz / wait_startup_script_to_exit.sh
Created May 4, 2021 14:14
Wait until startup script logs it is finished with time threshold
wait_startup_script_to_finish() {
vm_name=$1
vm_zone=$2
threshold=$(date --date="-5 min" "+%b %_d %H:%M:%S")
echo -n "Wait for \"$vm_name\" startup script to exit."
status=""
while [[ -z "$status" ]]
do
sleep 3;
echo -n "."
<?xml version='1.0' encoding='UTF-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud</groupId>
<artifactId>examples-testbed-local</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>Test Local Environment Examples</name>
<!--
2022-10-03T18:53:36.321-0700 [INFO] Terraform version: 1.3.1
2022-10-03T18:53:36.321-0700 [DEBUG] using github.com/hashicorp/go-tfe v1.9.0
2022-10-03T18:53:36.321-0700 [DEBUG] using github.com/hashicorp/hcl/v2 v2.14.1
2022-10-03T18:53:36.321-0700 [DEBUG] using github.com/hashicorp/terraform-config-inspect v0.0.0-20210209133302-4fd17a0faac2
2022-10-03T18:53:36.321-0700 [DEBUG] using github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
2022-10-03T18:53:36.321-0700 [DEBUG] using github.com/zclconf/go-cty v1.11.0
2022-10-03T18:53:36.321-0700 [INFO] Go runtime version: go1.19.1
2022-10-03T18:53:36.321-0700 [INFO] CLI args: []string{"terraform", "apply", "-auto-approve"}
2022-10-03T18:53:36.321-0700 [TRACE] Stdout is a terminal of width 111
2022-10-03T18:53:36.321-0700 [TRACE] Stderr is a terminal of width 111