Skip to content

Instantly share code, notes, and snippets.

@elblivion
Last active February 28, 2016 14:21
Show Gist options
  • Save elblivion/f52c38f720b8a200a04c to your computer and use it in GitHub Desktop.
Save elblivion/f52c38f720b8a200a04c to your computer and use it in GitHub Desktop.
Generate Terraform config for CoreOS AMIs
{
"variable": {
"coreos_stable_amis": {
"default": [
{
"eu-central-1": "ami-f0e8f09c"
},
{
"ap-northeast-1": "ami-a93802c7"
},
{
"us-gov-west-1": "ami-46e05c27"
},
{
"sa-east-1": "ami-6c1a9a00"
},
{
"ap-southeast-2": "ami-d0a783b3"
},
{
"ap-southeast-1": "ami-4a65aa29"
},
{
"us-east-1": "ami-dfb699b5"
},
{
"us-west-2": "ami-abc82ecb"
},
{
"us-west-1": "ami-4d2d5b2d"
},
{
"eu-west-1": "ami-1461d767"
}
]
}
},
"output": {
"coreos_stable_ami": {
"value": "${lookup(var.coreos_stable_amis, var.region)}"
}
}
}
#!/usr/bin/env ruby
#
# Update CoreOS AMIs
require 'open-uri'
require 'json'
# source URL
coreos_stable_url = "https://coreos.com/dist/aws/aws-stable.json"
# target file
module_file = "contentful_amis/coreos.tf.json"
coreos_amis_tf = File.expand_path(File.dirname(__FILE__) + "/../" + module_file)
begin
coreos_stable_json = JSON.parse(open(coreos_stable_url) { |f| f.read })
rescue => e
puts e.msg
exit 1
end
per_region_hvm = coreos_stable_json.reject { |k,v| k == "release_info" }
.map { |k,v| { k => v["hvm"] } }
tf_config = {
"variable" => {
"coreos_stable_amis" => {
"default" => per_region_hvm
}
},
"output" => {
"coreos_stable_ami" => {
"value" => "${lookup(var.coreos_stable_amis, var.region)}"
}
}
}
File.open(coreos_amis_tf, 'w') do |f|
f.write JSON.pretty_generate tf_config
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment