Skip to content

Instantly share code, notes, and snippets.

View dtelaroli's full-sized avatar

Denilson Telaroli dtelaroli

View GitHub Profile
@dtelaroli
dtelaroli / add_depends_on_to_files.sh
Last active November 14, 2022 12:24
script which splits terraform states and adds depends_on to some resources
grep -E 'resource.+"codefresh_project"' ./squads/**/*.tf | sed -E 's/([a-z_\/]+):.+" "(.+)" {/\1:\2/g' |
while IFS=":"; read -r key value; do
export key=$key value=$value
cat $key | grep name | sed -E 's/.+name.+\"(.+)\"/\1/g' |
xargs -I{} grep -E 'project_name.+"{}"' ./squads/**/*.tf | sed -E 's/([a-z\/_-]+):.+/\1/g' > tmp.txt
while read file; do
if [ -z "$(grep depends_on $file)" ]; then
replace="\ndepends_on = [codefresh_project.${value}]\n}"
perl -i"" -pe "s/^}/${replace}/g" $file
terraform fmt $file
@dtelaroli
dtelaroli / main.tf
Created October 7, 2022 17:10
workaround to list all directories in a specific folder in terraform
locals {
subfolders = toset(distinct(flatten([for _, v in fileset(".", "./dir/**") : regex("./dir/([^/]*).*", dirname(v))])))
}
@dtelaroli
dtelaroli / script.sh
Created July 28, 2022 15:04
How to fix SunCertPathBuilderException: unable to find valid certification path to requested target in MacOS
# step 1
# execute the command to get the certificates
openssl s_client -showcerts -connect start.spring.io:443
# copy the lines stating in: Certificate chain (including this line)
# Ending in last -----END CERTIFICATE-----
# step 2
# create the cert file with this content
mkdir $HOME/certs
@dtelaroli
dtelaroli / clean-tf-state.js
Last active December 14, 2021 20:29
Script in node to cleanup terraform state file based on terraform file
# $1 parameter inverse (true|false)
# inverse true remove what is in tf file
# inverse false remove what is not in tf file
# command: node clean-tf-state.js [true|false]
const json = require("./state.json")
const fs = require('fs')
const inverse = process.argv[1]

Keybase proof

I hereby claim:

  • I am dtelaroli on github.
  • I am dtelaroli (https://keybase.io/dtelaroli) on keybase.
  • I have a public key ASB80HHC08K7bPObA78PeVBwIa6Jc4cWL6tFvu-7TdLO6Ao

To claim this, I am signing this object:

@dtelaroli
dtelaroli / script.sh
Last active November 12, 2020 01:54
mac osx enable and disable aac aptx codecs
#read
sudo defaults read bluetoothaudiod
# disable
sudo defaults write bluetoothaudiod "Enable AAC codec" -bool false
sudo defaults write bluetoothaudiod "Enable AptX code" -bool false
# restart
# enable
sudo defaults write bluetoothaudiod "Enable AAC codec" -bool true
@dtelaroli
dtelaroli / elastisearch.json
Created September 4, 2020 00:31
ElasticSearch error Fielddata is disabled on text fields by default. Set fielddata=true on [field] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.
PUT <index>/_mapping/doc
{
"properties": {
"field": {
"type": "text",
"fielddata": true
}
}
}
@dtelaroli
dtelaroli / policy.json
Created August 23, 2020 18:49
AWS ElasticSearch Service policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<accountId>:role/<authRoleArn>"
},
"Action": "es:*",
"Resource": "<ESDomainArn>/*"
@dtelaroli
dtelaroli / lambda-get-identity-id.js
Created August 4, 2020 17:18
How to get identity id from cognito with jwt token
// npm install await-to-js
const { to } = require("await-to-js");
const { CognitoIdentity } = require("aws-sdk");
const identity = new CognitoIdentity();
const IDENTITY_POOL_ID = "<your identity pool id>";
exports.handler = async (event) => {
const { issuer } = event.identity;
@dtelaroli
dtelaroli / amplify-create-subdomain.js
Created July 14, 2020 18:24
Creates an amplify subdomain with aws javascript sdk
const { to } = require("await-to-js");
const { Amplify } = require("aws-sdk");
const amplify = new Amplify();
const config = {
AMPLIFY_FRONTEND_APP_ID: "your_app_id",
AMPLIFY_FRONTEND_DOMAIN: "your_domain.com",
AMPLIFY_FRONTEND_BRANCH: "your_branch_env"
};