Skip to content

Instantly share code, notes, and snippets.

View pporada-gl's full-sized avatar

Phil Porada pporada-gl

View GitHub Profile

Setting Tags in Terraform

Determine some sensible tags to pass non-critical information to Ansible or other CM solutions:

resource "aws_instance" "main" {
...
  tags {
  ...
    "some_tag" = "waka"
- hosts: localhost
connection: local
tasks:
- ec2_remote_facts:
region: us-east-1
filters:
instance-state-name: running
"tag:ENV": prod
"tag:ROLES": consul-server
register: ec2_facts
APIMETHOD="/repos/${OWNER}/${REPO}/issues/$ISSUE/labels"
URL="https://api.github.com/${APIMETHOD}"
curl --header "Authorization: token ${TOKEN}" \
-s \
-XPOST \
--data '{["enhancement"]}' \
--location "${URL}"
-------------------------------------------
{
"builders": [
{
"access_key": "{{user `var_aws_access_key`}}",
"ami_description": "My new AMI",
"ami_name": "CentOS 7 x86_64 Base {{timestamp}}",
"associate_public_ip_address": true,
"enhanced_networking": true,
"instance_type": "{{user `var_aws_instance_type`}}",
"region": "{{user `var_aws_region`}}",
68 "resources": {
69 "data.terraform_remote_state.build-vpc": {
70 "type": "terraform_remote_state",
71 "depends_on": [],
72 "primary": {
variable "region" {}
variable "aws_access_key" {}
variable "aws_secret_key" {}
variable "env" {}
variable "company" {}
data "terraform_remote_state" "build-vpc" {
backend = "s3"
config {
region = "us-east-1"
$ cat Jenkinsfile
#!/usr/bin/env groovy
node {
git credentialsId: '4sdjfsdkjbfgksjdbfksjdbfkjsdbfkjsdbfjkbsdfb', url: 'git@bitbucket.org:/terraform-autobot.git'
withEnv(["SOURCE_BUILD_NUMBER=${env.BUILD_NUMBER}"]) {
sh '''#!/bin/bash
echo $SOURCE_BUILD_NUMBER
echo "======="
### Assume this list of ips
192.168.33.10,192.168.33.11,192.168.33.12
"retry_join": [{% for h in groups['consul_servers'] %}"{{ hostvars[h].ansible_eth1.ipv4.address|difference(ansible_all_ipv4_addresses)|list }}"{% if not loop.last %},{% endif %}{% endfor ,
### This will output
"retry_join": ["[u'1', u'9', u'2', u'.', u'6', u'8', u'3', u'0']"],
### I am looking for the following instead of ^
#### Assuming I am on box 192.168.33.12
@pporada-gl
pporada-gl / gist:f2f6af93b148a693fc6409bfcb7100d5
Created January 3, 2017 19:22
Terraform security group example
resource "aws_security_group" "jenkins" {
name = "${var.env}_${var.tier}_jenkins_secgroup"
vpc_id = "${var.vpc_id}"
description = "jenkins security group"
tags {
Name = "${var.env}_${var.tier}_jenkins_secgroup"
TERRAFORM = "true"
ENV = "${var.env}"
TIER = "${var.tier}"
ENVIRONMENT="$1"
test_CNT="thing1 thing2 thing3"
beta_CNT="thing4 thing5 thing6"
for i in ${${ENVIRONMENT}_CNT}; do
echo $i
done
####