Skip to content

Instantly share code, notes, and snippets.

View tom-butler's full-sized avatar
🚵

tom-butler tom-butler

🚵
View GitHub Profile
@tom-butler
tom-butler / reference.tf
Created January 31, 2017 00:43
Terraform to only reference the resource that exists
# Assuming either name_1 or name_2 exists (using a count = 0)
# The following can be used to pass an attribute from the resource that was created
"${coalesce(
join("", resource.name.*.id),
join("", resource.name_2.*.id)
)}"
@tom-butler
tom-butler / ec2_helper.rb
Last active March 5, 2018 19:52
Get Running Instance ID
require 'aws-sdk'
# Return only a single running instance with the Name tag specified
class EC2Helper
def self.GetIdFromName(name)
instances = Array.new
# Filter the ec2 instances for name and state pending or running
ec2 = Aws::EC2::Resource.new(region: ENV['AWS_DEFAULT_REGION'])
ec2.instances({filters: [