Skip to content

Instantly share code, notes, and snippets.

View jnahelou's full-sized avatar

jnahelou

View GitHub Profile
@jnahelou
jnahelou / sample.py
Last active August 25, 2022 09:49
medium logging
import logging
import requests
import json
from opentelemetry.instrumentation.logging import LoggingInstrumentor
metadata_server = "http://metadata/computeMetadata/v1/"
metadata_flavor = {'Metadata-Flavor': 'Google'}
project_id = requests.get(
metadata_server + 'project/project-id', headers=metadata_flavor).text
receivers: [0/45]
elasticsearch/elasticsearch_elasticsearch:
collection_interval: 30s
endpoint: https://my-deployment-<CHANGEME>.es.europe-west1.gcp.cloud.es.io
nodes: ["_local"]
password: <CHANGEME>
skip_cluster_metrics: false
tls:
insecure: false
username: elastic
@jnahelou
jnahelou / main.py
Last active May 12, 2022 16:08
List users with ssh keys
import googleapiclient.discovery
compute_v1 = googleapiclient.discovery.build(
"compute", "v1", cache_discovery=False
)
project_id = "<project_id>"
project_info = compute_v1.projects().get(project=project_id).execute()
@jnahelou
jnahelou / ci.yml.j2
Last active October 26, 2021 12:27
python cookiecutter ci example
name: CI
on:
push:
pull_request:
branches: [master]
jobs:
Quality:
runs-on: ubuntu-latest
steps:
@jnahelou
jnahelou / monitoring.tf.j2
Last active October 26, 2021 12:27
Draft cookiecutter template to monitore cloud functions
{%- if cookiecutter.use_monitoring == "datadog" %}
provider "datadog" {
api_url = "https://api.datadoghq.eu/"
}
resource "datadog_monitor" "alert-slack" {
name = "{{cookiecutter.project_name}} function errored"
type = "metric alert"
message = "{{cookiecutter.project_name}} completion in error !"
query = "sum(last_5m):sum:gcp.cloudfunctions.function.execution_count{function_name:${var.function_name},status:error,project_id:${var.project_id}}.as_count() > 0"
@jnahelou
jnahelou / .terraformrc
Created July 27, 2021 15:51
override provider in terraform 0.14+
provider_installation {
dev_overrides {
"registry.terraform.io/grafana/grafana" = "<path_to_binary>"
}
direct {}
}
@jnahelou
jnahelou / medium.tf
Created July 27, 2021 15:48
code sample - grafana medium story
terraform {
required_providers {
grafana = {
source = "grafana/grafana"
}
}
}
resource "grafana_dashboard" "test" {
config_json = <<EOD
{
@jnahelou
jnahelou / main.tf
Created October 16, 2020 22:11
hello provider
terraform {
required_providers {
hello = {
source = "registry1.jnahelou.net/jnahelou/hello"
}
}
}
provider "hello" {
nickname = "jnahelou"
@jnahelou
jnahelou / mirror_auth.patch
Last active October 16, 2020 20:55
Terraform patch to add authentication headers during provider download
diff --git a/command/providers_mirror.go b/command/providers_mirror.go
index 029b08630..db0760d95 100644
--- a/command/providers_mirror.go
+++ b/command/providers_mirror.go
@@ -4,6 +4,8 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
+ "log"
+ "net/http"
@jnahelou
jnahelou / inspec-iggy-tf0.12.patch
Last active October 18, 2019 09:50
Patch to use inspec-iggy with terraform 0.12
--- gems/2.5.0/gems/inspec-iggy-0.6.0/lib/inspec-iggy/terraform/generate.rb 2019-08-08 13:27:19.494150516 +0200
+++ gems/2.5.0/gems/inspec-iggy-0.6.0/lib/inspec-iggy/terraform/generate.rb 2019-10-18 11:46:58.920277083 +0200
@@ -30,31 +30,31 @@
def self.parse_resources(tfstate, resource_path, _platform)
# iterate over the resources
resources = {}
- tfstate['modules'].each do |m|
- tf_resources = m['resources']
- tf_resources.keys.each do |tf_res|
- resource_type = tf_resources[tf_res]['type']