Skip to content

Instantly share code, notes, and snippets.

View jungopro's full-sized avatar
:octocat:
terraform decoupling

Omer Barel jungopro

:octocat:
terraform decoupling
View GitHub Profile
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
name: Build-$(Build.BuildId)
trigger: none
pr: [dev]
pool:
vmImage: 'ubuntu-latest'
@jungopro
jungopro / main.tf
Created December 3, 2019 18:06
Sample terraform code I
locals {
tags = merge(var.tags, { "workspace" = "${terraform.workspace}" }) # add terraform workspace tag to any additional tags given as input
}
resource "azurerm_resource_group" "rg" {
count = var.create_resource_group ? 1 : 0 # conditional creation
name = "${terraform.workspace}-${var.resource_group_name}"
location = var.resource_group_location
tags = local.tags
@jungopro
jungopro / docker-save.sh
Created November 26, 2019 12:00
Basic Docker script to Save a docker image as .tar file
while getopts :i:v:p opt; do
case $opt in
i) IMAGE=$OPTARG
;;
v) VERSION=$OPTARG
;;
\?) echo "Unknown option: -$OPTARG" >&2
exit 1
;;
esac
@jungopro
jungopro / TerraformInitAzureBackend.sh
Created June 4, 2019 11:49
Bash Script to Initialize Terraform with Remote State in Azure Storage
#!/bin/bash
#
# Maintainer: Omer Barel (jungo@jungopro.com)
######################################################################################################################################################################
# Examples:
#
#
# Run with minimum values (Note that the defaults should pre-exist in your shell environment: TFM_STORAGE_NAME, TFM_STORAGE_CONTAINER, TFM_STORAGE_ACCESS_KEY)
# TerraformInitAzureBackend.sh -f "terraform.tfstate"
provide "azurerm" {}
## Declare Variables
variable "resource_group_name" {
default = "my-resource-group"
}
variable "location" {
default = "West Europe"
resource "random_string" "password" {
length = 14
min_upper = 2
min_lower = 2
min_numeric = 2
min_special = 2
}
resource "azurerm_key_vault_secret" "secret" {
name = "${var.secret_name}"
@jungopro
jungopro / variables.tf
Created October 5, 2018 15:53
Sample Terraform Variables
# Variables
variable "ad_tenant_id" {}
@jungopro
jungopro / mytfvars.sh
Created October 5, 2018 15:51
Sample Terraform Variables shell export
$ vi .mytfvars
# TF Azure configuration
export TF_VAR_ad_tenant_id=11111111-1111-1111-1111-111111111111
@jungopro
jungopro / createsecrets.sh
Last active March 19, 2019 10:51
Sample Azure Credentials shell export
az keyvault secret set --name ARM-SUBSCRIPTION-ID --vault-name myVault --value ##ARM_SUBSCRIPTION_ID##
az keyvault secret set --name ARM-CLIENT-ID --vault-name myVault --value ##ARM_CLIENT_ID##
az keyvault secret set --name ARM-CLIENT-SECRET --vault-name myVault --value ##ARM_CLIENT_SECRET##
az keyvault secret set --name ARM-TENANT-ID --vault-name myVault --value ##ARM_TENANT_ID##
@jungopro
jungopro / main.tf
Created October 5, 2018 15:46
Basic provider with hardcoded credentials
provider "azurerm" {
subscription_id = "xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx"
client_id ="xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx"
client_secret ="xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx"
tenant_id ="xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx-xxxxxx"
}