Skip to content

Instantly share code, notes, and snippets.

View rafalsep's full-sized avatar

Rafal Szczepankiewicz rafalsep

View GitHub Profile
@rafalsep
rafalsep / cloudAccess.tf
Created May 3, 2022 22:19
Example snippet that creates GCP custom service account using terraform google_service_account
resource "google_service_account" "custom" {
account_id = "${var.app_name}"
display_name = "Custom Service Account"
}
resource "google_project_iam_member" "secret-accessor-custom" {
role = "roles/secretmanager.secretAccessor"
member = "serviceAccount:${google_service_account.custom.email}"
}
@rafalsep
rafalsep / gcpSecretCredentialsInit.js
Created May 3, 2022 22:13
Example snippet describing how to retrieve secret from GCP secret manager using @google-cloud/secret-manager library
import { SecretManagerServiceClient } from '@google-cloud/secret-manager';
const secretManagerServiceClient = new SecretManagerServiceClient();
let secretCredentials;
const initSecretCredentials = async () => {
if (process.env.NODE_ENV === 'production') {
const [secret] = await secretManagerServiceClient.accessSecretVersion({
name: `projects/${process.env.GCP_PROJECT}/secrets/secret-credentials/versions/latest`,
@rafalsep
rafalsep / jenkins_backup_dsl.groovy
Created May 3, 2022 22:00
Jenkins DSL script that will add backup and restore jobs for Jenkins. Backups all configs and jobs to Google Cloud Storage. <<BUCKET_NAME>> needs to be replaced with actual bucket name.
job('jenkins-backup') {
logRotator(30, -1, 30, -1)
label('master')
steps {
shell("""
#!/bin/bash
cd \$JENKINS_HOME
NOW_DATE=\$(date +%Y-%m-%d)