Skip to content

Instantly share code, notes, and snippets.

@jnahelou
Last active October 18, 2019 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnahelou/d9728003d89e22a48550d15e8fc7187a to your computer and use it in GitHub Desktop.
Save jnahelou/d9728003d89e22a48550d15e8fc7187a to your computer and use it in GitHub Desktop.
Patch to use inspec-iggy with terraform 0.12
--- gems/2.5.0/gems/inspec-iggy-0.6.0/lib/inspec-iggy/terraform/generate.rb 2019-08-08 13:27:19.494150516 +0200
+++ gems/2.5.0/gems/inspec-iggy-0.6.0/lib/inspec-iggy/terraform/generate.rb 2019-10-18 11:46:58.920277083 +0200
@@ -30,31 +30,31 @@
def self.parse_resources(tfstate, resource_path, _platform)
# iterate over the resources
resources = {}
- tfstate['modules'].each do |m|
- tf_resources = m['resources']
- tf_resources.keys.each do |tf_res|
- resource_type = tf_resources[tf_res]['type']
+ tf_resources = tfstate['resources']
+ tf_resources.each do |tf_res|
+ resource_type = tf_res['type']
- next if resource_type.eql?('random_id') # this is a Terraform resource, not a provider resource
+ next if resource_type.eql?('random_id') # this is a Terraform resource, not a provider resource
- # load resource pack resources
- InspecPlugins::Iggy::InspecHelper.load_resource_pack(resource_path) if resource_path
+ # load resource pack resources
+ InspecPlugins::Iggy::InspecHelper.load_resource_pack(resource_path) if resource_path
- # add translation layer
- if InspecPlugins::Iggy::InspecHelper::TRANSLATED_RESOURCES.key?(resource_type)
- Inspec::Log.debug "Iggy::Terraform::Generate.parse_resources resource_type = #{resource_type} #{InspecPlugins::Iggy::InspecHelper::TRANSLATED_RESOURCES[resource_type]} TRANSLATED"
- resource_type = InspecPlugins::Iggy::InspecHelper::TRANSLATED_RESOURCES[resource_type]
- end
- resources[resource_type] = {} if resources[resource_type].nil?
- # does this match an InSpec resource?
- if InspecPlugins::Iggy::InspecHelper.available_resources.include?(resource_type)
- Inspec::Log.debug "Iggy::Terraform::Generate.parse_resources resource_type = #{resource_type} MATCHED"
- resource_id = tf_resources[tf_res]['primary']['id']
- resource_attributes = tf_resources[tf_res]['primary']['attributes']
- resources[resource_type][resource_id] = resource_attributes
- else
- Inspec::Log.debug "Iggy::Terraform.Generate.parse_generate resource_type = #{resource_type} SKIPPED"
+ # add translation layer
+ if InspecPlugins::Iggy::InspecHelper::TRANSLATED_RESOURCES.key?(resource_type)
+ Inspec::Log.debug "Iggy::Terraform::Generate.parse_resources resource_type = #{resource_type} #{InspecPlugins::Iggy::InspecHelper::TRANSLATED_RESOURCES[resource_type]} TRANSLATED"
+ resource_type = InspecPlugins::Iggy::InspecHelper::TRANSLATED_RESOURCES[resource_type]
+ end
+ resources[resource_type] = {} if resources[resource_type].nil?
+ # does this match an InSpec resource?
+ if InspecPlugins::Iggy::InspecHelper.available_resources.include?(resource_type)
+ Inspec::Log.debug "Iggy::Terraform::Generate.parse_resources resource_type = #{resource_type} MATCHED"
+ tf_res['instances'].each do | instance |
+ resource_id = instance['attributes']['id']
+ resource_attributes = instance['attributes']
+ resources[resource_type][resource_id] = resource_attributes
end
+ else
+ Inspec::Log.debug "Iggy::Terraform.Generate.parse_generate resource_type = #{resource_type} SKIPPED"
end
end
resources
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment