Skip to content

Commit

Permalink
Implement ability to filter GCP projects by lifecycle state
Browse files Browse the repository at this point in the history
  • Loading branch information
walterdolce committed Feb 19, 2019
1 parent 50a3180 commit 414db9c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 10 additions & 1 deletion docs/resources/google_projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,27 @@ The following examples show how to use this InSpec audit resource.
its('lifecycle_state') { should eq "ACTIVE" }
end
end

### Test that a particular subset of ACTIVE projects with id 'prod*' exist

google_projects.where(project_id: /^prod/, lifecycle_state: 'ACTIVE').project_ids.each do |gcp_project_id|
describe google_project(project: gcp_project_id) do
it { should exist }
end
end

<br>

## Filter Criteria

This resource supports the following filter criteria: `project_id`; `project_name` and `project_number`. Anyy of these may be used with `where`, as a block or as a method.
This resource supports the following filter criteria: `project_id`; `project_name`; `project_number` and `lifecycle_state`. Any of these may be used with `where`, as a block or as a method.

## Properties

* `project_ids` - an array of google_compute_project identifier strings
* `project_names` - an array of google_compute_project name strings
* `project_numbers`- an array of google_compute_project number identifier integers
* `lifecycle_state`- an array of google_compute_project lifecycle state strings

<br>

Expand Down
10 changes: 7 additions & 3 deletions libraries/google_projects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def initialize(opts = {})
filter_table_config.add(:project_ids, field: :project_id)
filter_table_config.add(:project_names, field: :project_name)
filter_table_config.add(:project_numbers, field: :project_number)
filter_table_config.add(:lifecycle_state, field: :lifecycle_state)
filter_table_config.connect(self, :fetch_data)

def fetch_data
Expand All @@ -35,9 +36,12 @@ def fetch_data
end
return [] if !@projects || !@projects.projects
@projects.projects.map do |project|
project_rows+=[{ project_id: project.project_id,
project_name: project.name,
project_number: project.project_number }]
project_rows += [{
project_id: project.project_id,
project_name: project.name,
project_number: project.project_number,
lifecycle_state: project.lifecycle_state,
}]
end
next_page = @projects.next_page_token
break unless next_page
Expand Down

0 comments on commit 414db9c

Please sign in to comment.