github.com/hobbeswalsh/terraform@v0.3.7-0.20150619183303-ad17cf55a0fa/contrib/api-coverage/aws_api_coverage.rb (about) 1 # 2 # This script generates CSV output reporting on the API Coverage of Terraform's 3 # AWS Provider. 4 # 5 # In addition to Ruby, it depends on a properly configured Go development 6 # environment with both terraform and aws-sdk-go present. 7 # 8 9 require 'csv' 10 require 'json' 11 require 'pathname' 12 13 module APIs 14 module Terraform 15 def self.path 16 @path ||= Pathname(`go list -f '{{.Dir}}' github.com/hashicorp/terraform`.chomp) 17 end 18 19 def self.called?(api, op) 20 `git -C "#{path}" grep "#{api}.*#{op}" -- builtin/providers/aws | wc -l`.chomp.to_i > 0 21 end 22 end 23 24 module AWS 25 def self.path 26 @path ||= Pathname(`go list -f '{{.Dir}}' github.com/awslabs/aws-sdk-go/aws`.chomp).parent 27 end 28 29 def self.api_json_files 30 Pathname.glob(path.join('**', '*.normal.json')) 31 end 32 33 def self.each 34 api_json_files.each do |api_json_file| 35 json = JSON.parse(api_json_file.read) 36 api = api_json_file.dirname.basename 37 json["operations"].keys.each do |op| 38 yield api, op 39 end 40 end 41 end 42 end 43 end 44 45 csv = CSV.new($stdout) 46 csv << ["API", "Operation", "Called in Terraform?"] 47 APIs::AWS.each do |api, op| 48 csv << [api, op, APIs::Terraform.called?(api, op)] 49 end