Skip to content

Instantly share code, notes, and snippets.

View karl-cardenas-coding's full-sized avatar

Karl Cardenas karl-cardenas-coding

View GitHub Profile
@karl-cardenas-coding
karl-cardenas-coding / main.tf
Created March 19, 2019 02:08
Automate-ami-TF
##########################################
# Retrieve the latest AMI id
##########################################
module "latest-ami" {
source = "./modules/ami-latest"
}
##########################################
# Initiate the temp files
##########################################
{
"builders": [{
"type": "amazon-ebs",
"ami_name": "${ami-name}-{{isotime \"Jan-02-06\"}}",
"instance_type": "${instance_type}",
"region": "${region}",
"source_ami": "${source_ami}",
"security_group_ids": ["${security_groups}"],
"ssh_username": "${ssh_username}",
"iam_instance_profile": "${instance_profile}",
@karl-cardenas-coding
karl-cardenas-coding / lambda.py
Created March 19, 2019 02:17
lambda-start-ci
import json
import boto3
import os
from botocore.vendored import requests
from base64 import b64decode
projectId = os.environ['projectId']
token = os.environ['token']
tokenDecrypted = boto3.client('kms').decrypt(CiphertextBlob=b64decode(token))['Plaintext'].decode("utf-8")
@karl-cardenas-coding
karl-cardenas-coding / Dockerfile
Created March 19, 2019 02:19
automation-dockerfile
FROM hashicorp/terraform:latest
RUN apk update && apk upgrade && apk add --no-cache \
python3 \
&& python3 -m ensurepip \
&& pip3 install --upgrade pip setuptools \
&& pip3 install awscli --upgrade --user \
&& apk add bash \
&& mv /root/.local/bin/* /usr/local/bin \
&& rm -rf /var/cache/apk/*
@karl-cardenas-coding
karl-cardenas-coding / .gitlab-ci.yml
Created March 19, 2019 02:12
Automation-ci-yml
stages:
- terraform
- packer
before_script:
- mkdir ~/.aws/
- echo -e "[default]" > ~/.aws/credentials
- echo -e "aws_access_key_id=$AWS_ACCESS_KEY">> ~/.aws/credentials
- echo -e "aws_secret_access_key=$AWS_SECRET_KEY">> ~/.aws/credentials
- echo -e "[default]" > ~/.aws/config
- echo -e "region = us-east-1" >> ~/.aws/config
@karl-cardenas-coding
karl-cardenas-coding / for-loop-s3.tf
Last active March 8, 2020 00:05
For loop in Terraform
locals {
s3_ips = try(distinct([ #distinct() is not needed but added to showcase the wrap of functions before the loop
for items in jsondecode(data.http.primary-server.body).prefixes:
items.ip_prefix if items.service == "S3"
]), "NO LIST PROVIDED IN LOCALS S3_IPS VARIABLE")
}
@karl-cardenas-coding
karl-cardenas-coding / try.tf
Last active May 29, 2020 15:28
Example of using try in Terraform
# Try example
data "http" "primary-server" {
url = "https://ip-ranges.amazonaws.com/ip-ranges.json"
# Optional request headers
request_headers = {
Accept = "application/json"
}
}
variable "os" {
default = "linux"
validation {
# The condition here identifies if the variable contains the string "linxu" OR "windows".
condition = can(regex("linux|windows", var.os))
error_message = "ERROR: Operating System must be Windows OR Linux."
}
}
### Test scenario for "can"
variable "word-length" {
validation {
# The condition here identifies if the integer if greater than 1
condition = var.word-length > 1
error_message = "The variable is not greater than 5. Word length has to be at a minimum > 1."
}
}
@karl-cardenas-coding
karl-cardenas-coding / new-car.md
Created July 19, 2020 03:40
Markdown example for adding content to a Hugo project
title New Car
date 2020-07-18 15:20:47 -0700
draft false

A car for everyone

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum