Skip to content

Commit

Permalink
- Added helper methods: raw_checksums_to_hash, fetch_checksums, and t…
Browse files Browse the repository at this point in the history
…erraform_url

- Fixed Issue rosstimson#10(rosstimson#10)
  • Loading branch information
haidangwa committed Feb 27, 2016
1 parent 14ac20b commit 9a9ef7c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
terraform Cookbook CHANGELOG
============================

0.4.0
-----
- Add helper methods: raw_checksums_to_hash, fetch_checksums, terraform_url
- Fixed Issue #10(https://github.com/rosstimson/chef-terraform/issues/10)

0.3.0
-----
- Fixed rubocop offenses
Expand Down
22 changes: 1 addition & 21 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,5 @@
default['terraform']['owner'] = 'Administrator'
end

# Transform raw output of the checksum list into a Hash[filename, checksum].
# https://releases.hashicorp.com/terraform/0.6.11/terraform_0.6.11_SHA256SUMS
default['terraform']['raw_checksums'] = <<-EOF
cef10c71b7337cfe85c895a0a42d4f512c99f7944a06102b578f73aba32b45a7 terraform_0.6.11_darwin_386.zip
9802b1d56576bea86e34fd3800e100eb043ab6de5a5fa40f7f05a0a44f364dd2 terraform_0.6.11_darwin_amd64.zip
2eb8079176fd173803e06159c1901707b00045dff4e5ea175166bcc957726733 terraform_0.6.11_freebsd_386.zip
a8d28c82dfa9e0f6503b6c2a840d8e373f9cf54437db08d935be92152719ba07 terraform_0.6.11_freebsd_amd64.zip
2806bbadfe70139f60beeda381b2976f75ce8682eaef294b77fcbeeb332e2d02 terraform_0.6.11_freebsd_arm.zip
8b3bf0e1ac3180f3846abea9bfb3a30eb098460f7923989b5eb4bb8cd4ae80fc terraform_0.6.11_linux_386.zip
f451411db521fc4d22c9fe0c80105cf028eb8df0639bac7c1e781880353d9a5f terraform_0.6.11_linux_amd64.zip
7a906ea4137f590afd650aae4bc121e52ae40d5a7f7e57a2ba5c0c3bd316768c terraform_0.6.11_linux_arm.zip
9f04586b066c7a3496e07aaafb1dd1bb470e049ad812657f1c1c59259be69a93 terraform_0.6.11_openbsd_386.zip
a57fbcff72ad17c3261b272b4fc9ae15e059ff186d4aa9064ada43613ada3f23 terraform_0.6.11_openbsd_amd64.zip
0738fad4fc55d0120d4bc0ff47fb57a45376a45cf7d8f939c03e5becb97f30cd terraform_0.6.11_solaris_amd64.zip
8564488b4a8e8e40d37c63424006315b89c13096357411a21ce84f26ec92767f terraform_0.6.11_windows_386.zip
4832e6ca2b60bb3d08ef69497bc11890d3e986f0ce76d20bed1a2e9520fc93ba terraform_0.6.11_windows_amd64.zip
EOF

default['terraform']['checksums'] = Hash[
node['terraform']['raw_checksums'].split("\n").map { |s| s.split.reverse }
]
default['terraform']['checksums'] = raw_checksums_to_hash
default['terraform']['checksum'] = node['terraform']['checksums'][node['terraform']['zipfile']]
1 change: 0 additions & 1 deletion files/default/tests/minitest/default_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@
.with(:to, File.join(terraform_dir, 'terraform'))
file(File.join(terraform_dir, 'terraform'))
.must_exist
.with(:mode, '755')
end
end
40 changes: 40 additions & 0 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# These are helper methods that can be used in this cookbook
# the Terraform namespace
module Terraform
# Helpers belonging to the Terraform namespace
module Helpers
# Transform raw output of the checksum list into a Hash[filename, checksum].
def raw_checksums_to_hash
raw_checksums = fetch_checksums
Hash[
raw_checksums.split("\n").map do |s|
s.split.reverse
end
]
end

# Downloads the raw checksums from hashicorp
# https://releases.hashicorp.com/terraform/#{version}/#{checksum_file}
def fetch_checksums
require 'uri'
uri = URI.parse(node['terraform']['url_base'])
terraform_releases = "#{uri.scheme}://#{uri.host}/"
version = node['terraform']['version']
checksum_file = "terraform_#{version}_SHA256SUMS"
Chef::HTTP::Simple.new(terraform_releases)
.get("terraform/#{version}/#{checksum_file}")
end

def terraform_url
"#{node['terraform']['url_base']}/#{node['terraform']['version']}/" \
"#{node['terraform']['zipfile']}"
end

private :fetch_checksums
end
end

::Chef::Node.send(:include, Terraform::Helpers)
::Chef::Recipe.send(:include, Terraform::Helpers)
::Chef::Provider.send(:include, Terraform::Helpers)
::Chef::Resource.send(:include, Terraform::Helpers)
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
license 'Apache 2.0'
description 'Installs Terraform (terraform.io)'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.3.0'
version '0.4.0'

depends 'ark', '~> 1.0.0'

Expand Down
3 changes: 1 addition & 2 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
include_recipe 'ark'

ark 'terraform' do
url "#{node['terraform']['url_base']}/#{node['terraform']['version']}/" \
"#{node['terraform']['zipfile']}"
url terraform_url
version node['terraform']['version']
checksum node['terraform']['checksum']
has_binaries ['terraform']
Expand Down

0 comments on commit 9a9ef7c

Please sign in to comment.