From 85f0c9f4ffb685b8079dbdfcbc97d4e618a3c820 Mon Sep 17 00:00:00 2001 From: Samir <85890442+sa-progress@users.noreply.github.com> Date: Tue, 15 Oct 2024 13:32:50 +0530 Subject: [PATCH 1/4] Automatically generated by magic modules for service: monitoring_v3 and resource: Projects__group. This commit includes the following changes: - Singular Resource - Plural Resource - Documentation updates - Terraform configuration - Integration tests Signed-off-by: Samir <85890442+sa-progress@users.noreply.github.com> --- .../google_monitoring_project_group.md | 60 +++++++++++++ .../google_monitoring_project_groups.md | 56 ++++++++++++ libraries/google_monitoring_project_group.rb | 63 ++++++++++++++ libraries/google_monitoring_project_groups.rb | 87 +++++++++++++++++++ .../google_monitoring_project_group.rb | 41 +++++++++ .../google_monitoring_project_groups.rb | 32 +++++++ 6 files changed, 339 insertions(+) create mode 100644 docs/resources/google_monitoring_project_group.md create mode 100644 docs/resources/google_monitoring_project_groups.md create mode 100644 libraries/google_monitoring_project_group.rb create mode 100644 libraries/google_monitoring_project_groups.rb create mode 100644 test/integration/verify/controls/google_monitoring_project_group.rb create mode 100644 test/integration/verify/controls/google_monitoring_project_groups.rb diff --git a/docs/resources/google_monitoring_project_group.md b/docs/resources/google_monitoring_project_group.md new file mode 100644 index 00000000..f46aa105 --- /dev/null +++ b/docs/resources/google_monitoring_project_group.md @@ -0,0 +1,60 @@ ++++ + +title = "google_monitoring_project_group Resource" +platform = "gcp" +draft = false +gh_repo = "inspec-gcp" + + +[menu.inspec] + +title = "google_monitoring_project_group" +identifier = "inspec/resources/gcp/google_monitoring_project_group Resource" +parent = "inspec/resources/gcp" ++++ + +Use the `google_monitoring_project_group` InSpec audit resource to test the properties of a test a Google ProjectGroup. + +## Installation +{{% inspec_gcp_install %}} + +## Syntax +A `google_monitoring_project_group` is used to test a Google ProjectGroup resource + +## Examples +``` +describe google_monitoring_project_group(name: ' value_name') do + it { should exist } + its('name') { should cmp 'value_name' } + its('display_name') { should cmp 'value_displayname' } + its('parent_name') { should cmp 'value_parentname' } + its('filter') { should cmp 'value_filter' } + +end + +describe google_monitoring_project_group(name: "does_not_exit") do + it { should_not exist } +end +``` + +## Parameters +Properties that can be accessed from the `google_monitoring_project_group` resource: + +## Properties +Properties that can be accessed from the `google_monitoring_project_group` resource: + + + * `name`: Output only. The name of this group. The format is: projects/[PROJECT_ID_OR_NUMBER]/groups/[GROUP_ID] When creating a group, this field is ignored and a new name is created consisting of the project specified in the call to CreateGroup and a unique [GROUP_ID] that is generated automatically. + + * `display_name`: A user-assigned name for this group, used only for display purposes. + + * `parent_name`: The name of the group's parent, if it has one. The format is: projects/[PROJECT_ID_OR_NUMBER]/groups/[GROUP_ID] For groups with no parent, parent_name is the empty string, "". + + * `filter`: The filter used to determine which monitored resources belong to this group. + + * `is_cluster`: If true, the members of this group are considered to be a cluster. The system can perform additional analysis on groups that are clusters. + + +## GCP Permissions + +Ensure the [Stackdriver Monitoring API](https://console.cloud.google.com/apis/library/monitoring.googleapis.com/) is enabled for the current project. diff --git a/docs/resources/google_monitoring_project_groups.md b/docs/resources/google_monitoring_project_groups.md new file mode 100644 index 00000000..f8ad619f --- /dev/null +++ b/docs/resources/google_monitoring_project_groups.md @@ -0,0 +1,56 @@ ++++ + +title = "google_monitoring_project_groups Resource" +platform = "gcp" +draft = false +gh_repo = "inspec-gcp" + + +[menu.inspec] + +title = "google_monitoring_project_groups" +identifier = "inspec/resources/gcp/google_monitoring_project_groups Resource" +parent = "inspec/resources/gcp" ++++ + +Use the `google_monitoring_project_groups` InSpec audit resource to test the properties of a test a Google ProjectGroup. + +## Installation +{{% inspec_gcp_install %}} + +## Syntax +A `google_monitoring_project_groups` is used to test a Google ProjectGroup resource + +## Examples +``` + describe google_monitoring_project_groups(name: ' value_name') do + it { should exist } + end +``` + +## Parameters +Properties that can be accessed from the `google_monitoring_project_groups` resource: + +See [google_monitoring_project_group.md](google_monitoring_project_group.md) for more detailed information +* `names`: an array of `google_monitoring_project_group` name +* `display_names`: an array of `google_monitoring_project_group` display_name +* `parent_names`: an array of `google_monitoring_project_group` parent_name +* `filters`: an array of `google_monitoring_project_group` filter +* `is_clusters`: an array of `google_monitoring_project_group` is_cluster +## Properties +Properties that can be accessed from the `google_monitoring_project_groups` resource: + +See [google_monitoring_project_group.md](google_monitoring_project_group.md) for more detailed information +* `names`: an array of `google_monitoring_project_group` name +* `display_names`: an array of `google_monitoring_project_group` display_name +* `parent_names`: an array of `google_monitoring_project_group` parent_name +* `filters`: an array of `google_monitoring_project_group` filter +* `is_clusters`: an array of `google_monitoring_project_group` is_cluster + +## Filter Criteria +This resource supports all of the above properties as filter criteria, which can be used +with `where` as a block or a method. + +## GCP Permissions + +Ensure the [Stackdriver Monitoring API](https://console.cloud.google.com/apis/library/monitoring.googleapis.com/) is enabled for the current project. diff --git a/libraries/google_monitoring_project_group.rb b/libraries/google_monitoring_project_group.rb new file mode 100644 index 00000000..d000fc37 --- /dev/null +++ b/libraries/google_monitoring_project_group.rb @@ -0,0 +1,63 @@ +# frozen_string_literal: false + +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** Type: MMv1 *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- +require 'gcp_backend' + +# A provider to manage Cloud (Stackdriver) Monitoring resources. +class MonitoringProjectGroup < GcpResourceBase + name 'google_monitoring_project_group' + desc 'ProjectGroup' + supports platform: 'gcp' + + attr_reader :params + attr_reader :name + attr_reader :display_name + attr_reader :parent_name + attr_reader :filter + attr_reader :is_cluster + + def initialize(params) + super(params.merge({ use_http_transport: true })) + @params = params + @fetched = @connection.fetch(product_url(params[:beta]), resource_base_url, params, 'Get') + parse unless @fetched.nil? + end + + def parse + @name = @fetched['name'] + @display_name = @fetched['displayName'] + @parent_name = @fetched['parentName'] + @filter = @fetched['filter'] + @is_cluster = @fetched['isCluster'] + end + + def exists? + !@fetched.nil? + end + + def to_s + "ProjectGroup #{@params[:]}" + end + + private + + def product_url(_ = nil) + 'https://monitoring.googleapis.com/' + end + + def resource_base_url + '{{+name}}' + end +end diff --git a/libraries/google_monitoring_project_groups.rb b/libraries/google_monitoring_project_groups.rb new file mode 100644 index 00000000..10d6e942 --- /dev/null +++ b/libraries/google_monitoring_project_groups.rb @@ -0,0 +1,87 @@ +# frozen_string_literal: false + +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** Type: MMv1 *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- +require 'gcp_backend' +class MonitoringProjectGroups < GcpResourceBase + name 'google_monitoring_project_groups' + desc 'ProjectGroup plural resource' + supports platform: 'gcp' + + attr_reader :table + + filter_table_config = FilterTable.create + + filter_table_config.add(:names, field: :name) + filter_table_config.add(:display_names, field: :display_name) + filter_table_config.add(:parent_names, field: :parent_name) + filter_table_config.add(:filters, field: :filter) + filter_table_config.add(:is_clusters, field: :is_cluster) + + filter_table_config.connect(self, :table) + + def initialize(params = {}) + super(params.merge({ use_http_transport: true })) + @params = params + @table = fetch_wrapped_resource('projectGroups') + end + + def fetch_wrapped_resource(wrap_path) + # fetch_resource returns an array of responses (to handle pagination) + result = @connection.fetch_all(product_url, resource_base_url, @params, 'Get') + return if result.nil? + + # Conversion of string -> object hash to symbol -> object hash that InSpec needs + converted = [] + result.each do |response| + next if response.nil? || !response.key?(wrap_path) + response[wrap_path].each do |hash| + hash_with_symbols = {} + hash.each_key do |key| + name, value = transform(key, hash) + hash_with_symbols[name] = value + end + converted.push(hash_with_symbols) + end + end + + converted + end + + def transform(key, value) + return transformers[key].call(value) if transformers.key?(key) + + [key.to_sym, value] + end + + def transformers + { + 'name' => ->(obj) { [:name, obj['name']] }, + 'displayName' => ->(obj) { [:display_name, obj['displayName']] }, + 'parentName' => ->(obj) { [:parent_name, obj['parentName']] }, + 'filter' => ->(obj) { [:filter, obj['filter']] }, + 'isCluster' => ->(obj) { [:is_cluster, obj['isCluster']] }, + } + end + + private + + def product_url(_ = nil) + 'https://monitoring.googleapis.com/' + end + + def resource_base_url + '{{+name}}/groups' + end +end diff --git a/test/integration/verify/controls/google_monitoring_project_group.rb b/test/integration/verify/controls/google_monitoring_project_group.rb new file mode 100644 index 00000000..bb739164 --- /dev/null +++ b/test/integration/verify/controls/google_monitoring_project_group.rb @@ -0,0 +1,41 @@ +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** Type: MMv1 *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- + +title 'Test GCP google_monitoring_project_group resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + project_group = input('project_group', value: { + "name": "value_name", + "display_name": "value_displayname", + "parent_name": "value_parentname", + "filter": "value_filter" +}, description: 'project_group description') +control 'google_monitoring_project_group-1.0' do + impact 1.0 + title 'google_monitoring_project_group resource test' + + describe google_monitoring_project_group(name: project_group['name']) do + it { should exist } + its('name') { should cmp project_group['name'] } + its('display_name') { should cmp project_group['display_name'] } + its('parent_name') { should cmp project_group['parent_name'] } + its('filter') { should cmp project_group['filter'] } + + end + + describe google_monitoring_project_group(name: "does_not_exit") do + it { should_not exist } + end +end diff --git a/test/integration/verify/controls/google_monitoring_project_groups.rb b/test/integration/verify/controls/google_monitoring_project_groups.rb new file mode 100644 index 00000000..5ceec7bf --- /dev/null +++ b/test/integration/verify/controls/google_monitoring_project_groups.rb @@ -0,0 +1,32 @@ +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** Type: MMv1 *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- + +title 'Test GCP google_monitoring_project_groups resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + project_group = input('project_group', value: { + "name": "value_name", + "display_name": "value_displayname", + "parent_name": "value_parentname", + "filter": "value_filter" +}, description: 'project_group description') +control 'google_monitoring_project_groups-1.0' do + impact 1.0 + title 'google_monitoring_project_groups resource test' + + describe google_monitoring_project_groups(name: project_group['name']) do + it { should exist } + end +end From 3c821dcad6c2ad40551e4b0639cf749525ccb915 Mon Sep 17 00:00:00 2001 From: balasubramanian-s Date: Thu, 17 Oct 2024 13:23:16 +0530 Subject: [PATCH 2/4] rename resource name Signed-off-by: balasubramanian-s --- ...ct_group.md => google_monitoring_group.md} | 20 +++---- docs/resources/google_monitoring_groups.md | 59 +++++++++++++++++++ .../google_monitoring_project_groups.md | 56 ------------------ ...ct_group.rb => google_monitoring_group.rb} | 12 ++-- ..._groups.rb => google_monitoring_groups.rb} | 12 ++-- ...ct_group.rb => google_monitoring_group.rb} | 22 +++---- ..._groups.rb => google_monitoring_groups.rb} | 12 ++-- 7 files changed, 97 insertions(+), 96 deletions(-) rename docs/resources/{google_monitoring_project_group.md => google_monitoring_group.md} (66%) create mode 100644 docs/resources/google_monitoring_groups.md delete mode 100644 docs/resources/google_monitoring_project_groups.md rename libraries/{google_monitoring_project_group.rb => google_monitoring_group.rb} (87%) rename libraries/{google_monitoring_project_groups.rb => google_monitoring_groups.rb} (90%) rename test/integration/verify/controls/{google_monitoring_project_group.rb => google_monitoring_group.rb} (58%) rename test/integration/verify/controls/{google_monitoring_project_groups.rb => google_monitoring_groups.rb} (71%) diff --git a/docs/resources/google_monitoring_project_group.md b/docs/resources/google_monitoring_group.md similarity index 66% rename from docs/resources/google_monitoring_project_group.md rename to docs/resources/google_monitoring_group.md index f46aa105..199edf51 100644 --- a/docs/resources/google_monitoring_project_group.md +++ b/docs/resources/google_monitoring_group.md @@ -1,6 +1,6 @@ +++ -title = "google_monitoring_project_group Resource" +title = "google_monitoring_group Resource" platform = "gcp" draft = false gh_repo = "inspec-gcp" @@ -8,40 +8,38 @@ gh_repo = "inspec-gcp" [menu.inspec] -title = "google_monitoring_project_group" -identifier = "inspec/resources/gcp/google_monitoring_project_group Resource" +title = "google_monitoring_group" +identifier = "inspec/resources/gcp/google_monitoring_group Resource" parent = "inspec/resources/gcp" +++ -Use the `google_monitoring_project_group` InSpec audit resource to test the properties of a test a Google ProjectGroup. +Use the `google_monitoring_group` InSpec audit resource to test the properties of a test a Google Group. ## Installation {{% inspec_gcp_install %}} ## Syntax -A `google_monitoring_project_group` is used to test a Google ProjectGroup resource +A `google_monitoring_group` is used to test a Google Group resource ## Examples ``` -describe google_monitoring_project_group(name: ' value_name') do +describe google_monitoring_group(name: 'projects/*/groups/value_group_id') do it { should exist } its('name') { should cmp 'value_name' } its('display_name') { should cmp 'value_displayname' } - its('parent_name') { should cmp 'value_parentname' } its('filter') { should cmp 'value_filter' } - end -describe google_monitoring_project_group(name: "does_not_exit") do +describe google_monitoring_group(name: "does_not_exit") do it { should_not exist } end ``` ## Parameters -Properties that can be accessed from the `google_monitoring_project_group` resource: +Properties that can be accessed from the `google_monitoring_group` resource: ## Properties -Properties that can be accessed from the `google_monitoring_project_group` resource: +Properties that can be accessed from the `google_monitoring_group` resource: * `name`: Output only. The name of this group. The format is: projects/[PROJECT_ID_OR_NUMBER]/groups/[GROUP_ID] When creating a group, this field is ignored and a new name is created consisting of the project specified in the call to CreateGroup and a unique [GROUP_ID] that is generated automatically. diff --git a/docs/resources/google_monitoring_groups.md b/docs/resources/google_monitoring_groups.md new file mode 100644 index 00000000..234c66a4 --- /dev/null +++ b/docs/resources/google_monitoring_groups.md @@ -0,0 +1,59 @@ ++++ + +title = "google_monitoring_groups Resource" +platform = "gcp" +draft = false +gh_repo = "inspec-gcp" + + +[menu.inspec] + +title = "google_monitoring_groups" +identifier = "inspec/resources/gcp/google_monitoring_groups Resource" +parent = "inspec/resources/gcp" ++++ + +Use the `google_monitoring_groups` InSpec audit resource to test the properties of a test a Google Group. + +## Installation +{{% inspec_gcp_install %}} + +## Syntax +A `google_monitoring_groups` is used to test a Google Group resource + +## Examples +``` + describe google_monitoring_groups(name: 'value_name') do + it { should exist } + its('names') { should include 'value_name' } + its('display_names') { should include 'value_displayname' } + its('filters') { should include 'value_filter' } + end +``` + +## Parameters +Properties that can be accessed from the `google_monitoring_groups` resource: + +See [google_monitoring_group.md](google_monitoring_group.md) for more detailed information +* `names`: an array of `google_monitoring_group` name +* `display_names`: an array of `google_monitoring_group` display_name +* `parent_names`: an array of `google_monitoring_group` parent_name +* `filters`: an array of `google_monitoring_group` filter +* `is_clusters`: an array of `google_monitoring_group` is_cluster +## Properties +Properties that can be accessed from the `google_monitoring_groups` resource: + +See [google_monitoring_group.md](google_monitoring_group.md) for more detailed information +* `names`: an array of `google_monitoring_group` name +* `display_names`: an array of `google_monitoring_group` display_name +* `parent_names`: an array of `google_monitoring_group` parent_name +* `filters`: an array of `google_monitoring_group` filter +* `is_clusters`: an array of `google_monitoring_group` is_cluster + +## Filter Criteria +This resource supports all of the above properties as filter criteria, which can be used +with `where` as a block or a method. + +## GCP Permissions + +Ensure the [Stackdriver Monitoring API](https://console.cloud.google.com/apis/library/monitoring.googleapis.com/) is enabled for the current project. diff --git a/docs/resources/google_monitoring_project_groups.md b/docs/resources/google_monitoring_project_groups.md deleted file mode 100644 index f8ad619f..00000000 --- a/docs/resources/google_monitoring_project_groups.md +++ /dev/null @@ -1,56 +0,0 @@ -+++ - -title = "google_monitoring_project_groups Resource" -platform = "gcp" -draft = false -gh_repo = "inspec-gcp" - - -[menu.inspec] - -title = "google_monitoring_project_groups" -identifier = "inspec/resources/gcp/google_monitoring_project_groups Resource" -parent = "inspec/resources/gcp" -+++ - -Use the `google_monitoring_project_groups` InSpec audit resource to test the properties of a test a Google ProjectGroup. - -## Installation -{{% inspec_gcp_install %}} - -## Syntax -A `google_monitoring_project_groups` is used to test a Google ProjectGroup resource - -## Examples -``` - describe google_monitoring_project_groups(name: ' value_name') do - it { should exist } - end -``` - -## Parameters -Properties that can be accessed from the `google_monitoring_project_groups` resource: - -See [google_monitoring_project_group.md](google_monitoring_project_group.md) for more detailed information -* `names`: an array of `google_monitoring_project_group` name -* `display_names`: an array of `google_monitoring_project_group` display_name -* `parent_names`: an array of `google_monitoring_project_group` parent_name -* `filters`: an array of `google_monitoring_project_group` filter -* `is_clusters`: an array of `google_monitoring_project_group` is_cluster -## Properties -Properties that can be accessed from the `google_monitoring_project_groups` resource: - -See [google_monitoring_project_group.md](google_monitoring_project_group.md) for more detailed information -* `names`: an array of `google_monitoring_project_group` name -* `display_names`: an array of `google_monitoring_project_group` display_name -* `parent_names`: an array of `google_monitoring_project_group` parent_name -* `filters`: an array of `google_monitoring_project_group` filter -* `is_clusters`: an array of `google_monitoring_project_group` is_cluster - -## Filter Criteria -This resource supports all of the above properties as filter criteria, which can be used -with `where` as a block or a method. - -## GCP Permissions - -Ensure the [Stackdriver Monitoring API](https://console.cloud.google.com/apis/library/monitoring.googleapis.com/) is enabled for the current project. diff --git a/libraries/google_monitoring_project_group.rb b/libraries/google_monitoring_group.rb similarity index 87% rename from libraries/google_monitoring_project_group.rb rename to libraries/google_monitoring_group.rb index d000fc37..42893fe5 100644 --- a/libraries/google_monitoring_project_group.rb +++ b/libraries/google_monitoring_group.rb @@ -16,9 +16,9 @@ require 'gcp_backend' # A provider to manage Cloud (Stackdriver) Monitoring resources. -class MonitoringProjectGroup < GcpResourceBase - name 'google_monitoring_project_group' - desc 'ProjectGroup' +class MonitoringGroup < GcpResourceBase + name 'google_monitoring_group' + desc 'Group' supports platform: 'gcp' attr_reader :params @@ -48,16 +48,16 @@ def exists? end def to_s - "ProjectGroup #{@params[:]}" + "Group #{@params[:name]}" end private def product_url(_ = nil) - 'https://monitoring.googleapis.com/' + 'https://monitoring.googleapis.com/v3/' end def resource_base_url - '{{+name}}' + '{{name}}' end end diff --git a/libraries/google_monitoring_project_groups.rb b/libraries/google_monitoring_groups.rb similarity index 90% rename from libraries/google_monitoring_project_groups.rb rename to libraries/google_monitoring_groups.rb index 10d6e942..044c06f5 100644 --- a/libraries/google_monitoring_project_groups.rb +++ b/libraries/google_monitoring_groups.rb @@ -14,9 +14,9 @@ # # ---------------------------------------------------------------------------- require 'gcp_backend' -class MonitoringProjectGroups < GcpResourceBase - name 'google_monitoring_project_groups' - desc 'ProjectGroup plural resource' +class MonitoringGroups < GcpResourceBase + name 'google_monitoring_groups' + desc 'Group plural resource' supports platform: 'gcp' attr_reader :table @@ -34,7 +34,7 @@ class MonitoringProjectGroups < GcpResourceBase def initialize(params = {}) super(params.merge({ use_http_transport: true })) @params = params - @table = fetch_wrapped_resource('projectGroups') + @table = fetch_wrapped_resource('group') end def fetch_wrapped_resource(wrap_path) @@ -78,10 +78,10 @@ def transformers private def product_url(_ = nil) - 'https://monitoring.googleapis.com/' + 'https://monitoring.googleapis.com/v3/' end def resource_base_url - '{{+name}}/groups' + '{{name}}/groups' end end diff --git a/test/integration/verify/controls/google_monitoring_project_group.rb b/test/integration/verify/controls/google_monitoring_group.rb similarity index 58% rename from test/integration/verify/controls/google_monitoring_project_group.rb rename to test/integration/verify/controls/google_monitoring_group.rb index bb739164..14ba21f2 100644 --- a/test/integration/verify/controls/google_monitoring_project_group.rb +++ b/test/integration/verify/controls/google_monitoring_group.rb @@ -12,30 +12,30 @@ # # ---------------------------------------------------------------------------- -title 'Test GCP google_monitoring_project_group resource.' +title 'Test GCP google_monitoring_group resource.' gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') - project_group = input('project_group', value: { + group = input('group', value: { "name": "value_name", "display_name": "value_displayname", "parent_name": "value_parentname", "filter": "value_filter" -}, description: 'project_group description') -control 'google_monitoring_project_group-1.0' do +}, description: 'group description') +control 'google_monitoring_group-1.0' do impact 1.0 - title 'google_monitoring_project_group resource test' + title 'google_monitoring_group resource test' - describe google_monitoring_project_group(name: project_group['name']) do + describe google_monitoring_group(name: group['name']) do it { should exist } - its('name') { should cmp project_group['name'] } - its('display_name') { should cmp project_group['display_name'] } - its('parent_name') { should cmp project_group['parent_name'] } - its('filter') { should cmp project_group['filter'] } + its('name') { should cmp group['name'] } + its('display_name') { should cmp group['display_name'] } + its('parent_name') { should cmp group['parent_name'] } + its('filter') { should cmp group['filter'] } end - describe google_monitoring_project_group(name: "does_not_exit") do + describe google_monitoring_group(name: "does_not_exit") do it { should_not exist } end end diff --git a/test/integration/verify/controls/google_monitoring_project_groups.rb b/test/integration/verify/controls/google_monitoring_groups.rb similarity index 71% rename from test/integration/verify/controls/google_monitoring_project_groups.rb rename to test/integration/verify/controls/google_monitoring_groups.rb index 5ceec7bf..ee071f9e 100644 --- a/test/integration/verify/controls/google_monitoring_project_groups.rb +++ b/test/integration/verify/controls/google_monitoring_groups.rb @@ -12,21 +12,21 @@ # # ---------------------------------------------------------------------------- -title 'Test GCP google_monitoring_project_groups resource.' +title 'Test GCP google_monitoring_groups resource.' gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') - project_group = input('project_group', value: { + group = input('group', value: { "name": "value_name", "display_name": "value_displayname", "parent_name": "value_parentname", "filter": "value_filter" -}, description: 'project_group description') -control 'google_monitoring_project_groups-1.0' do +}, description: 'group description') +control 'google_monitoring_groups-1.0' do impact 1.0 - title 'google_monitoring_project_groups resource test' + title 'google_monitoring_groups resource test' - describe google_monitoring_project_groups(name: project_group['name']) do + describe google_monitoring_groups(name: group['name']) do it { should exist } end end From e2844be1a13c6d8c28786ab6cfccaa5c81b710e7 Mon Sep 17 00:00:00 2001 From: balasubramanian-s Date: Thu, 17 Oct 2024 13:50:28 +0530 Subject: [PATCH 3/4] added tf scripts Signed-off-by: balasubramanian-s --- test/integration/build/gcp-mm.tf | 8 ++++++++ test/integration/configuration/mm-attributes.yml | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/test/integration/build/gcp-mm.tf b/test/integration/build/gcp-mm.tf index 0866db18..2665a170 100644 --- a/test/integration/build/gcp-mm.tf +++ b/test/integration/build/gcp-mm.tf @@ -269,6 +269,9 @@ variable "data_fusion_instance" { variable "cloud_run_jobs" { type = any } +variable "monitoring_group" { + type = any +} resource "google_compute_ssl_policy" "custom-ssl-policy" { name = var.ssl_policy["name"] min_tls_version = var.ssl_policy["min_tls_version"] @@ -2245,3 +2248,8 @@ resource "google_cloud_run_v2_job" "default" { } } } +resource "google_monitoring_group" "inspec-test-group" { + project = var.gcp_project_id + display_name = var.monitoring_group.name + filter = var.monitoring_group.filter +} diff --git a/test/integration/configuration/mm-attributes.yml b/test/integration/configuration/mm-attributes.yml index ab0626a0..7c0ec298 100644 --- a/test/integration/configuration/mm-attributes.yml +++ b/test/integration/configuration/mm-attributes.yml @@ -751,3 +751,7 @@ cloud_run_jobs: location: "us-central1" deletion_protection: "false" image: "us-central1-docker.pkg.dev/ppradhan/nas/balasubs_tutorial1_20230915_182543:latest" + +monitoring_group: + name: "inspec-test-group" + filter: "resource.metadata.name = has_substring(\"inspec\")" From 58c6c3b9e836b0e9171377f3fe64c504618ae716 Mon Sep 17 00:00:00 2001 From: balasubramanian-s Date: Thu, 17 Oct 2024 14:21:59 +0530 Subject: [PATCH 4/4] update test case& readme Signed-off-by: balasubramanian-s --- README.md | 1 + docs/resources/google_monitoring_groups.md | 2 +- .../verify/controls/google_monitoring_group.rb | 12 +++++------- .../verify/controls/google_monitoring_groups.rb | 15 +++++++++------ 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ee144796..43fd18c3 100644 --- a/README.md +++ b/README.md @@ -328,6 +328,7 @@ The following resources are available in the InSpec GCP Profile | [google_logging_project_sink](docs/resources/google_logging_project_sink.md) | [google_logging_project_sinks](docs/resources/google_logging_project_sinks.md) | | [google_memcache_instance](docs/resources/google_memcache_instance.md) | [google_memcache_instances](docs/resources/google_memcache_instances.md) | | [google_ml_engine_model](docs/resources/google_ml_engine_model.md) | [google_ml_engine_models](docs/resources/google_ml_engine_models.md) | +| [google_monitoring_group](docs/resources/google_monitoring_group.md) | [google_monitoring_groups](docs/resources/google_monitoring_groups.md) | | [google_organization](docs/resources/google_organization.md) | [google_organizations](docs/resources/google_organizations.md) | | No Singular Resource | [google_orgpolicy_folder_constraints](docs/resources/google_orgpolicy_folder_constraints.md) | | No Singular Resource | [google_orgpolicy_organization_constraints](docs/resources/google_orgpolicy_project_constraints.md) | diff --git a/docs/resources/google_monitoring_groups.md b/docs/resources/google_monitoring_groups.md index 234c66a4..2b1e20b5 100644 --- a/docs/resources/google_monitoring_groups.md +++ b/docs/resources/google_monitoring_groups.md @@ -23,7 +23,7 @@ A `google_monitoring_groups` is used to test a Google Group resource ## Examples ``` - describe google_monitoring_groups(name: 'value_name') do + describe google_monitoring_groups(name: 'projects/*') do it { should exist } its('names') { should include 'value_name' } its('display_names') { should include 'value_displayname' } diff --git a/test/integration/verify/controls/google_monitoring_group.rb b/test/integration/verify/controls/google_monitoring_group.rb index 14ba21f2..426951ca 100644 --- a/test/integration/verify/controls/google_monitoring_group.rb +++ b/test/integration/verify/controls/google_monitoring_group.rb @@ -16,11 +16,11 @@ gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') - group = input('group', value: { - "name": "value_name", - "display_name": "value_displayname", - "parent_name": "value_parentname", - "filter": "value_filter" +group = input('group', value: { + "name": "projects/ppradhan/groups/1973775459523949291", + "display_name": "inspec-test-group", + "parent_name": "projects/ppradhan", + "filter": "resource.metadata.name = has_substring(\"inspec\")" }, description: 'group description') control 'google_monitoring_group-1.0' do impact 1.0 @@ -30,9 +30,7 @@ it { should exist } its('name') { should cmp group['name'] } its('display_name') { should cmp group['display_name'] } - its('parent_name') { should cmp group['parent_name'] } its('filter') { should cmp group['filter'] } - end describe google_monitoring_group(name: "does_not_exit") do diff --git a/test/integration/verify/controls/google_monitoring_groups.rb b/test/integration/verify/controls/google_monitoring_groups.rb index ee071f9e..e56b5fcf 100644 --- a/test/integration/verify/controls/google_monitoring_groups.rb +++ b/test/integration/verify/controls/google_monitoring_groups.rb @@ -16,17 +16,20 @@ gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') - group = input('group', value: { - "name": "value_name", - "display_name": "value_displayname", - "parent_name": "value_parentname", - "filter": "value_filter" +group = input('group', value: { + "name": "projects/ppradhan/groups/1973775459523949291", + "display_name": "inspec-test-group", + "parent_name": "projects/ppradhan", + "filter": "resource.metadata.name = has_substring(\"inspec\")" }, description: 'group description') control 'google_monitoring_groups-1.0' do impact 1.0 title 'google_monitoring_groups resource test' - describe google_monitoring_groups(name: group['name']) do + describe google_monitoring_groups(name: group['name']) do it { should exist } + its('names') { should include group['name'] } + its('display_names') { should include group['display_name'] } + its('filters') { should include group['filter'] } end end