From f360591bbd26a3c945474bcb46e9deb5cee962a5 Mon Sep 17 00:00:00 2001 From: sa-progress Date: Tue, 28 Sep 2021 16:54:53 +0530 Subject: [PATCH 1/3] added resources --- libraries/google_compute_accelerator_type.rb | 80 +++++++++++++++ libraries/google_compute_accelerator_types.rb | 99 +++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100644 libraries/google_compute_accelerator_type.rb create mode 100644 libraries/google_compute_accelerator_types.rb diff --git a/libraries/google_compute_accelerator_type.rb b/libraries/google_compute_accelerator_type.rb new file mode 100644 index 000000000..c30a83e8a --- /dev/null +++ b/libraries/google_compute_accelerator_type.rb @@ -0,0 +1,80 @@ + +# frozen_string_literal: false + +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# 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/zone_deprecated' + +# A provider to manage Compute Engine resources. +class ComputeAcceleratorType < GcpResourceBase + name 'google_compute_accelerator_type' + desc 'Accelerator Type' + supports platform: 'gcp' + + attr_reader :params + attr_reader :creation_timestamp + attr_reader :deprecated + attr_reader :description + attr_reader :id + attr_reader :name + attr_reader :zone + attr_reader :selfLink + attr_reader :availableCpuPlatforms + + 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 + @creation_timestamp = parse_time_string(@fetched['creationTimestamp']) + @deprecated = GoogleInSpec::Compute::Property::ZoneDeprecated.new(@fetched['deprecated'], to_s) + @description = @fetched['description'] + @id = @fetched['id'] + @name = @fetched['name'] + @zone = @fetched['zone'] + @selfLink = @fetched['selfLink'] + @availableCpuPlatforms = @fetched['availableCpuPlatforms'] + end + + # Handles parsing RFC3339 time string + def parse_time_string(time_string) + time_string ? Time.parse(time_string) : nil + end + + def exists? + !@fetched.nil? + end + + def to_s + "AcceleratorType #{@params[:name]}" + end + + private + + def product_url(beta = false) + if beta + 'https://compute.googleapis.com/compute/beta/' + else + 'https://compute.googleapis.com/compute/v1/' + end + end + + def resource_base_url + 'projects/{{project}}/zones/{{zone}}/acceleratorTypes/{{accelerator_id}}' + end +end diff --git a/libraries/google_compute_accelerator_types.rb b/libraries/google_compute_accelerator_types.rb new file mode 100644 index 000000000..89734907c --- /dev/null +++ b/libraries/google_compute_accelerator_types.rb @@ -0,0 +1,99 @@ +# frozen_string_literal: false + +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# 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 ComputeAcceleratorTypes < GcpResourceBase + name 'google_compute_accelerator_types' + desc 'Zone plural resource' + supports platform: 'gcp' + + attr_reader :table + + filter_table_config = FilterTable.create + + filter_table_config.add(:creation_timestamps, field: :creation_timestamp) + filter_table_config.add(:deprecateds, field: :deprecated) + filter_table_config.add(:descriptions, field: :description) + filter_table_config.add(:ids, field: :id) + filter_table_config.add(:names, field: :name) + filter_table_config.add(:zones, field: :zone) + + filter_table_config.connect(self, :table) + + def initialize(params = {}) + super(params.merge({ use_http_transport: true })) + @params = params + @table = fetch_wrapped_resource('items') + 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 + { + 'creationTimestamp' => ->(obj) { return :creation_timestamp, parse_time_string(obj['creationTimestamp']) }, + 'deprecated' => ->(obj) { return :deprecated, GoogleInSpec::Compute::Property::ZoneDeprecated.new(obj['deprecated'], to_s) }, + 'description' => ->(obj) { return :description, obj['description'] }, + 'id' => ->(obj) { return :id, obj['id'] }, + 'name' => ->(obj) { return :name, obj['name'] }, + 'zone' => ->(obj) { return :zone, obj['zone'] }, + } + end + + # Handles parsing RFC3339 time string + def parse_time_string(time_string) + time_string ? Time.parse(time_string) : nil + end + + private + + def product_url(beta = false) + if beta + 'https://compute.googleapis.com/compute/beta/' + else + 'https://compute.googleapis.com/compute/v1/' + end + end + + def resource_base_url + 'projects/{{project}}/zones/{{zone}}/acceleratorTypes' + end +end + From 6b4f33d3d7204d2aeeee789d66075e4ff3012e0f Mon Sep 17 00:00:00 2001 From: sa-progress Date: Tue, 19 Oct 2021 14:11:34 +0530 Subject: [PATCH 2/3] Added new resource compute#acceleratorType Signed-off-by: sa-progress --- .../google_compute_accelerator_type.md | 50 ++++++++++++++++++ .../google_compute_accelerator_types.md | 34 +++++++++++++ .../property/acceleratortype_deprecated.rb | 51 +++++++++++++++++++ libraries/google_compute_accelerator_type.rb | 23 +++------ libraries/google_compute_accelerator_types.rb | 15 ++---- .../configuration/gcp_inspec_config.rb | 8 +-- .../configuration/mm-attributes.yml | 7 ++- .../google_compute_accelerator_type.rb | 27 ++++++++++ .../google_compute_accelerator_types.rb | 27 ++++++++++ 9 files changed, 210 insertions(+), 32 deletions(-) create mode 100644 docs/resources/google_compute_accelerator_type.md create mode 100644 docs/resources/google_compute_accelerator_types.md create mode 100644 libraries/google/compute/property/acceleratortype_deprecated.rb create mode 100644 test/integration/verify/controls/google_compute_accelerator_type.rb create mode 100644 test/integration/verify/controls/google_compute_accelerator_types.rb diff --git a/docs/resources/google_compute_accelerator_type.md b/docs/resources/google_compute_accelerator_type.md new file mode 100644 index 000000000..5b8a972a5 --- /dev/null +++ b/docs/resources/google_compute_accelerator_type.md @@ -0,0 +1,50 @@ +--- +title: About the google_compute_accelerator_type resource +platform: gcp +--- + +## Syntax +A `google_compute_accelerator_type` is used to test a Google AcceleratorType resource + +## Examples +``` +describe google_compute_accelerator_type(project: 'chef-gcp-inspec', zone: 'us-east1-b', name: 'accelerator_id') do + it { should exist } + it { should be_up } +end +``` + +## Properties +Properties that can be accessed from the `google_compute_accelerator_type` resource: + + + * `creation_timestamp`: Creation timestamp in RFC3339 text format. + + * `deprecated`: The deprecation status associated with this accelerator type. + + * `state`: An optional RFC3339 timestamp on or after which the state of this resource is intended to change to DELETED. This is only informational and the status will not change unless the client explicitly changes it. + + * `deprecated`: An optional RFC3339 timestamp on or after which the state of this resource is intended to change to DEPRECATED. This is only informational and the status will not change unless the client explicitly changes it. + + * `obsolete`: An optional RFC3339 timestamp on or after which the state of this resource is intended to change to OBSOLETE. This is only informational and the status will not change unless the client explicitly changes it. + + * `replacement`: The URL of the suggested replacement for a deprecated resource. The suggested replacement resource must be the same kind of resource as the deprecated resource. + + * `state`: The deprecation state of this resource. This can be DEPRECATED, OBSOLETE, or DELETED. Operations which create a new resource using a DEPRECATED resource will return successfully, but with a warning indicating the deprecated resource and recommending its replacement. Operations which use OBSOLETE or DELETED resources will be rejected and result in an error. + Possible values: + * DEPRECATED + * OBSOLETE + * DELETED + + * `description`: An optional textual description of the resource. + + * `id`: The unique identifier for the resource. + + * `name`: Name of the resource. + + * `zone`: The name of the zone where the accelerator type resides. + + +## 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_accelerator_types.md b/docs/resources/google_compute_accelerator_types.md new file mode 100644 index 000000000..73f5df95b --- /dev/null +++ b/docs/resources/google_compute_accelerator_types.md @@ -0,0 +1,34 @@ +--- +title: About the google_compute_accelerator_types resource +platform: gcp +--- + +## Syntax +A `google_compute_accelerator_types` is used to test a Google AcceleratorType resource + +## Examples +``` +describe google_compute_accelerator_types(project: 'chef-gcp-inspec', zone: 'us-east1-b') do +it { should exist } +it { should be_up } +end +``` + +## Properties +Properties that can be accessed from the `google_compute_accelerator_types` resource: + +See [google_compute_accelerator_type.md](google_compute_accelerator_type.md) for more detailed information + * `creation_timestamps`: an array of `google_compute_accelerator_type` creation_timestamp + * `deprecateds`: an array of `google_compute_accelerator_type` deprecated + * `descriptions`: an array of `google_compute_accelerator_type` description + * `ids`: an array of `google_compute_accelerator_type` id + * `names`: an array of `google_compute_accelerator_type` name + * `zones`: an array of `google_compute_accelerator_type` zone + +## 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/acceleratortype_deprecated.rb b/libraries/google/compute/property/acceleratortype_deprecated.rb new file mode 100644 index 000000000..ed046081a --- /dev/null +++ b/libraries/google/compute/property/acceleratortype_deprecated.rb @@ -0,0 +1,51 @@ +# 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 AcceleratorTypeDeprecated + attr_reader :state + + attr_reader :deprecated + + attr_reader :obsolete + + attr_reader :replacement + + attr_reader :state + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @state = parse_time_string(args['state']) + @deprecated = parse_time_string(args['deprecated']) + @obsolete = parse_time_string(args['obsolete']) + @replacement = args['replacement'] + @state = args['state'] + end + + def to_s + "#{@parent_identifier} AcceleratorTypeDeprecated" + end + + # Handles parsing RFC3339 time string + def parse_time_string(time_string) + time_string ? Time.parse(time_string) : nil + end + end + end + end +end diff --git a/libraries/google_compute_accelerator_type.rb b/libraries/google_compute_accelerator_type.rb index c30a83e8a..7273196b3 100644 --- a/libraries/google_compute_accelerator_type.rb +++ b/libraries/google_compute_accelerator_type.rb @@ -1,9 +1,8 @@ - # frozen_string_literal: false # ---------------------------------------------------------------------------- # -# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# *** AUTO GENERATED CODE *** Type: MMv1 *** # # ---------------------------------------------------------------------------- # @@ -15,12 +14,12 @@ # # ---------------------------------------------------------------------------- require 'gcp_backend' -require 'google/compute/property/zone_deprecated' +require 'google/compute/property/acceleratortype_deprecated' # A provider to manage Compute Engine resources. class ComputeAcceleratorType < GcpResourceBase name 'google_compute_accelerator_type' - desc 'Accelerator Type' + desc 'AcceleratorType' supports platform: 'gcp' attr_reader :params @@ -30,8 +29,6 @@ class ComputeAcceleratorType < GcpResourceBase attr_reader :id attr_reader :name attr_reader :zone - attr_reader :selfLink - attr_reader :availableCpuPlatforms def initialize(params) super(params.merge({ use_http_transport: true })) @@ -42,13 +39,11 @@ def initialize(params) def parse @creation_timestamp = parse_time_string(@fetched['creationTimestamp']) - @deprecated = GoogleInSpec::Compute::Property::ZoneDeprecated.new(@fetched['deprecated'], to_s) + @deprecated = GoogleInSpec::Compute::Property::AcceleratorTypeDeprecated.new(@fetched['deprecated'], to_s) @description = @fetched['description'] @id = @fetched['id'] @name = @fetched['name'] @zone = @fetched['zone'] - @selfLink = @fetched['selfLink'] - @availableCpuPlatforms = @fetched['availableCpuPlatforms'] end # Handles parsing RFC3339 time string @@ -66,15 +61,11 @@ def to_s private - def product_url(beta = false) - if beta - 'https://compute.googleapis.com/compute/beta/' - else - 'https://compute.googleapis.com/compute/v1/' - end + def product_url(_ = nil) + 'https://compute.googleapis.com/compute/v1/' end def resource_base_url - 'projects/{{project}}/zones/{{zone}}/acceleratorTypes/{{accelerator_id}}' + 'projects/{{project}}/zones/{{zone}}/acceleratorTypes/{{name}}' end end diff --git a/libraries/google_compute_accelerator_types.rb b/libraries/google_compute_accelerator_types.rb index 89734907c..691e3512f 100644 --- a/libraries/google_compute_accelerator_types.rb +++ b/libraries/google_compute_accelerator_types.rb @@ -2,7 +2,7 @@ # ---------------------------------------------------------------------------- # -# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# *** AUTO GENERATED CODE *** Type: MMv1 *** # # ---------------------------------------------------------------------------- # @@ -16,7 +16,7 @@ require 'gcp_backend' class ComputeAcceleratorTypes < GcpResourceBase name 'google_compute_accelerator_types' - desc 'Zone plural resource' + desc 'AcceleratorType plural resource' supports platform: 'gcp' attr_reader :table @@ -69,7 +69,7 @@ def transform(key, value) def transformers { 'creationTimestamp' => ->(obj) { return :creation_timestamp, parse_time_string(obj['creationTimestamp']) }, - 'deprecated' => ->(obj) { return :deprecated, GoogleInSpec::Compute::Property::ZoneDeprecated.new(obj['deprecated'], to_s) }, + 'deprecated' => ->(obj) { return :deprecated, GoogleInSpec::Compute::Property::AcceleratorTypeDeprecated.new(obj['deprecated'], to_s) }, 'description' => ->(obj) { return :description, obj['description'] }, 'id' => ->(obj) { return :id, obj['id'] }, 'name' => ->(obj) { return :name, obj['name'] }, @@ -84,16 +84,11 @@ def parse_time_string(time_string) private - def product_url(beta = false) - if beta - 'https://compute.googleapis.com/compute/beta/' - else - 'https://compute.googleapis.com/compute/v1/' - end + def product_url(_ = nil) + 'https://compute.googleapis.com/compute/v1/' end def resource_base_url 'projects/{{project}}/zones/{{zone}}/acceleratorTypes' end end - diff --git a/test/integration/configuration/gcp_inspec_config.rb b/test/integration/configuration/gcp_inspec_config.rb index 579be4ad5..cde61462e 100644 --- a/test/integration/configuration/gcp_inspec_config.rb +++ b/test/integration/configuration/gcp_inspec_config.rb @@ -21,10 +21,10 @@ def initialize(seed = nil) end @config = { # Generic GCP resource parameters - :gcp_organization_id => '953310715741', - :gcp_project_name => "SPaterson Project", - :gcp_project_id => "spaterson-project", - :gcp_project_number => "1041358276233", + :gcp_organization_id => '827482578277', + :gcp_project_name => "ppradhan", + :gcp_project_id => "ppradhan", + :gcp_project_number => "165434197229", # Determine the storage account name and the admin password :gcp_location => "europe-west2", :gcp_zone => "europe-west2-a", diff --git a/test/integration/configuration/mm-attributes.yml b/test/integration/configuration/mm-attributes.yml index 3fc9f34ea..88b70f4a4 100644 --- a/test/integration/configuration/mm-attributes.yml +++ b/test/integration/configuration/mm-attributes.yml @@ -249,11 +249,11 @@ dataproc_cluster: num_instances: 1 machine_type: n1-standard-1 boot_disk_type: pd-ssd - boot_disk_size_gb: 15 + boot_disk_size_gb: 30 worker_config: num_instances: 2 machine_type: n1-standard-1 - boot_disk_size_gb: 20 + boot_disk_size_gb: 40 num_local_ssds: 1 preemptible_worker_config: num_instances: 0 @@ -447,3 +447,6 @@ security_policy: memcache_instance: name: mem-instance + +accelerator_type: + name: accelerator_id diff --git a/test/integration/verify/controls/google_compute_accelerator_type.rb b/test/integration/verify/controls/google_compute_accelerator_type.rb new file mode 100644 index 000000000..0cd04ac01 --- /dev/null +++ b/test/integration/verify/controls/google_compute_accelerator_type.rb @@ -0,0 +1,27 @@ +# ---------------------------------------------------------------------------- +# +# *** 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_accelerator_type resource.' + +gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.') +accelerator_type = attribute('accelerator_type', default: null, description: 'The accelerator type') +control 'google_compute_accelerator_type-1.0' do + impact 1.0 + title 'google_compute_accelerator_type resource test' + + describe google_compute_accelerator_type(project: gcp_project_id, zone: 'us-east1-b', name: accelerator_type['name']) do + it { should exist } + it { should be_up } + end +end diff --git a/test/integration/verify/controls/google_compute_accelerator_types.rb b/test/integration/verify/controls/google_compute_accelerator_types.rb new file mode 100644 index 000000000..c0d763eda --- /dev/null +++ b/test/integration/verify/controls/google_compute_accelerator_types.rb @@ -0,0 +1,27 @@ +# ---------------------------------------------------------------------------- +# +# *** 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_accelerator_types resource.' + +gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.') +accelerator_type = attribute('accelerator_type', default: null, description: 'The accelerator type') +control 'google_compute_accelerator_types-1.0' do + impact 1.0 + title 'google_compute_accelerator_types resource test' + + describe google_compute_accelerator_types(project: gcp_project_id, zone: 'us-east1-b') do + it { should exist } + it { should be_up } + end +end From 2a30bcca4d8c504755da8a4bfa1240cfe0100cee Mon Sep 17 00:00:00 2001 From: sa-progress Date: Wed, 20 Oct 2021 10:01:22 +0530 Subject: [PATCH 3/3] added new resource --- libraries/google/compute/property/acceleratortype_deprecated.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/google/compute/property/acceleratortype_deprecated.rb b/libraries/google/compute/property/acceleratortype_deprecated.rb index ed046081a..a7a3f4750 100644 --- a/libraries/google/compute/property/acceleratortype_deprecated.rb +++ b/libraries/google/compute/property/acceleratortype_deprecated.rb @@ -25,8 +25,6 @@ class AcceleratorTypeDeprecated attr_reader :replacement - attr_reader :state - def initialize(args = nil, parent_identifier = nil) return if args.nil? @parent_identifier = parent_identifier