Skip to content

Instantly share code, notes, and snippets.

View giuliocalzolari's full-sized avatar

Giulio Calzolari giuliocalzolari

View GitHub Profile
@giuliocalzolari
giuliocalzolari / vault-acme-plugin.sh
Last active June 13, 2022 07:21
Vault + Let's encrypt integration
# source https://github.com/remilapeyre/vault-acme
wget https://github.com/remilapeyre/vault-acme/releases/download/v0.0.8/linux_amd64.zip -O /tmp/acme.zip
unzip /tmp/acme.zip -d /tmp/
mv /tmp/acme-plugin /opt/vault/plugins/
chmod vault:vault /opt/vault/plugins/acme-plugin
sudo setcap cap_ipc_lock=+ep /opt/vault/plugins/acme-plugin
vault write sys/plugins/catalog/secret/acme sha_256=29b5d33532cd55fddd5de199c4717683ccc3957bf8d8fe645974be984c1abd5a command=acme-plugin
vault secrets enable -path acme -plugin-name acme plugin
@giuliocalzolari
giuliocalzolari / lambda_poweroff_ec2_all_region.py
Last active February 15, 2022 14:28
Lambda poweroff ec2 across all regions
from datetime import datetime, timedelta, time
import boto3
# last update 2022/02/15
TIME = {
"eu-central-1": {
"description": "Europe(Frankfurt)",
"permitted_ec2_time": "8-19",
"utc_offset": "+1"
@giuliocalzolari
giuliocalzolari / run.sh
Last active October 13, 2021 07:55
quick port check
</dev/tcp/10.228.196.124/22 && echo "Port is open" || echo "Port is closed"
@giuliocalzolari
giuliocalzolari / aws-backup.yaml
Last active November 13, 2019 13:50 — forked from quiver/cloudformation-template-for-aws-backup-thin-backups.yaml
CloudFormation template to configure thin backup rules for AWS Backup
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Create AWS Backup Vault, Backup Plan and Backup Selection
Parameters:
# Backup
CreateNewBackupVault:
Type: String
AllowedValues:
- true
- false
@giuliocalzolari
giuliocalzolari / Cloudwatch Agent Install
Last active April 29, 2024 03:08 — forked from naavveenn/Cloudwatch Agent Install
Cloudwatch agent installation: Make sure to attach a cloudwatch role to your ec2 instance. amazon-cloudwatch-agent.json file should be created before hand (on your local machine or from where you are executing your ansible playbook), other wise cw_agent will not start. Below is the example of amazon-cloudwatch-agent.json.
---
###Cloudwatch role should be attached to the ec2 instance###
- hosts: dd ###servers on which you need to run the cw_agent
become: yes
remote_user: root
gather_facts: true
tasks:
- name: Check if Cloudwatch Agent is Installed Already
shell: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status
register: init_status_result
@giuliocalzolari
giuliocalzolari / linux-vmimport_checker.sh
Last active May 8, 2024 15:20
AWS IMPORT VM Checker
#!/bin/bash
##########################################################################################
# AWS VM Import Instance Checker 1.2 #
# #
# The script has been implemented to simplify the VM Import process of the virtual #
# environment in AWS. #
# #
# The script checks that the requirements to import a VM in AWS are verified. #
# Please make a backup of the VM before to proceed. #
@giuliocalzolari
giuliocalzolari / .gitlab-ci.yml
Created April 10, 2019 13:19
terraform .gitlab-ci.yml
# source https://github.com/radekg/terraform-provisioner-ansible
image:
name: rflume/terraform-aws-ansible:latest
stages:
# 'global' stages
- validate global
- plan global
- apply global
# Dev env stages
@giuliocalzolari
giuliocalzolari / UserData.ps1
Last active February 8, 2019 10:47
EC2 UserData - AD autojoin
<powershell>
$password = (Get-SSMParameter -Name /ds/svc_password -WithDecryption $true).Value | ConvertTo-SecureString -asPlainText -Force
$username = (Get-SSMParameter -Name /ds/svc_user -WithDecryption $true).Value
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
$instanceID = invoke-restmethod -uri http://169.254.169.254/latest/meta-data/instance-id
Add-Computer -domainname example.com -ComputerName $instanceID -Credential $credential -Passthru -Verbose -Force -Restart
</powershell>
AWSTemplateFormatVersion: '2010-09-09'
Description: Automatically validate ACM requests from this account
ACMApproverRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
@giuliocalzolari
giuliocalzolari / insecure-sg-scanner.py
Last active September 14, 2018 09:02
AWS insecure Security Group Scanner
#!/usr/bin/env python
import boto3
import json
import sys
def find_public_addresses(ec2):
public_instances = {}
instance_public_ips = {}
instance_private_ips = {}
instance_ident = {}