Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ability to filter GCP projects by lifecycle state #109

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 5 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,10 @@ def fetch_data
end
return [] if !@projects || [email protected]
@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