From 5c03d228d6a6a29a875201663a5a592754fe32a7 Mon Sep 17 00:00:00 2001 From: Samir Anand Date: Wed, 29 Nov 2023 23:54:18 +0530 Subject: [PATCH 1/2] Automatically generated by magic modules for service: compute and resource: RegionNetworkEndpointGroup. This commit includes the following changes: - Singular Resource - Plural Resource - Documentation updates - Terraform configuration - Integration tests Signed-off-by: Samir Anand --- .../configuration/mm-attributes.yml | 30 ++++- ...e_compute_region_network_endpoint_group.md | 117 ++++++++++++++++++ ..._compute_region_network_endpoint_groups.md | 46 +++++++ .../regionnetworkendpointgroup_annotations.rb | 34 +++++ .../regionnetworkendpointgroup_app_engine.rb | 40 ++++++ ...gionnetworkendpointgroup_cloud_function.rb | 37 ++++++ .../regionnetworkendpointgroup_cloud_run.rb | 40 ++++++ .../regionnetworkendpointgroup_psc_data.rb | 40 ++++++ ...e_compute_region_network_endpoint_group.rb | 96 ++++++++++++++ ..._compute_region_network_endpoint_groups.rb | 115 +++++++++++++++++ ...e_compute_region_network_endpoint_group.rb | 59 +++++++++ ..._compute_region_network_endpoint_groups.rb | 42 +++++++ 12 files changed, 695 insertions(+), 1 deletion(-) create mode 100644 docs/resources/google_compute_region_network_endpoint_group.md create mode 100644 docs/resources/google_compute_region_network_endpoint_groups.md create mode 100644 libraries/google/compute/property/regionnetworkendpointgroup_annotations.rb create mode 100644 libraries/google/compute/property/regionnetworkendpointgroup_app_engine.rb create mode 100644 libraries/google/compute/property/regionnetworkendpointgroup_cloud_function.rb create mode 100644 libraries/google/compute/property/regionnetworkendpointgroup_cloud_run.rb create mode 100644 libraries/google/compute/property/regionnetworkendpointgroup_psc_data.rb create mode 100644 libraries/google_compute_region_network_endpoint_group.rb create mode 100644 libraries/google_compute_region_network_endpoint_groups.rb create mode 100644 test/integration/verify/controls/google_compute_region_network_endpoint_group.rb create mode 100644 test/integration/verify/controls/google_compute_region_network_endpoint_groups.rb diff --git a/build/inspec/test/integration/configuration/mm-attributes.yml b/build/inspec/test/integration/configuration/mm-attributes.yml index eab23d3ea..d80aaba57 100644 --- a/build/inspec/test/integration/configuration/mm-attributes.yml +++ b/build/inspec/test/integration/configuration/mm-attributes.yml @@ -882,4 +882,32 @@ tensorboard_experiment_run_time_series_resource: value_type : "value_valuetype" project_location_image_version: - parent : "value_parent" \ No newline at end of file + parent : "value_parent" +vpn_gateway: + project : "value_project" + region : "value_region" + vpn_gateway : "value_vpngateway" + kind : "value_kind" + id : "value_id" + creation_timestamp : "value_creationtimestamp" + name : "value_name" + description : "value_description" + network : "value_network" + self_link : "value_selflink" + label_fingerprint : "value_labelfingerprint" + stack_type : "value_stacktype" +region_network_endpoint_group: + network_endpoint_group : "value_networkendpointgroup" + project : "value_project" + kind : "value_kind" + id : "value_id" + creation_timestamp : "value_creationtimestamp" + self_link : "value_selflink" + name : "value_name" + description : "value_description" + network_endpoint_type : "value_networkendpointtype" + region : "value_region" + zone : "value_zone" + network : "value_network" + subnetwork : "value_subnetwork" + psc_target_service : "value_psctargetservice" \ No newline at end of file diff --git a/docs/resources/google_compute_region_network_endpoint_group.md b/docs/resources/google_compute_region_network_endpoint_group.md new file mode 100644 index 000000000..40c050b38 --- /dev/null +++ b/docs/resources/google_compute_region_network_endpoint_group.md @@ -0,0 +1,117 @@ +--- +title: About the google_compute_region_network_endpoint_group resource +platform: gcp +--- + +## Syntax +A `google_compute_region_network_endpoint_group` is used to test a Google RegionNetworkEndpointGroup resource + +## Examples +``` +describe google_compute_region_network_endpoint_group(networkEndpointGroup: ' ', project: 'chef-gcp-inspec', region: ' value_region') do + it { should exist } + its('kind') { should cmp 'value_kind' } + its('id') { should cmp 'value_id' } + its('creation_timestamp') { should cmp 'value_creationtimestamp' } + its('self_link') { should cmp 'value_selflink' } + its('name') { should cmp 'value_name' } + its('description') { should cmp 'value_description' } + its('network_endpoint_type') { should cmp 'value_networkendpointtype' } + its('region') { should cmp 'value_region' } + its('zone') { should cmp 'value_zone' } + its('network') { should cmp 'value_network' } + its('subnetwork') { should cmp 'value_subnetwork' } + its('psc_target_service') { should cmp 'value_psctargetservice' } + +end + +describe google_compute_region_network_endpoint_group(networkEndpointGroup: ' ', project: 'chef-gcp-inspec', region: ' value_region') do + it { should_not exist } +end +``` + +## Properties +Properties that can be accessed from the `google_compute_region_network_endpoint_group` resource: + + + * `kind`: [Output Only] Type of the resource. Always compute#networkEndpointGroup for network endpoint group. + + * `id`: [Output Only] The unique identifier for the resource. This identifier is defined by the server. + + * `creation_timestamp`: [Output Only] Creation timestamp in RFC3339 text format. + + * `self_link`: [Output Only] Server-defined URL for the resource. + + * `name`: Name of the resource; provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash. + + * `description`: An optional description of this resource. Provide this property when you create the resource. + + * `network_endpoint_type`: Type of network endpoints in this network endpoint group. Can be one of GCE_VM_IP, GCE_VM_IP_PORT, NON_GCP_PRIVATE_IP_PORT, INTERNET_FQDN_PORT, INTERNET_IP_PORT, SERVERLESS, PRIVATE_SERVICE_CONNECT. + Possible values: + * GCE_VM_IP + * GCE_VM_IP_PORT + * INTERNET_FQDN_PORT + * INTERNET_IP_PORT + * NON_GCP_PRIVATE_IP_PORT + * PRIVATE_SERVICE_CONNECT + * SERVERLESS + + * `size`: [Output only] Number of network endpoints in the network endpoint group. + + * `region`: [Output Only] The URL of the region where the network endpoint group is located. + + * `zone`: [Output Only] The URL of the zone where the network endpoint group is located. + + * `network`: The URL of the network to which all network endpoints in the NEG belong. Uses "default" project network if unspecified. + + * `subnetwork`: Optional URL of the subnetwork to which all network endpoints in the NEG belong. + + * `default_port`: The default port used if the port number is not specified in the network endpoint. + + * `annotations`: Metadata defined as annotations on the network endpoint group. + + * `additional_properties`: + + * `cloud_run`: Configuration for a Cloud Run network endpoint group (NEG). The service must be provided explicitly or in the URL mask. The tag is optional, may be provided explicitly or in the URL mask. Note: Cloud Run service must be in the same project and located in the same region as the Serverless NEG. + + * `service`: Cloud Run service is the main resource of Cloud Run. The service must be 1-63 characters long, and comply with RFC1035. Example value: "run-service". + + * `tag`: Optional Cloud Run tag represents the "named-revision" to provide additional fine-grained traffic routing information. The tag must be 1-63 characters long, and comply with RFC1035. Example value: "revision-0010". + + * `url_mask`: A template to parse and fields from a request URL. URL mask allows for routing to multiple Run services without having to create multiple network endpoint groups and backend services. For example, request URLs "foo1.domain.com/bar1" and "foo1.domain.com/bar2" can be backed by the same Serverless Network Endpoint Group (NEG) with URL mask ".domain.com/". The URL mask will parse them to { service="bar1", tag="foo1" } and { service="bar2", tag="foo2" } respectively. + + * `app_engine`: Configuration for an App Engine network endpoint group (NEG). The service is optional, may be provided explicitly or in the URL mask. The version is optional and can only be provided explicitly or in the URL mask when service is present. Note: App Engine service must be in the same project and located in the same region as the Serverless NEG. + + * `service`: Optional serving service. The service name is case-sensitive and must be 1-63 characters long. Example value: "default", "my-service". + + * `version`: Optional serving version. The version name is case-sensitive and must be 1-100 characters long. Example value: "v1", "v2". + + * `url_mask`: A template to parse service and version fields from a request URL. URL mask allows for routing to multiple App Engine services without having to create multiple Network Endpoint Groups and backend services. For example, the request URLs "foo1-dot-appname.appspot.com/v1" and "foo1-dot-appname.appspot.com/v2" can be backed by the same Serverless NEG with URL mask "-dot-appname.appspot.com/". The URL mask will parse them to { service = "foo1", version = "v1" } and { service = "foo1", version = "v2" } respectively. + + * `cloud_function`: Configuration for a Cloud Function network endpoint group (NEG). The function must be provided explicitly or in the URL mask. Note: Cloud Function must be in the same project and located in the same region as the Serverless NEG. + + * `function`: A user-defined name of the Cloud Function. The function name is case-sensitive and must be 1-63 characters long. Example value: "func1". + + * `url_mask`: A template to parse function field from a request URL. URL mask allows for routing to multiple Cloud Functions without having to create multiple Network Endpoint Groups and backend services. For example, request URLs " mydomain.com/function1" and "mydomain.com/function2" can be backed by the same Serverless NEG with URL mask "/". The URL mask will parse them to { function = "function1" } and { function = "function2" } respectively. + + * `psc_target_service`: The target service url used to set up private service connection to a Google API or a PSC Producer Service Attachment. An example value is: "asia-northeast3-cloudkms.googleapis.com" + + * `psc_data`: All data that is specifically relevant to only network endpoint groups of type PRIVATE_SERVICE_CONNECT. + + * `consumer_psc_address`: [Output Only] Address allocated from given subnetwork for PSC. This IP address acts as a VIP for a PSC NEG, allowing it to act as an endpoint in L7 PSC-XLB. + + * `psc_connection_id`: [Output Only] The PSC connection id of the PSC Network Endpoint Group Consumer. + + * `psc_connection_status`: [Output Only] The connection status of the PSC Forwarding Rule. + Possible values: + * ACCEPTED + * CLOSED + * NEEDS_ATTENTION + * PENDING + * REJECTED + * STATUS_UNSPECIFIED + + +## GCP Permissions + +Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the current project. diff --git a/docs/resources/google_compute_region_network_endpoint_groups.md b/docs/resources/google_compute_region_network_endpoint_groups.md new file mode 100644 index 000000000..c4f232e83 --- /dev/null +++ b/docs/resources/google_compute_region_network_endpoint_groups.md @@ -0,0 +1,46 @@ +--- +title: About the google_compute_region_network_endpoint_groups resource +platform: gcp +--- + +## Syntax +A `google_compute_region_network_endpoint_groups` is used to test a Google RegionNetworkEndpointGroup resource + +## Examples +``` + describe google_compute_region_network_endpoint_groups(project: 'chef-gcp-inspec', region: ' value_region') do + it { should exist } + end +``` + +## Properties +Properties that can be accessed from the `google_compute_region_network_endpoint_groups` resource: + +See [google_compute_region_network_endpoint_group.md](google_compute_region_network_endpoint_group.md) for more detailed information + * `kinds`: an array of `google_compute_region_network_endpoint_group` kind + * `ids`: an array of `google_compute_region_network_endpoint_group` id + * `creation_timestamps`: an array of `google_compute_region_network_endpoint_group` creation_timestamp + * `self_links`: an array of `google_compute_region_network_endpoint_group` self_link + * `names`: an array of `google_compute_region_network_endpoint_group` name + * `descriptions`: an array of `google_compute_region_network_endpoint_group` description + * `network_endpoint_types`: an array of `google_compute_region_network_endpoint_group` network_endpoint_type + * `sizes`: an array of `google_compute_region_network_endpoint_group` size + * `regions`: an array of `google_compute_region_network_endpoint_group` region + * `zones`: an array of `google_compute_region_network_endpoint_group` zone + * `networks`: an array of `google_compute_region_network_endpoint_group` network + * `subnetworks`: an array of `google_compute_region_network_endpoint_group` subnetwork + * `default_ports`: an array of `google_compute_region_network_endpoint_group` default_port + * `annotations`: an array of `google_compute_region_network_endpoint_group` annotations + * `cloud_runs`: an array of `google_compute_region_network_endpoint_group` cloud_run + * `app_engines`: an array of `google_compute_region_network_endpoint_group` app_engine + * `cloud_functions`: an array of `google_compute_region_network_endpoint_group` cloud_function + * `psc_target_services`: an array of `google_compute_region_network_endpoint_group` psc_target_service + * `psc_data`: an array of `google_compute_region_network_endpoint_group` psc_data + +## 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 [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the current project. diff --git a/libraries/google/compute/property/regionnetworkendpointgroup_annotations.rb b/libraries/google/compute/property/regionnetworkendpointgroup_annotations.rb new file mode 100644 index 000000000..029f92d7c --- /dev/null +++ b/libraries/google/compute/property/regionnetworkendpointgroup_annotations.rb @@ -0,0 +1,34 @@ +# 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. +# +# ---------------------------------------------------------------------------- +module GoogleInSpec + module Compute + module Property + class RegionNetworkEndpointGroupAnnotations + attr_reader :additional_properties + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @additional_properties = args['additionalProperties'] + end + + def to_s + "#{@parent_identifier} RegionNetworkEndpointGroupAnnotations" + end + end + end + end +end diff --git a/libraries/google/compute/property/regionnetworkendpointgroup_app_engine.rb b/libraries/google/compute/property/regionnetworkendpointgroup_app_engine.rb new file mode 100644 index 000000000..9a3dcf292 --- /dev/null +++ b/libraries/google/compute/property/regionnetworkendpointgroup_app_engine.rb @@ -0,0 +1,40 @@ +# 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. +# +# ---------------------------------------------------------------------------- +module GoogleInSpec + module Compute + module Property + class RegionNetworkEndpointGroupAppEngine + attr_reader :service + + attr_reader :version + + attr_reader :url_mask + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @service = args['service'] + @version = args['version'] + @url_mask = args['urlMask'] + end + + def to_s + "#{@parent_identifier} RegionNetworkEndpointGroupAppEngine" + end + end + end + end +end diff --git a/libraries/google/compute/property/regionnetworkendpointgroup_cloud_function.rb b/libraries/google/compute/property/regionnetworkendpointgroup_cloud_function.rb new file mode 100644 index 000000000..39d3a8869 --- /dev/null +++ b/libraries/google/compute/property/regionnetworkendpointgroup_cloud_function.rb @@ -0,0 +1,37 @@ +# 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. +# +# ---------------------------------------------------------------------------- +module GoogleInSpec + module Compute + module Property + class RegionNetworkEndpointGroupCloudFunction + attr_reader :function + + attr_reader :url_mask + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @function = args['function'] + @url_mask = args['urlMask'] + end + + def to_s + "#{@parent_identifier} RegionNetworkEndpointGroupCloudFunction" + end + end + end + end +end diff --git a/libraries/google/compute/property/regionnetworkendpointgroup_cloud_run.rb b/libraries/google/compute/property/regionnetworkendpointgroup_cloud_run.rb new file mode 100644 index 000000000..6e3afe2a6 --- /dev/null +++ b/libraries/google/compute/property/regionnetworkendpointgroup_cloud_run.rb @@ -0,0 +1,40 @@ +# 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. +# +# ---------------------------------------------------------------------------- +module GoogleInSpec + module Compute + module Property + class RegionNetworkEndpointGroupCloudRun + attr_reader :service + + attr_reader :tag + + attr_reader :url_mask + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @service = args['service'] + @tag = args['tag'] + @url_mask = args['urlMask'] + end + + def to_s + "#{@parent_identifier} RegionNetworkEndpointGroupCloudRun" + end + end + end + end +end diff --git a/libraries/google/compute/property/regionnetworkendpointgroup_psc_data.rb b/libraries/google/compute/property/regionnetworkendpointgroup_psc_data.rb new file mode 100644 index 000000000..157ce91a1 --- /dev/null +++ b/libraries/google/compute/property/regionnetworkendpointgroup_psc_data.rb @@ -0,0 +1,40 @@ +# 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. +# +# ---------------------------------------------------------------------------- +module GoogleInSpec + module Compute + module Property + class RegionNetworkEndpointGroupPscData + attr_reader :consumer_psc_address + + attr_reader :psc_connection_id + + attr_reader :psc_connection_status + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @consumer_psc_address = args['consumerPscAddress'] + @psc_connection_id = args['pscConnectionId'] + @psc_connection_status = args['pscConnectionStatus'] + end + + def to_s + "#{@parent_identifier} RegionNetworkEndpointGroupPscData" + end + end + end + end +end diff --git a/libraries/google_compute_region_network_endpoint_group.rb b/libraries/google_compute_region_network_endpoint_group.rb new file mode 100644 index 000000000..1b2151d4b --- /dev/null +++ b/libraries/google_compute_region_network_endpoint_group.rb @@ -0,0 +1,96 @@ +# 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' +require 'google/compute/property/regionnetworkendpointgroup_annotations' +require 'google/compute/property/regionnetworkendpointgroup_app_engine' +require 'google/compute/property/regionnetworkendpointgroup_cloud_function' +require 'google/compute/property/regionnetworkendpointgroup_cloud_run' +require 'google/compute/property/regionnetworkendpointgroup_psc_data' + +# A provider to manage Compute Engine resources. +class ComputeRegionNetworkEndpointGroup < GcpResourceBase + name 'google_compute_region_network_endpoint_group' + desc 'RegionNetworkEndpointGroup' + supports platform: 'gcp' + + attr_reader :params + attr_reader :kind + attr_reader :id + attr_reader :creation_timestamp + attr_reader :self_link + attr_reader :name + attr_reader :description + attr_reader :network_endpoint_type + attr_reader :size + attr_reader :region + attr_reader :zone + attr_reader :network + attr_reader :subnetwork + attr_reader :default_port + attr_reader :annotations + attr_reader :cloud_run + attr_reader :app_engine + attr_reader :cloud_function + attr_reader :psc_target_service + attr_reader :psc_data + + 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 + @kind = @fetched['kind'] + @id = @fetched['id'] + @creation_timestamp = @fetched['creationTimestamp'] + @self_link = @fetched['selfLink'] + @name = @fetched['name'] + @description = @fetched['description'] + @network_endpoint_type = @fetched['networkEndpointType'] + @size = @fetched['size'] + @region = @fetched['region'] + @zone = @fetched['zone'] + @network = @fetched['network'] + @subnetwork = @fetched['subnetwork'] + @default_port = @fetched['defaultPort'] + @annotations = GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupAnnotations.new(@fetched['annotations'], to_s) + @cloud_run = GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupCloudRun.new(@fetched['cloudRun'], to_s) + @app_engine = GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupAppEngine.new(@fetched['appEngine'], to_s) + @cloud_function = GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupCloudFunction.new(@fetched['cloudFunction'], to_s) + @psc_target_service = @fetched['pscTargetService'] + @psc_data = GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupPscData.new(@fetched['pscData'], to_s) + end + + def exists? + !@fetched.nil? + end + + def to_s + "RegionNetworkEndpointGroup #{@params[:networkEndpointGroup]}" + end + + private + + def product_url(_ = nil) + 'https://compute.googleapis.com/compute/v1/' + end + + def resource_base_url + 'projects/{{project}}/regions/{{region}}/networkEndpointGroups/{{network_endpoint_group}}' + end +end diff --git a/libraries/google_compute_region_network_endpoint_groups.rb b/libraries/google_compute_region_network_endpoint_groups.rb new file mode 100644 index 000000000..414702902 --- /dev/null +++ b/libraries/google_compute_region_network_endpoint_groups.rb @@ -0,0 +1,115 @@ +# 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 ComputeRegionNetworkEndpointGroups < GcpResourceBase + name 'google_compute_region_network_endpoint_groups' + desc 'RegionNetworkEndpointGroup plural resource' + supports platform: 'gcp' + + attr_reader :table + + filter_table_config = FilterTable.create + + filter_table_config.add(:kinds, field: :kind) + filter_table_config.add(:ids, field: :id) + filter_table_config.add(:creation_timestamps, field: :creation_timestamp) + filter_table_config.add(:self_links, field: :self_link) + filter_table_config.add(:names, field: :name) + filter_table_config.add(:descriptions, field: :description) + filter_table_config.add(:network_endpoint_types, field: :network_endpoint_type) + filter_table_config.add(:sizes, field: :size) + filter_table_config.add(:regions, field: :region) + filter_table_config.add(:zones, field: :zone) + filter_table_config.add(:networks, field: :network) + filter_table_config.add(:subnetworks, field: :subnetwork) + filter_table_config.add(:default_ports, field: :default_port) + filter_table_config.add(:annotations, field: :annotations) + filter_table_config.add(:cloud_runs, field: :cloud_run) + filter_table_config.add(:app_engines, field: :app_engine) + filter_table_config.add(:cloud_functions, field: :cloud_function) + filter_table_config.add(:psc_target_services, field: :psc_target_service) + filter_table_config.add(:psc_data, field: :psc_data) + + filter_table_config.connect(self, :table) + + def initialize(params = {}) + super(params.merge({ use_http_transport: true })) + @params = params + @table = fetch_wrapped_resource('regionNetworkEndpointGroups') + 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 + { + 'kind' => ->(obj) { return :kind, obj['kind'] }, + 'id' => ->(obj) { return :id, obj['id'] }, + 'creationTimestamp' => ->(obj) { return :creation_timestamp, obj['creationTimestamp'] }, + 'selfLink' => ->(obj) { return :self_link, obj['selfLink'] }, + 'name' => ->(obj) { return :name, obj['name'] }, + 'description' => ->(obj) { return :description, obj['description'] }, + 'networkEndpointType' => ->(obj) { return :network_endpoint_type, obj['networkEndpointType'] }, + 'size' => ->(obj) { return :size, obj['size'] }, + 'region' => ->(obj) { return :region, obj['region'] }, + 'zone' => ->(obj) { return :zone, obj['zone'] }, + 'network' => ->(obj) { return :network, obj['network'] }, + 'subnetwork' => ->(obj) { return :subnetwork, obj['subnetwork'] }, + 'defaultPort' => ->(obj) { return :default_port, obj['defaultPort'] }, + 'annotations' => ->(obj) { return :annotations, GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupAnnotations.new(obj['annotations'], to_s) }, + 'cloudRun' => ->(obj) { return :cloud_run, GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupCloudRun.new(obj['cloudRun'], to_s) }, + 'appEngine' => ->(obj) { return :app_engine, GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupAppEngine.new(obj['appEngine'], to_s) }, + 'cloudFunction' => ->(obj) { return :cloud_function, GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupCloudFunction.new(obj['cloudFunction'], to_s) }, + 'pscTargetService' => ->(obj) { return :psc_target_service, obj['pscTargetService'] }, + 'pscData' => ->(obj) { return :psc_data, GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupPscData.new(obj['pscData'], to_s) }, + } + end + + private + + def product_url(_ = nil) + 'https://compute.googleapis.com/compute/v1/' + end + + def resource_base_url + 'projects/{{project}}/regions/{{region}}/networkEndpointGroups' + end +end diff --git a/test/integration/verify/controls/google_compute_region_network_endpoint_group.rb b/test/integration/verify/controls/google_compute_region_network_endpoint_group.rb new file mode 100644 index 000000000..7d72dc2d0 --- /dev/null +++ b/test/integration/verify/controls/google_compute_region_network_endpoint_group.rb @@ -0,0 +1,59 @@ +# ---------------------------------------------------------------------------- +# +# *** 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_compute_region_network_endpoint_group resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + region_network_endpoint_group = input('region_network_endpoint_group', value: { + "network_endpoint_group": "value_networkendpointgroup", + "project": "value_project", + "kind": "value_kind", + "id": "value_id", + "creation_timestamp": "value_creationtimestamp", + "self_link": "value_selflink", + "name": "value_name", + "description": "value_description", + "network_endpoint_type": "value_networkendpointtype", + "region": "value_region", + "zone": "value_zone", + "network": "value_network", + "subnetwork": "value_subnetwork", + "psc_target_service": "value_psctargetservice" +}, description: 'region_network_endpoint_group description') +control 'google_compute_region_network_endpoint_group-1.0' do + impact 1.0 + title 'google_compute_region_network_endpoint_group resource test' + + describe google_compute_region_network_endpoint_group(networkEndpointGroup: region_network_endpoint_group['networkEndpointGroup'], project: gcp_project_id, region: region_network_endpoint_group['region']) do + it { should exist } + its('kind') { should cmp region_network_endpoint_group['kind'] } + its('id') { should cmp region_network_endpoint_group['id'] } + its('creation_timestamp') { should cmp region_network_endpoint_group['creation_timestamp'] } + its('self_link') { should cmp region_network_endpoint_group['self_link'] } + its('name') { should cmp region_network_endpoint_group['name'] } + its('description') { should cmp region_network_endpoint_group['description'] } + its('network_endpoint_type') { should cmp region_network_endpoint_group['network_endpoint_type'] } + its('region') { should cmp region_network_endpoint_group['region'] } + its('zone') { should cmp region_network_endpoint_group['zone'] } + its('network') { should cmp region_network_endpoint_group['network'] } + its('subnetwork') { should cmp region_network_endpoint_group['subnetwork'] } + its('psc_target_service') { should cmp region_network_endpoint_group['psc_target_service'] } + + end + + describe google_compute_region_network_endpoint_group(networkEndpointGroup: region_network_endpoint_group['networkEndpointGroup'], project: gcp_project_id, region: region_network_endpoint_group['region']) do + it { should_not exist } + end +end diff --git a/test/integration/verify/controls/google_compute_region_network_endpoint_groups.rb b/test/integration/verify/controls/google_compute_region_network_endpoint_groups.rb new file mode 100644 index 000000000..3aacfbe4e --- /dev/null +++ b/test/integration/verify/controls/google_compute_region_network_endpoint_groups.rb @@ -0,0 +1,42 @@ +# ---------------------------------------------------------------------------- +# +# *** 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_compute_region_network_endpoint_groups resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + region_network_endpoint_group = input('region_network_endpoint_group', value: { + "network_endpoint_group": "value_networkendpointgroup", + "project": "value_project", + "kind": "value_kind", + "id": "value_id", + "creation_timestamp": "value_creationtimestamp", + "self_link": "value_selflink", + "name": "value_name", + "description": "value_description", + "network_endpoint_type": "value_networkendpointtype", + "region": "value_region", + "zone": "value_zone", + "network": "value_network", + "subnetwork": "value_subnetwork", + "psc_target_service": "value_psctargetservice" +}, description: 'region_network_endpoint_group description') +control 'google_compute_region_network_endpoint_groups-1.0' do + impact 1.0 + title 'google_compute_region_network_endpoint_groups resource test' + + describe google_compute_region_network_endpoint_groups(project: gcp_project_id, region: region_network_endpoint_group['region']) do + it { should exist } + end +end From bd7c67d5211e5ed0dbf07a76c0de3fb8e86ad7f5 Mon Sep 17 00:00:00 2001 From: balasubramanian-s Date: Wed, 17 Jan 2024 18:51:49 +0530 Subject: [PATCH 2/2] update attributed and add tf scripts Signed-off-by: balasubramanian-s --- .../configuration/mm-attributes.yml | 0 ...e_compute_region_network_endpoint_group.md | 6 +-- ..._compute_region_network_endpoint_groups.rb | 40 +++++++++---------- test/integration/build/gcp-mm.tf | 10 ++++- .../configuration/mm-attributes.yml | 6 +++ ...e_compute_region_network_endpoint_group.rb | 8 ++-- ..._compute_region_network_endpoint_groups.rb | 4 +- 7 files changed, 44 insertions(+), 30 deletions(-) delete mode 100644 build/inspec/test/integration/configuration/mm-attributes.yml diff --git a/build/inspec/test/integration/configuration/mm-attributes.yml b/build/inspec/test/integration/configuration/mm-attributes.yml deleted file mode 100644 index e69de29bb..000000000 diff --git a/docs/resources/google_compute_region_network_endpoint_group.md b/docs/resources/google_compute_region_network_endpoint_group.md index 40c050b38..ebb624c7d 100644 --- a/docs/resources/google_compute_region_network_endpoint_group.md +++ b/docs/resources/google_compute_region_network_endpoint_group.md @@ -8,7 +8,7 @@ A `google_compute_region_network_endpoint_group` is used to test a Google Region ## Examples ``` -describe google_compute_region_network_endpoint_group(networkEndpointGroup: ' ', project: 'chef-gcp-inspec', region: ' value_region') do +describe google_compute_region_network_endpoint_group(network_endpoint_group: ' ', project: 'chef-gcp-inspec', region: ' value_region') do it { should exist } its('kind') { should cmp 'value_kind' } its('id') { should cmp 'value_id' } @@ -25,7 +25,7 @@ describe google_compute_region_network_endpoint_group(networkEndpointGroup: ' ', end -describe google_compute_region_network_endpoint_group(networkEndpointGroup: ' ', project: 'chef-gcp-inspec', region: ' value_region') do +describe google_compute_region_network_endpoint_group(network_endpoint_group: ' ', project: 'chef-gcp-inspec', region: ' value_region') do it { should_not exist } end ``` @@ -70,7 +70,7 @@ Properties that can be accessed from the `google_compute_region_network_endpoint * `annotations`: Metadata defined as annotations on the network endpoint group. - * `additional_properties`: + * `additional_properties`: * `cloud_run`: Configuration for a Cloud Run network endpoint group (NEG). The service must be provided explicitly or in the URL mask. The tag is optional, may be provided explicitly or in the URL mask. Note: Cloud Run service must be in the same project and located in the same region as the Serverless NEG. diff --git a/libraries/google_compute_region_network_endpoint_groups.rb b/libraries/google_compute_region_network_endpoint_groups.rb index 414702902..cb7c4a7b6 100644 --- a/libraries/google_compute_region_network_endpoint_groups.rb +++ b/libraries/google_compute_region_network_endpoint_groups.rb @@ -48,7 +48,7 @@ class ComputeRegionNetworkEndpointGroups < GcpResourceBase def initialize(params = {}) super(params.merge({ use_http_transport: true })) @params = params - @table = fetch_wrapped_resource('regionNetworkEndpointGroups') + @table = fetch_wrapped_resource('items') end def fetch_wrapped_resource(wrap_path) @@ -81,25 +81,25 @@ def transform(key, value) def transformers { - 'kind' => ->(obj) { return :kind, obj['kind'] }, - 'id' => ->(obj) { return :id, obj['id'] }, - 'creationTimestamp' => ->(obj) { return :creation_timestamp, obj['creationTimestamp'] }, - 'selfLink' => ->(obj) { return :self_link, obj['selfLink'] }, - 'name' => ->(obj) { return :name, obj['name'] }, - 'description' => ->(obj) { return :description, obj['description'] }, - 'networkEndpointType' => ->(obj) { return :network_endpoint_type, obj['networkEndpointType'] }, - 'size' => ->(obj) { return :size, obj['size'] }, - 'region' => ->(obj) { return :region, obj['region'] }, - 'zone' => ->(obj) { return :zone, obj['zone'] }, - 'network' => ->(obj) { return :network, obj['network'] }, - 'subnetwork' => ->(obj) { return :subnetwork, obj['subnetwork'] }, - 'defaultPort' => ->(obj) { return :default_port, obj['defaultPort'] }, - 'annotations' => ->(obj) { return :annotations, GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupAnnotations.new(obj['annotations'], to_s) }, - 'cloudRun' => ->(obj) { return :cloud_run, GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupCloudRun.new(obj['cloudRun'], to_s) }, - 'appEngine' => ->(obj) { return :app_engine, GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupAppEngine.new(obj['appEngine'], to_s) }, - 'cloudFunction' => ->(obj) { return :cloud_function, GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupCloudFunction.new(obj['cloudFunction'], to_s) }, - 'pscTargetService' => ->(obj) { return :psc_target_service, obj['pscTargetService'] }, - 'pscData' => ->(obj) { return :psc_data, GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupPscData.new(obj['pscData'], to_s) }, + 'kind' => ->(obj) { [:kind, obj['kind']] }, + 'id' => ->(obj) { [:id, obj['id']] }, + 'creationTimestamp' => ->(obj) { [:creation_timestamp, obj['creationTimestamp']] }, + 'selfLink' => ->(obj) { [:self_link, obj['selfLink']] }, + 'name' => ->(obj) { [:name, obj['name']] }, + 'description' => ->(obj) { [:description, obj['description']] }, + 'networkEndpointType' => ->(obj) { [:network_endpoint_type, obj['networkEndpointType']] }, + 'size' => ->(obj) { [:size, obj['size']] }, + 'region' => ->(obj) { [:region, obj['region']] }, + 'zone' => ->(obj) { [:zone, obj['zone']] }, + 'network' => ->(obj) { [:network, obj['network']] }, + 'subnetwork' => ->(obj) { [:subnetwork, obj['subnetwork']] }, + 'defaultPort' => ->(obj) { [:default_port, obj['defaultPort']] }, + 'annotations' => ->(obj) { [:annotations, GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupAnnotations.new(obj['annotations'], to_s)] }, + 'cloudRun' => ->(obj) { [:cloud_run, GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupCloudRun.new(obj['cloudRun'], to_s)] }, + 'appEngine' => ->(obj) { [:app_engine, GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupAppEngine.new(obj['appEngine'], to_s)] }, + 'cloudFunction' => ->(obj) { [:cloud_function, GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupCloudFunction.new(obj['cloudFunction'], to_s)] }, + 'pscTargetService' => ->(obj) { [:psc_target_service, obj['pscTargetService']] }, + 'pscData' => ->(obj) { [:psc_data, GoogleInSpec::Compute::Property::RegionNetworkEndpointGroupPscData.new(obj['pscData'], to_s)] }, } end diff --git a/test/integration/build/gcp-mm.tf b/test/integration/build/gcp-mm.tf index 0d3d82d67..1c4fdb970 100644 --- a/test/integration/build/gcp-mm.tf +++ b/test/integration/build/gcp-mm.tf @@ -239,7 +239,9 @@ variable "organization_envgroup" { variable "vpn_gateway" { type = any } - +variable "region_network_endpoint_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"] @@ -1692,3 +1694,9 @@ resource "google_apigee_envgroup_attachment" "engroup_attachment" { envgroup_id = var.apigee_organization_envgroup_attachment.envgroup_id environment = var.apigee_organization_envgroup_attachment.environment } +resource "google_compute_region_network_endpoint_group" "region_network_endpoint_group" { + name = var.region_network_endpoint_group.name + network_endpoint_type = var.region_network_endpoint_group.network_endpoint_type + region = var.region_network_endpoint_group.region + psc_target_service = var.region_network_endpoint_group.target_service +} diff --git a/test/integration/configuration/mm-attributes.yml b/test/integration/configuration/mm-attributes.yml index 8c37d5494..133b45d37 100644 --- a/test/integration/configuration/mm-attributes.yml +++ b/test/integration/configuration/mm-attributes.yml @@ -621,3 +621,9 @@ vpn_gateway: self_link : "value_selflink" label_fingerprint : "value_labelfingerprint" stack_type : "IPV4_ONLY" + +region_network_endpoint_group: + name: "inspec" + region: "us-central1" + network_endpoint_type: "PRIVATE_SERVICE_CONNECT" + target_service: "us-central1-logging.googleapis.com" diff --git a/test/integration/verify/controls/google_compute_region_network_endpoint_group.rb b/test/integration/verify/controls/google_compute_region_network_endpoint_group.rb index 7d72dc2d0..428f33cc6 100644 --- a/test/integration/verify/controls/google_compute_region_network_endpoint_group.rb +++ b/test/integration/verify/controls/google_compute_region_network_endpoint_group.rb @@ -17,7 +17,7 @@ gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') region_network_endpoint_group = input('region_network_endpoint_group', value: { - "network_endpoint_group": "value_networkendpointgroup", + "network_endpoint_group": "apigee-us-west1-xw8iaictllv4", "project": "value_project", "kind": "value_kind", "id": "value_id", @@ -26,7 +26,7 @@ "name": "value_name", "description": "value_description", "network_endpoint_type": "value_networkendpointtype", - "region": "value_region", + "region": "us-west1", "zone": "value_zone", "network": "value_network", "subnetwork": "value_subnetwork", @@ -36,7 +36,7 @@ impact 1.0 title 'google_compute_region_network_endpoint_group resource test' - describe google_compute_region_network_endpoint_group(networkEndpointGroup: region_network_endpoint_group['networkEndpointGroup'], project: gcp_project_id, region: region_network_endpoint_group['region']) do + describe google_compute_region_network_endpoint_group(network_endpoint_group: region_network_endpoint_group['network_endpoint_group'], project: gcp_project_id, region: region_network_endpoint_group['region']) do it { should exist } its('kind') { should cmp region_network_endpoint_group['kind'] } its('id') { should cmp region_network_endpoint_group['id'] } @@ -53,7 +53,7 @@ end - describe google_compute_region_network_endpoint_group(networkEndpointGroup: region_network_endpoint_group['networkEndpointGroup'], project: gcp_project_id, region: region_network_endpoint_group['region']) do + describe google_compute_region_network_endpoint_group(network_endpoint_group: region_network_endpoint_group['network_endpoint_group'], project: gcp_project_id, region: region_network_endpoint_group['region']) do it { should_not exist } end end diff --git a/test/integration/verify/controls/google_compute_region_network_endpoint_groups.rb b/test/integration/verify/controls/google_compute_region_network_endpoint_groups.rb index 3aacfbe4e..fd21b3c1e 100644 --- a/test/integration/verify/controls/google_compute_region_network_endpoint_groups.rb +++ b/test/integration/verify/controls/google_compute_region_network_endpoint_groups.rb @@ -17,7 +17,7 @@ gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') region_network_endpoint_group = input('region_network_endpoint_group', value: { - "network_endpoint_group": "value_networkendpointgroup", + "network_endpoint_group": "apigee-us-west1-xw8iaictllv4", "project": "value_project", "kind": "value_kind", "id": "value_id", @@ -26,7 +26,7 @@ "name": "value_name", "description": "value_description", "network_endpoint_type": "value_networkendpointtype", - "region": "value_region", + "region": "us-west1", "zone": "value_zone", "network": "value_network", "subnetwork": "value_subnetwork",