forked from rosstimson/chef-terraform
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added helper methods: raw_checksums_to_hash, fetch_checksums, and t…
…erraform_url - Fixed Issue rosstimson#10(rosstimson#10)
- Loading branch information
Showing
6 changed files
with
48 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters