From 31c8ea5099a984bdca6b020e67c868bf82657bc2 Mon Sep 17 00:00:00 2001 From: Samir <85890442+sa-progress@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:05:53 +0530 Subject: [PATCH 1/4] Automatically generated by magic modules for service: compute_v1 and resource: Reservation. 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> --- docs/resources/google_compute_reservation.md | 179 ++++++++++++++++++ docs/resources/google_compute_reservations.md | 46 +++++ .../reservation_aggregate_reservation.rb | 45 +++++ ..._aggregate_reservation_in_use_resources.rb | 43 +++++ ...eservation_in_use_resources_accelerator.rb | 37 ++++ ...ggregate_reservation_reserved_resources.rb | 43 +++++ ...ervation_reserved_resources_accelerator.rb | 37 ++++ .../reservation_delete_after_duration.rb | 37 ++++ .../property/reservation_resource_policies.rb | 34 ++++ .../property/reservation_resource_status.rb | 35 ++++ ...resource_status_specific_sku_allocation.rb | 34 ++++ .../property/reservation_share_settings.rb | 45 +++++ .../reservation_share_settings_folder_map.rb | 34 ++++ .../reservation_share_settings_project_map.rb | 34 ++++ .../reservation_specific_reservation.rb | 49 +++++ ...pecific_reservation_instance_properties.rb | 54 ++++++ ..._instance_properties_guest_accelerators.rb | 45 +++++ ...ervation_instance_properties_local_ssds.rb | 45 +++++ libraries/google_compute_reservation.rb | 105 ++++++++++ libraries/google_compute_reservations.rb | 115 +++++++++++ .../controls/google_compute_reservation.rb | 57 ++++++ .../controls/google_compute_reservations.rb | 41 ++++ 22 files changed, 1194 insertions(+) create mode 100644 docs/resources/google_compute_reservation.md create mode 100644 docs/resources/google_compute_reservations.md create mode 100644 libraries/google/compute/property/reservation_aggregate_reservation.rb create mode 100644 libraries/google/compute/property/reservation_aggregate_reservation_in_use_resources.rb create mode 100644 libraries/google/compute/property/reservation_aggregate_reservation_in_use_resources_accelerator.rb create mode 100644 libraries/google/compute/property/reservation_aggregate_reservation_reserved_resources.rb create mode 100644 libraries/google/compute/property/reservation_aggregate_reservation_reserved_resources_accelerator.rb create mode 100644 libraries/google/compute/property/reservation_delete_after_duration.rb create mode 100644 libraries/google/compute/property/reservation_resource_policies.rb create mode 100644 libraries/google/compute/property/reservation_resource_status.rb create mode 100644 libraries/google/compute/property/reservation_resource_status_specific_sku_allocation.rb create mode 100644 libraries/google/compute/property/reservation_share_settings.rb create mode 100644 libraries/google/compute/property/reservation_share_settings_folder_map.rb create mode 100644 libraries/google/compute/property/reservation_share_settings_project_map.rb create mode 100644 libraries/google/compute/property/reservation_specific_reservation.rb create mode 100644 libraries/google/compute/property/reservation_specific_reservation_instance_properties.rb create mode 100644 libraries/google/compute/property/reservation_specific_reservation_instance_properties_guest_accelerators.rb create mode 100644 libraries/google/compute/property/reservation_specific_reservation_instance_properties_local_ssds.rb create mode 100644 libraries/google_compute_reservation.rb create mode 100644 libraries/google_compute_reservations.rb create mode 100644 test/integration/verify/controls/google_compute_reservation.rb create mode 100644 test/integration/verify/controls/google_compute_reservations.rb diff --git a/docs/resources/google_compute_reservation.md b/docs/resources/google_compute_reservation.md new file mode 100644 index 000000000..d0870c972 --- /dev/null +++ b/docs/resources/google_compute_reservation.md @@ -0,0 +1,179 @@ +--- +title: About the google_compute_reservation resource +platform: gcp +--- + +## Syntax +A `google_compute_reservation` is used to test a Google Reservation resource + +## Examples +``` +describe google_compute_reservation(project: 'chef-gcp-inspec', name: ' value_name', zone: ' value_zone') 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('self_link_with_id') { should cmp 'value_selflinkwithid' } + its('zone') { should cmp 'value_zone' } + its('description') { should cmp 'value_description' } + its('name') { should cmp 'value_name' } + its('commitment') { should cmp 'value_commitment' } + its('status') { should cmp 'value_status' } + its('delete_at_time') { should cmp 'value_deleteattime' } + +end + +describe google_compute_reservation(project: 'chef-gcp-inspec', name: "does_not_exit", zone: ' value_zone') do + it { should_not exist } +end +``` + +## Properties +Properties that can be accessed from the `google_compute_reservation` resource: + + + * `kind`: [Output Only] Type of the resource. Always compute#reservations for reservations. + + * `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 fully-qualified URL for this resource. + + * `self_link_with_id`: [Output Only] Server-defined URL for this resource with the resource id. + + * `zone`: Zone in which the reservation resides. A zone must be provided if the reservation is created within a commitment. + + * `description`: An optional description of this resource. Provide this property when you create the resource. + + * `name`: The name of the resource, provided by the client when initially creating the resource. The resource 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. + + * `specific_reservation`: This reservation type allows to pre allocate specific instance configuration. Next ID: 6 + + * `instance_properties`: Properties of the SKU instances being reserved. Next ID: 9 + + * `machine_type`: Specifies type of machine (name only) which has fixed number of vCPUs and fixed amount of memory. This also includes specifying custom machine type following custom-NUMBER_OF_CPUS-AMOUNT_OF_MEMORY pattern. + + * `guest_accelerators`: Specifies accelerator type and count. + + * `accelerator_type`: Full or partial URL of the accelerator type resource to attach to this instance. For example: projects/my-project/zones/us-central1-c/acceleratorTypes/nvidia-tesla-p100 If you are creating an instance template, specify only the accelerator name. See GPUs on Compute Engine for a full list of accelerator types. + + * `accelerator_count`: The number of the guest accelerator cards exposed to this instance. + + * `min_cpu_platform`: Minimum cpu platform the reservation. + + * `local_ssds`: Specifies amount of local ssd to reserve with each instance. The type of disk is local-ssd. + + * `disk_size_gb`: Specifies the size of the disk in base-2 GB. + + * `interface`: Specifies the disk interface to use for attaching this disk, which is either SCSI or NVME. The default is SCSI. For performance characteristics of SCSI over NVMe, see Local SSD performance. + Possible values: + * NVDIMM + * NVME + * SCSI + + * `maintenance_freeze_duration_hours`: Specifies the number of hours after reservation creation where instances using the reservation won't be scheduled for maintenance. + + * `location_hint`: An opaque location hint used to place the allocation close to other resources. This field is for use by internal tools that use the public API. + + * `maintenance_interval`: Specifies the frequency of planned maintenance events. The accepted values are: `PERIODIC`. + Possible values: + * AS_NEEDED + * PERIODIC + * RECURRENT + + * `count`: Specifies the number of resources that are allocated. + + * `in_use_count`: [Output Only] Indicates how many instances are in use. + + * `assured_count`: [Output Only] Indicates how many instances are actually usable currently. + + * `source_instance_template`: Specifies the instance template to create the reservation. If you use this field, you must exclude the instanceProperties field. This field is optional, and it can be a full or partial URL. For example, the following are all valid URLs to an instance template: - https://www.googleapis.com/compute/v1/projects/project /global/instanceTemplates/instanceTemplate - projects/project/global/instanceTemplates/instanceTemplate - global/instanceTemplates/instanceTemplate + + * `aggregate_reservation`: This reservation type is specified by total resource amounts (e.g. total count of CPUs) and can account for multiple instance SKUs. In other words, one can create instances of varying shapes against this reservation. + + * `vm_family`: The VM family that all instances scheduled against this reservation must belong to. + Possible values: + * VM_FAMILY_CLOUD_TPU_LITE_DEVICE_CT5L + * VM_FAMILY_CLOUD_TPU_LITE_POD_SLICE_CT5LP + * VM_FAMILY_CLOUD_TPU_POD_SLICE_CT4P + + * `reserved_resources`: List of reserved resources (CPUs, memory, accelerators). + + * `accelerator`: + + * `accelerator_count`: Number of accelerators of specified type. + + * `accelerator_type`: Full or partial URL to accelerator type. e.g. "projects/{PROJECT}/zones/{ZONE}/acceleratorTypes/ct4l" + + * `in_use_resources`: [Output only] List of resources currently in use. + + * `accelerator`: + + * `accelerator_count`: Number of accelerators of specified type. + + * `accelerator_type`: Full or partial URL to accelerator type. e.g. "projects/{PROJECT}/zones/{ZONE}/acceleratorTypes/ct4l" + + * `workload_type`: The workload type of the instances that will target this reservation. + Possible values: + * BATCH + * SERVING + * UNSPECIFIED + + * `commitment`: [Output Only] Full or partial URL to a parent commitment. This field displays for reservations that are tied to a commitment. + + * `specific_reservation_required`: Indicates whether the reservation can be consumed by VMs with affinity for "any" reservation. If the field is set, then only VMs that target the reservation by name can consume from this reservation. + + * `status`: [Output Only] The status of the reservation. + Possible values: + * CREATING + * DELETING + * INVALID + * READY + * UPDATING + + * `share_settings`: The share setting for reservations and sole tenancy node groups. + + * `share_type`: Type of sharing for this shared-reservation + Possible values: + * DIRECT_PROJECTS_UNDER_SPECIFIC_FOLDERS + * LOCAL + * ORGANIZATION + * SHARE_TYPE_UNSPECIFIED + * SPECIFIC_PROJECTS + + * `projects`: A List of Project names to specify consumer projects for this shared-reservation. This is only valid when share_type's value is SPECIFIC_PROJECTS. + + * `project_map`: A map of project id and project config. This is only valid when share_type's value is SPECIFIC_PROJECTS. + + * `additional_properties`: Config for each project in the share settings. + + * `folder_map`: A map of folder id and folder config to specify consumer projects for this shared-reservation. This is only valid when share_type's value is DIRECT_PROJECTS_UNDER_SPECIFIC_FOLDERS. Folder id should be a string of number, and without "folders/" prefix. + + * `additional_properties`: Config for each folder in the share settings. + + * `satisfies_pzs`: [Output Only] Reserved for future use. + + * `resource_policies`: Resource policies to be added to this reservation. The key is defined by user, and the value is resource policy url. This is to define placement policy with reservation. + + * `additional_properties`: + + * `resource_status`: [Output Only] Contains output only fields. + + * `specific_sku_allocation`: Contains Properties set for the reservation. + + * `source_instance_template_id`: ID of the instance template used to populate reservation properties. + + * `delete_at_time`: Absolute time in future when the reservation will be auto-deleted by Compute Engine. Timestamp is represented in RFC3339 text format. + + * `delete_after_duration`: A Duration represents a fixed-length span of time represented as a count of seconds and fractions of seconds at nanosecond resolution. It is independent of any calendar and concepts like "day" or "month". Range is approximately 10,000 years. + + * `seconds`: Span of time at a resolution of a second. Must be from 0 to 315,576,000,000 inclusive. Note: these bounds are computed from: 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years + + * `nanos`: Span of time that's a fraction of a second at nanosecond resolution. Durations less than one second are represented with a 0 `seconds` field and a positive `nanos` field. Must be from 0 to 999,999,999 inclusive. + + +## 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_reservations.md b/docs/resources/google_compute_reservations.md new file mode 100644 index 000000000..e910c97d4 --- /dev/null +++ b/docs/resources/google_compute_reservations.md @@ -0,0 +1,46 @@ +--- +title: About the google_compute_reservations resource +platform: gcp +--- + +## Syntax +A `google_compute_reservations` is used to test a Google Reservation resource + +## Examples +``` + describe google_compute_reservations(project: 'chef-gcp-inspec', zone: ' value_zone') do + it { should exist } + end +``` + +## Properties +Properties that can be accessed from the `google_compute_reservations` resource: + +See [google_compute_reservation.md](google_compute_reservation.md) for more detailed information + * `kinds`: an array of `google_compute_reservation` kind + * `ids`: an array of `google_compute_reservation` id + * `creation_timestamps`: an array of `google_compute_reservation` creation_timestamp + * `self_links`: an array of `google_compute_reservation` self_link + * `self_link_with_ids`: an array of `google_compute_reservation` self_link_with_id + * `zones`: an array of `google_compute_reservation` zone + * `descriptions`: an array of `google_compute_reservation` description + * `names`: an array of `google_compute_reservation` name + * `specific_reservations`: an array of `google_compute_reservation` specific_reservation + * `aggregate_reservations`: an array of `google_compute_reservation` aggregate_reservation + * `commitments`: an array of `google_compute_reservation` commitment + * `specific_reservation_requireds`: an array of `google_compute_reservation` specific_reservation_required + * `statuses`: an array of `google_compute_reservation` status + * `share_settings`: an array of `google_compute_reservation` share_settings + * `satisfies_pzs`: an array of `google_compute_reservation` satisfies_pzs + * `resource_policies`: an array of `google_compute_reservation` resource_policies + * `resource_statuses`: an array of `google_compute_reservation` resource_status + * `delete_at_times`: an array of `google_compute_reservation` delete_at_time + * `delete_after_durations`: an array of `google_compute_reservation` delete_after_duration + +## 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/reservation_aggregate_reservation.rb b/libraries/google/compute/property/reservation_aggregate_reservation.rb new file mode 100644 index 000000000..c030aa876 --- /dev/null +++ b/libraries/google/compute/property/reservation_aggregate_reservation.rb @@ -0,0 +1,45 @@ +# 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 'google/compute/property/reservation_aggregate_reservation_in_use_resources' +require 'google/compute/property/reservation_aggregate_reservation_reserved_resources' +module GoogleInSpec + module Compute + module Property + class ReservationAggregateReservation + attr_reader :vm_family + + attr_reader :reserved_resources + + attr_reader :in_use_resources + + attr_reader :workload_type + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @vm_family = args['vmFamily'] + @reserved_resources = GoogleInSpec::Compute::Property::ReservationAggregateReservationReservedResourcesArray.parse(args['reservedResources'], to_s) + @in_use_resources = GoogleInSpec::Compute::Property::ReservationAggregateReservationInUseResourcesArray.parse(args['inUseResources'], to_s) + @workload_type = args['workloadType'] + end + + def to_s + "#{@parent_identifier} ReservationAggregateReservation" + end + end + end + end +end diff --git a/libraries/google/compute/property/reservation_aggregate_reservation_in_use_resources.rb b/libraries/google/compute/property/reservation_aggregate_reservation_in_use_resources.rb new file mode 100644 index 000000000..fd40d2f8b --- /dev/null +++ b/libraries/google/compute/property/reservation_aggregate_reservation_in_use_resources.rb @@ -0,0 +1,43 @@ +# 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 'google/compute/property/reservation_aggregate_reservation_in_use_resources_accelerator' +module GoogleInSpec + module Compute + module Property + class ReservationAggregateReservationInUseResources + attr_reader :accelerator + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @accelerator = GoogleInSpec::Compute::Property::ReservationAggregateReservationInUseResourcesAccelerator.new(args['accelerator'], to_s) + end + + def to_s + "#{@parent_identifier} ReservationAggregateReservationInUseResources" + end + end + + class ReservationAggregateReservationInUseResourcesArray + def self.parse(value, parent_identifier) + return if value.nil? + return ReservationAggregateReservationInUseResources.new(value, parent_identifier) unless value.is_a?(::Array) + value.map { |v| ReservationAggregateReservationInUseResources.new(v, parent_identifier) } + end + end + end + end +end diff --git a/libraries/google/compute/property/reservation_aggregate_reservation_in_use_resources_accelerator.rb b/libraries/google/compute/property/reservation_aggregate_reservation_in_use_resources_accelerator.rb new file mode 100644 index 000000000..16f394ff8 --- /dev/null +++ b/libraries/google/compute/property/reservation_aggregate_reservation_in_use_resources_accelerator.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 ReservationAggregateReservationInUseResourcesAccelerator + attr_reader :accelerator_count + + attr_reader :accelerator_type + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @accelerator_count = args['acceleratorCount'] + @accelerator_type = args['acceleratorType'] + end + + def to_s + "#{@parent_identifier} ReservationAggregateReservationInUseResourcesAccelerator" + end + end + end + end +end diff --git a/libraries/google/compute/property/reservation_aggregate_reservation_reserved_resources.rb b/libraries/google/compute/property/reservation_aggregate_reservation_reserved_resources.rb new file mode 100644 index 000000000..c7352e21a --- /dev/null +++ b/libraries/google/compute/property/reservation_aggregate_reservation_reserved_resources.rb @@ -0,0 +1,43 @@ +# 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 'google/compute/property/reservation_aggregate_reservation_reserved_resources_accelerator' +module GoogleInSpec + module Compute + module Property + class ReservationAggregateReservationReservedResources + attr_reader :accelerator + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @accelerator = GoogleInSpec::Compute::Property::ReservationAggregateReservationReservedResourcesAccelerator.new(args['accelerator'], to_s) + end + + def to_s + "#{@parent_identifier} ReservationAggregateReservationReservedResources" + end + end + + class ReservationAggregateReservationReservedResourcesArray + def self.parse(value, parent_identifier) + return if value.nil? + return ReservationAggregateReservationReservedResources.new(value, parent_identifier) unless value.is_a?(::Array) + value.map { |v| ReservationAggregateReservationReservedResources.new(v, parent_identifier) } + end + end + end + end +end diff --git a/libraries/google/compute/property/reservation_aggregate_reservation_reserved_resources_accelerator.rb b/libraries/google/compute/property/reservation_aggregate_reservation_reserved_resources_accelerator.rb new file mode 100644 index 000000000..7f4b3b941 --- /dev/null +++ b/libraries/google/compute/property/reservation_aggregate_reservation_reserved_resources_accelerator.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 ReservationAggregateReservationReservedResourcesAccelerator + attr_reader :accelerator_count + + attr_reader :accelerator_type + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @accelerator_count = args['acceleratorCount'] + @accelerator_type = args['acceleratorType'] + end + + def to_s + "#{@parent_identifier} ReservationAggregateReservationReservedResourcesAccelerator" + end + end + end + end +end diff --git a/libraries/google/compute/property/reservation_delete_after_duration.rb b/libraries/google/compute/property/reservation_delete_after_duration.rb new file mode 100644 index 000000000..cb2891488 --- /dev/null +++ b/libraries/google/compute/property/reservation_delete_after_duration.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 ReservationDeleteAfterDuration + attr_reader :seconds + + attr_reader :nanos + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @seconds = args['seconds'] + @nanos = args['nanos'] + end + + def to_s + "#{@parent_identifier} ReservationDeleteAfterDuration" + end + end + end + end +end diff --git a/libraries/google/compute/property/reservation_resource_policies.rb b/libraries/google/compute/property/reservation_resource_policies.rb new file mode 100644 index 000000000..038991030 --- /dev/null +++ b/libraries/google/compute/property/reservation_resource_policies.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 ReservationResourcePolicies + 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} ReservationResourcePolicies" + end + end + end + end +end diff --git a/libraries/google/compute/property/reservation_resource_status.rb b/libraries/google/compute/property/reservation_resource_status.rb new file mode 100644 index 000000000..c512f7f32 --- /dev/null +++ b/libraries/google/compute/property/reservation_resource_status.rb @@ -0,0 +1,35 @@ +# 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 'google/compute/property/reservation_resource_status_specific_sku_allocation' +module GoogleInSpec + module Compute + module Property + class ReservationResourceStatus + attr_reader :specific_sku_allocation + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @specific_sku_allocation = GoogleInSpec::Compute::Property::ReservationResourceStatusSpecificSkuAllocation.new(args['specificSkuAllocation'], to_s) + end + + def to_s + "#{@parent_identifier} ReservationResourceStatus" + end + end + end + end +end diff --git a/libraries/google/compute/property/reservation_resource_status_specific_sku_allocation.rb b/libraries/google/compute/property/reservation_resource_status_specific_sku_allocation.rb new file mode 100644 index 000000000..b85dd383b --- /dev/null +++ b/libraries/google/compute/property/reservation_resource_status_specific_sku_allocation.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 ReservationResourceStatusSpecificSkuAllocation + attr_reader :source_instance_template_id + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @source_instance_template_id = args['sourceInstanceTemplateId'] + end + + def to_s + "#{@parent_identifier} ReservationResourceStatusSpecificSkuAllocation" + end + end + end + end +end diff --git a/libraries/google/compute/property/reservation_share_settings.rb b/libraries/google/compute/property/reservation_share_settings.rb new file mode 100644 index 000000000..140fdced8 --- /dev/null +++ b/libraries/google/compute/property/reservation_share_settings.rb @@ -0,0 +1,45 @@ +# 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 'google/compute/property/reservation_share_settings_folder_map' +require 'google/compute/property/reservation_share_settings_project_map' +module GoogleInSpec + module Compute + module Property + class ReservationShareSettings + attr_reader :share_type + + attr_reader :projects + + attr_reader :project_map + + attr_reader :folder_map + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @share_type = args['shareType'] + @projects = args['projects'] + @project_map = GoogleInSpec::Compute::Property::ReservationShareSettingsProjectMap.new(args['projectMap'], to_s) + @folder_map = GoogleInSpec::Compute::Property::ReservationShareSettingsFolderMap.new(args['folderMap'], to_s) + end + + def to_s + "#{@parent_identifier} ReservationShareSettings" + end + end + end + end +end diff --git a/libraries/google/compute/property/reservation_share_settings_folder_map.rb b/libraries/google/compute/property/reservation_share_settings_folder_map.rb new file mode 100644 index 000000000..422c867ca --- /dev/null +++ b/libraries/google/compute/property/reservation_share_settings_folder_map.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 ReservationShareSettingsFolderMap + 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} ReservationShareSettingsFolderMap" + end + end + end + end +end diff --git a/libraries/google/compute/property/reservation_share_settings_project_map.rb b/libraries/google/compute/property/reservation_share_settings_project_map.rb new file mode 100644 index 000000000..f1d67f3d5 --- /dev/null +++ b/libraries/google/compute/property/reservation_share_settings_project_map.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 ReservationShareSettingsProjectMap + 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} ReservationShareSettingsProjectMap" + end + end + end + end +end diff --git a/libraries/google/compute/property/reservation_specific_reservation.rb b/libraries/google/compute/property/reservation_specific_reservation.rb new file mode 100644 index 000000000..8abc60e18 --- /dev/null +++ b/libraries/google/compute/property/reservation_specific_reservation.rb @@ -0,0 +1,49 @@ +# 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 'google/compute/property/reservation_specific_reservation_instance_properties' +require 'google/compute/property/reservation_specific_reservation_instance_properties_guest_accelerators' +require 'google/compute/property/reservation_specific_reservation_instance_properties_local_ssds' +module GoogleInSpec + module Compute + module Property + class ReservationSpecificReservation + attr_reader :instance_properties + + attr_reader :count + + attr_reader :in_use_count + + attr_reader :assured_count + + attr_reader :source_instance_template + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @instance_properties = GoogleInSpec::Compute::Property::ReservationSpecificReservationInstanceProperties.new(args['instanceProperties'], to_s) + @count = args['count'] + @in_use_count = args['inUseCount'] + @assured_count = args['assuredCount'] + @source_instance_template = args['sourceInstanceTemplate'] + end + + def to_s + "#{@parent_identifier} ReservationSpecificReservation" + end + end + end + end +end diff --git a/libraries/google/compute/property/reservation_specific_reservation_instance_properties.rb b/libraries/google/compute/property/reservation_specific_reservation_instance_properties.rb new file mode 100644 index 000000000..d32e7a0f0 --- /dev/null +++ b/libraries/google/compute/property/reservation_specific_reservation_instance_properties.rb @@ -0,0 +1,54 @@ +# 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 'google/compute/property/reservation_specific_reservation_instance_properties_guest_accelerators' +require 'google/compute/property/reservation_specific_reservation_instance_properties_local_ssds' +module GoogleInSpec + module Compute + module Property + class ReservationSpecificReservationInstanceProperties + attr_reader :machine_type + + attr_reader :guest_accelerators + + attr_reader :min_cpu_platform + + attr_reader :local_ssds + + attr_reader :maintenance_freeze_duration_hours + + attr_reader :location_hint + + attr_reader :maintenance_interval + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @machine_type = args['machineType'] + @guest_accelerators = GoogleInSpec::Compute::Property::ReservationSpecificReservationInstancePropertiesGuestAcceleratorsArray.parse(args['guestAccelerators'], to_s) + @min_cpu_platform = args['minCpuPlatform'] + @local_ssds = GoogleInSpec::Compute::Property::ReservationSpecificReservationInstancePropertiesLocalSsdsArray.parse(args['localSsds'], to_s) + @maintenance_freeze_duration_hours = args['maintenanceFreezeDurationHours'] + @location_hint = args['locationHint'] + @maintenance_interval = args['maintenanceInterval'] + end + + def to_s + "#{@parent_identifier} ReservationSpecificReservationInstanceProperties" + end + end + end + end +end diff --git a/libraries/google/compute/property/reservation_specific_reservation_instance_properties_guest_accelerators.rb b/libraries/google/compute/property/reservation_specific_reservation_instance_properties_guest_accelerators.rb new file mode 100644 index 000000000..61d1c054c --- /dev/null +++ b/libraries/google/compute/property/reservation_specific_reservation_instance_properties_guest_accelerators.rb @@ -0,0 +1,45 @@ +# 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 ReservationSpecificReservationInstancePropertiesGuestAccelerators + attr_reader :accelerator_type + + attr_reader :accelerator_count + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @accelerator_type = args['acceleratorType'] + @accelerator_count = args['acceleratorCount'] + end + + def to_s + "#{@parent_identifier} ReservationSpecificReservationInstancePropertiesGuestAccelerators" + end + end + + class ReservationSpecificReservationInstancePropertiesGuestAcceleratorsArray + def self.parse(value, parent_identifier) + return if value.nil? + return ReservationSpecificReservationInstancePropertiesGuestAccelerators.new(value, parent_identifier) unless value.is_a?(::Array) + value.map { |v| ReservationSpecificReservationInstancePropertiesGuestAccelerators.new(v, parent_identifier) } + end + end + end + end +end diff --git a/libraries/google/compute/property/reservation_specific_reservation_instance_properties_local_ssds.rb b/libraries/google/compute/property/reservation_specific_reservation_instance_properties_local_ssds.rb new file mode 100644 index 000000000..e3a11769c --- /dev/null +++ b/libraries/google/compute/property/reservation_specific_reservation_instance_properties_local_ssds.rb @@ -0,0 +1,45 @@ +# 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 ReservationSpecificReservationInstancePropertiesLocalSsds + attr_reader :disk_size_gb + + attr_reader :interface + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @disk_size_gb = args['diskSizeGb'] + @interface = args['interface'] + end + + def to_s + "#{@parent_identifier} ReservationSpecificReservationInstancePropertiesLocalSsds" + end + end + + class ReservationSpecificReservationInstancePropertiesLocalSsdsArray + def self.parse(value, parent_identifier) + return if value.nil? + return ReservationSpecificReservationInstancePropertiesLocalSsds.new(value, parent_identifier) unless value.is_a?(::Array) + value.map { |v| ReservationSpecificReservationInstancePropertiesLocalSsds.new(v, parent_identifier) } + end + end + end + end +end diff --git a/libraries/google_compute_reservation.rb b/libraries/google_compute_reservation.rb new file mode 100644 index 000000000..c1da5b05c --- /dev/null +++ b/libraries/google_compute_reservation.rb @@ -0,0 +1,105 @@ +# 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/reservation_aggregate_reservation' +require 'google/compute/property/reservation_aggregate_reservation_in_use_resources' +require 'google/compute/property/reservation_aggregate_reservation_reserved_resources' +require 'google/compute/property/reservation_delete_after_duration' +require 'google/compute/property/reservation_resource_policies' +require 'google/compute/property/reservation_resource_status' +require 'google/compute/property/reservation_resource_status_specific_sku_allocation' +require 'google/compute/property/reservation_share_settings' +require 'google/compute/property/reservation_share_settings_folder_map' +require 'google/compute/property/reservation_share_settings_project_map' +require 'google/compute/property/reservation_specific_reservation' +require 'google/compute/property/reservation_specific_reservation_instance_properties' +require 'google/compute/property/reservation_specific_reservation_instance_properties_guest_accelerators' +require 'google/compute/property/reservation_specific_reservation_instance_properties_local_ssds' + +# A provider to manage Compute Engine resources. +class ComputeReservation < GcpResourceBase + name 'google_compute_reservation' + desc 'Reservation' + supports platform: 'gcp' + + attr_reader :params + attr_reader :kind + attr_reader :id + attr_reader :creation_timestamp + attr_reader :self_link + attr_reader :self_link_with_id + attr_reader :zone + attr_reader :description + attr_reader :name + attr_reader :specific_reservation + attr_reader :aggregate_reservation + attr_reader :commitment + attr_reader :specific_reservation_required + attr_reader :status + attr_reader :share_settings + attr_reader :satisfies_pzs + attr_reader :resource_policies + attr_reader :resource_status + attr_reader :delete_at_time + attr_reader :delete_after_duration + + 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'] + @self_link_with_id = @fetched['selfLinkWithId'] + @zone = @fetched['zone'] + @description = @fetched['description'] + @name = @fetched['name'] + @specific_reservation = GoogleInSpec::Compute::Property::ReservationSpecificReservation.new(@fetched['specificReservation'], to_s) + @aggregate_reservation = GoogleInSpec::Compute::Property::ReservationAggregateReservation.new(@fetched['aggregateReservation'], to_s) + @commitment = @fetched['commitment'] + @specific_reservation_required = @fetched['specificReservationRequired'] + @status = @fetched['status'] + @share_settings = GoogleInSpec::Compute::Property::ReservationShareSettings.new(@fetched['shareSettings'], to_s) + @satisfies_pzs = @fetched['satisfiesPzs'] + @resource_policies = GoogleInSpec::Compute::Property::ReservationResourcePolicies.new(@fetched['resourcePolicies'], to_s) + @resource_status = GoogleInSpec::Compute::Property::ReservationResourceStatus.new(@fetched['resourceStatus'], to_s) + @delete_at_time = @fetched['deleteAtTime'] + @delete_after_duration = GoogleInSpec::Compute::Property::ReservationDeleteAfterDuration.new(@fetched['deleteAfterDuration'], to_s) + end + + def exists? + !@fetched.nil? + end + + def to_s + "Reservation #{@params[:reservation]}" + end + + private + + def product_url(_ = nil) + 'https://compute.googleapis.com/compute/v1/' + end + + def resource_base_url + 'projects/{{project}}/zones/{{zone}}/reservations/{{reservation}}' + end +end diff --git a/libraries/google_compute_reservations.rb b/libraries/google_compute_reservations.rb new file mode 100644 index 000000000..b88bab287 --- /dev/null +++ b/libraries/google_compute_reservations.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 ComputeReservations < GcpResourceBase + name 'google_compute_reservations' + desc 'Reservation 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(:self_link_with_ids, field: :self_link_with_id) + filter_table_config.add(:zones, field: :zone) + filter_table_config.add(:descriptions, field: :description) + filter_table_config.add(:names, field: :name) + filter_table_config.add(:specific_reservations, field: :specific_reservation) + filter_table_config.add(:aggregate_reservations, field: :aggregate_reservation) + filter_table_config.add(:commitments, field: :commitment) + filter_table_config.add(:specific_reservation_requireds, field: :specific_reservation_required) + filter_table_config.add(:statuses, field: :status) + filter_table_config.add(:share_settings, field: :share_settings) + filter_table_config.add(:satisfies_pzs, field: :satisfies_pzs) + filter_table_config.add(:resource_policies, field: :resource_policies) + filter_table_config.add(:resource_statuses, field: :resource_status) + filter_table_config.add(:delete_at_times, field: :delete_at_time) + filter_table_config.add(:delete_after_durations, field: :delete_after_duration) + + filter_table_config.connect(self, :table) + + def initialize(params = {}) + super(params.merge({ use_http_transport: true })) + @params = params + @table = fetch_wrapped_resource('reservations') + 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) { [:kind, obj['kind']] }, + 'id' => ->(obj) { [:id, obj['id']] }, + 'creationTimestamp' => ->(obj) { [:creation_timestamp, obj['creationTimestamp']] }, + 'selfLink' => ->(obj) { [:self_link, obj['selfLink']] }, + 'selfLinkWithId' => ->(obj) { [:self_link_with_id, obj['selfLinkWithId']] }, + 'zone' => ->(obj) { [:zone, obj['zone']] }, + 'description' => ->(obj) { [:description, obj['description']] }, + 'name' => ->(obj) { [:name, obj['name']] }, + 'specificReservation' => ->(obj) { [:specific_reservation, GoogleInSpec::Compute::Property::ReservationSpecificReservation.new(obj['specificReservation'], to_s)] }, + 'aggregateReservation' => ->(obj) { [:aggregate_reservation, GoogleInSpec::Compute::Property::ReservationAggregateReservation.new(obj['aggregateReservation'], to_s)] }, + 'commitment' => ->(obj) { [:commitment, obj['commitment']] }, + 'specificReservationRequired' => ->(obj) { [:specific_reservation_required, obj['specificReservationRequired']] }, + 'status' => ->(obj) { [:status, obj['status']] }, + 'shareSettings' => ->(obj) { [:share_settings, GoogleInSpec::Compute::Property::ReservationShareSettings.new(obj['shareSettings'], to_s)] }, + 'satisfiesPzs' => ->(obj) { [:satisfies_pzs, obj['satisfiesPzs']] }, + 'resourcePolicies' => ->(obj) { [:resource_policies, GoogleInSpec::Compute::Property::ReservationResourcePolicies.new(obj['resourcePolicies'], to_s)] }, + 'resourceStatus' => ->(obj) { [:resource_status, GoogleInSpec::Compute::Property::ReservationResourceStatus.new(obj['resourceStatus'], to_s)] }, + 'deleteAtTime' => ->(obj) { [:delete_at_time, obj['deleteAtTime']] }, + 'deleteAfterDuration' => ->(obj) { [:delete_after_duration, GoogleInSpec::Compute::Property::ReservationDeleteAfterDuration.new(obj['deleteAfterDuration'], to_s)] }, + } + end + + private + + def product_url(_ = nil) + 'https://compute.googleapis.com/compute/v1/' + end + + def resource_base_url + 'projects/{{project}}/zones/{{zone}}/reservations' + end +end diff --git a/test/integration/verify/controls/google_compute_reservation.rb b/test/integration/verify/controls/google_compute_reservation.rb new file mode 100644 index 000000000..ced7b31e4 --- /dev/null +++ b/test/integration/verify/controls/google_compute_reservation.rb @@ -0,0 +1,57 @@ +# ---------------------------------------------------------------------------- +# +# *** 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_reservation resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + reservation = input('reservation', value: { + "project": "value_project", + "reservation": "value_reservation", + "zone": "value_zone", + "kind": "value_kind", + "id": "value_id", + "creation_timestamp": "value_creationtimestamp", + "self_link": "value_selflink", + "self_link_with_id": "value_selflinkwithid", + "description": "value_description", + "name": "value_name", + "commitment": "value_commitment", + "status": "value_status", + "delete_at_time": "value_deleteattime" +}, description: 'reservation description') +control 'google_compute_reservation-1.0' do + impact 1.0 + title 'google_compute_reservation resource test' + + describe google_compute_reservation(project: gcp_project_id, name: reservation['name'], zone: reservation['zone']) do + it { should exist } + its('kind') { should cmp reservation['kind'] } + its('id') { should cmp reservation['id'] } + its('creation_timestamp') { should cmp reservation['creation_timestamp'] } + its('self_link') { should cmp reservation['self_link'] } + its('self_link_with_id') { should cmp reservation['self_link_with_id'] } + its('zone') { should cmp reservation['zone'] } + its('description') { should cmp reservation['description'] } + its('name') { should cmp reservation['name'] } + its('commitment') { should cmp reservation['commitment'] } + its('status') { should cmp reservation['status'] } + its('delete_at_time') { should cmp reservation['delete_at_time'] } + + end + + describe google_compute_reservation(project: gcp_project_id, name: "does_not_exit", zone: reservation['zone']) do + it { should_not exist } + end +end diff --git a/test/integration/verify/controls/google_compute_reservations.rb b/test/integration/verify/controls/google_compute_reservations.rb new file mode 100644 index 000000000..1bb02bd2c --- /dev/null +++ b/test/integration/verify/controls/google_compute_reservations.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_compute_reservations resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + reservation = input('reservation', value: { + "project": "value_project", + "reservation": "value_reservation", + "zone": "value_zone", + "kind": "value_kind", + "id": "value_id", + "creation_timestamp": "value_creationtimestamp", + "self_link": "value_selflink", + "self_link_with_id": "value_selflinkwithid", + "description": "value_description", + "name": "value_name", + "commitment": "value_commitment", + "status": "value_status", + "delete_at_time": "value_deleteattime" +}, description: 'reservation description') +control 'google_compute_reservations-1.0' do + impact 1.0 + title 'google_compute_reservations resource test' + + describe google_compute_reservations(project: gcp_project_id, zone: reservation['zone']) do + it { should exist } + end +end From dd7128e22773b66a799c3c55ec8da5b57ab46b31 Mon Sep 17 00:00:00 2001 From: Samir <85890442+sa-progress@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:15:49 +0530 Subject: [PATCH 2/4] Plural updated Signed-off-by: Samir <85890442+sa-progress@users.noreply.github.com> --- libraries/google_compute_reservations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/google_compute_reservations.rb b/libraries/google_compute_reservations.rb index b88bab287..aa71444df 100644 --- a/libraries/google_compute_reservations.rb +++ b/libraries/google_compute_reservations.rb @@ -48,7 +48,7 @@ class ComputeReservations < GcpResourceBase def initialize(params = {}) super(params.merge({ use_http_transport: true })) @params = params - @table = fetch_wrapped_resource('reservations') + @table = fetch_wrapped_resource('items') end def fetch_wrapped_resource(wrap_path) From 4c9618f855053ec0a2fd4824803a712a76859b8f Mon Sep 17 00:00:00 2001 From: Samir <85890442+sa-progress@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:25:43 +0530 Subject: [PATCH 3/4] Read me updated: Reservation entry Signed-off-by: Samir <85890442+sa-progress@users.noreply.github.com> --- README.md | 1 + libraries/google_compute_reservation.rb | 2 +- test/integration/build/.terraform.lock.hcl | 40 ---------------------- test/integration/build/gcp-mm.tf | 5 +++ test/mock/mock-gcp.rb | 28 +++++++++++++++ 5 files changed, 35 insertions(+), 41 deletions(-) delete mode 100644 test/integration/build/.terraform.lock.hcl create mode 100644 test/mock/mock-gcp.rb diff --git a/README.md b/README.md index 1aabe26c9..8ca9fa92f 100644 --- a/README.md +++ b/README.md @@ -259,6 +259,7 @@ The following resources are available in the InSpec GCP Profile | [google_compute_region_operation](docs/resources/google_compute_region_operation.md) | [google_compute_region_operations](docs/resources/google_compute_region_operations.md) | | [google_compute_region_operation](docs/resources/google_compute_region_url_map.md) | [google_compute_region_operations](docs/resources/google_compute_region_url_maps.md) | | [google_compute_regional_disk](docs/resources/google_compute_regional_disk.md) | [google_compute_regional_disks](docs/resources/google_compute_regional_disks.md) | +| [google_compute_reservation](docs/resources/google_compute_reservation.md) | [google_compute_reservations](docs/resources/google_compute_reservations.md) | | [google_compute_resource_policy](docs/resources/google_compute_resource_policy.md) | [google_compute_resource_policies](docs/resources/google_compute_resource_policies.md) | | [google_compute_route](docs/resources/google_compute_route.md) | [google_compute_routes](docs/resources/google_compute_routes.md) | | [google_compute_router](docs/resources/google_compute_router.md) | [google_compute_routers](docs/resources/google_compute_routers.md) | diff --git a/libraries/google_compute_reservation.rb b/libraries/google_compute_reservation.rb index c1da5b05c..1ed9eb9ac 100644 --- a/libraries/google_compute_reservation.rb +++ b/libraries/google_compute_reservation.rb @@ -100,6 +100,6 @@ def product_url(_ = nil) end def resource_base_url - 'projects/{{project}}/zones/{{zone}}/reservations/{{reservation}}' + 'projects/{{project}}/zones/{{zone}}/reservations/{{name}}' end end diff --git a/test/integration/build/.terraform.lock.hcl b/test/integration/build/.terraform.lock.hcl deleted file mode 100644 index 7b7fbc813..000000000 --- a/test/integration/build/.terraform.lock.hcl +++ /dev/null @@ -1,40 +0,0 @@ -# This file is maintained automatically by "terraform init". -# Manual edits may be lost in future updates. - -provider "registry.terraform.io/hashicorp/google" { - version = "3.90.1" - constraints = "~> 3.90.0" - hashes = [ - "h1:9TYwyR4R4dIop7wV2lvvYZHw9RUVd/YRWR+9jjXpyfw=", - "zh:07aabc8e46a5a2b29932e10677b23d4ce9d9a25f22ab61d3307a6b0e7998c84e", - "zh:0b63cd9534a98ed0fee794da495833046ad5319bd2da3102e21a941b7e2b857e", - "zh:17f815d57e1426edf8818323ab8e1022c8ec60dce0ced89a3b8e5dde5a95b3cc", - "zh:37855eae3542f2ebc6416984b124533d00299e0e01dcd7d2bc2205469cb9eceb", - "zh:579aa32a8e3fa317ddbd28c99a6449ae8864a5b7d10247bca6496f399cb36701", - "zh:703f71e0231cfe7a025c61db361d928189adba1d4fad2fe77f783dc73c8afe30", - "zh:afcd80c31cb1ed75ce6813269618e01ab29af68dae7aae1c51521c13acdaa678", - "zh:b21302f65a0d37045216912695d1ef718a1fe1732c30dc5654891fe2519b8e4e", - "zh:b69d0c8a74c2cd6233681db37e01aaaf1a6fb6bb24c83f7715bd2b456083e29d", - "zh:d4fb305816b143cb26c1827c79e56651347fd41809a57184e4807fb3f804f510", - "zh:fa24173ef9524bdfa1c5cada5188489554b08374f9519fe545f3fc1d3a9d9d4f", - ] -} - -provider "registry.terraform.io/hashicorp/google-beta" { - version = "3.90.1" - constraints = "~> 3.90.0" - hashes = [ - "h1:GYvCJnoIaT9clM2aAbfe0qsnRy4OdRfJ0NwO0dWnCJI=", - "zh:2d647e42313f4e3f36480d2508a5056373099843a16558c21d5c798899a1e2d7", - "zh:51a637b35d8c923cb02eb9a13c72526a72364f0a99100470cb253c5116446475", - "zh:52940431348d23998fdd9216b7fa666e3bcfd6c3ad9751f8f076fbd5529006de", - "zh:53d36e0ada5a5b95d0b66a8cdfa65adf25d5a49a826f7f4a6f891955c0d19600", - "zh:6564b0c6692c8ef571254e3279b5803893b50825abb4e4b175b8eff19af4e447", - "zh:747757f0582561e18d930295ea14dfde4ca485be87b2bb7097e410f40076707b", - "zh:a828fb94d2a2d99c435215a780ce1fcd2cbf8bd2dfce86d9989a9a978c100eec", - "zh:b81949694ec1bf59cd0a838149b33792e3ceed35b18333dbfbcd28052bc94f23", - "zh:db255de73e0c5c030c6d54fc9217b20169e2c19fd7dde8e0415c495dd48907f0", - "zh:e5966c5ac5887b02cef0b3aa703c986d5a74e95279be4ec1db93843e9c92e64a", - "zh:eb172abc91f80b9f13c942cf6b1081095b6d9796f024a301f218eaf7f5241121", - ] -} diff --git a/test/integration/build/gcp-mm.tf b/test/integration/build/gcp-mm.tf index 2c5bac15e..c2fec3fee 100644 --- a/test/integration/build/gcp-mm.tf +++ b/test/integration/build/gcp-mm.tf @@ -2136,3 +2136,8 @@ resource "google_compute_health_check" "default" { port = "443" } } + +data "google_compute_reservation" "reservation" { + name = "gce-reservation" + zone = "us-central1-a" +} \ No newline at end of file diff --git a/test/mock/mock-gcp.rb b/test/mock/mock-gcp.rb new file mode 100644 index 000000000..ae5ba9963 --- /dev/null +++ b/test/mock/mock-gcp.rb @@ -0,0 +1,28 @@ +# libraries/mock_gcp.rb + +require 'gcp_backend' + +module GcpBackend + class MockGcp < GcpBackend::Google + def initialize + @compute = Google::Apis::ComputeV1::ComputeService.new + end + + def get_region_notification_endpoints(_project, _region) + region_notification_endpoint = Google::Apis::ComputeV1::NotificationEndpoint.new( + id: '1234567890', + name: 'test-notification-endpoint', + description: 'A test notification endpoint', + creation_timestamp: '2021-01-01T00:00:00.000-00:00', + self_link: 'https://www.googleapis.com/compute/v1/projects/my-project/regions/us-central1/notificationEndpoints/test-notification-endpoint' + ) + + region_notification_endpoints = Google::Apis::ComputeV1::NotificationEndpointList.new( + items: [region_notification_endpoint] + ) + + region_notification_endpoints + end + end +end + From 8db78c2511c156f7f4dba5d6c1359ea91abb4cab Mon Sep 17 00:00:00 2001 From: Samir <85890442+sa-progress@users.noreply.github.com> Date: Mon, 17 Jun 2024 12:31:15 +0530 Subject: [PATCH 4/4] Terraform updated: Reservation entry Signed-off-by: Samir <85890442+sa-progress@users.noreply.github.com> --- test/integration/build/gcp-mm.tf | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/integration/build/gcp-mm.tf b/test/integration/build/gcp-mm.tf index c2fec3fee..94af21027 100644 --- a/test/integration/build/gcp-mm.tf +++ b/test/integration/build/gcp-mm.tf @@ -2137,7 +2137,15 @@ resource "google_compute_health_check" "default" { } } -data "google_compute_reservation" "reservation" { +resource "google_compute_reservation" "gce_reservation" { name = "gce-reservation" zone = "us-central1-a" + + specific_reservation { + count = 1 + instance_properties { + min_cpu_platform = "Intel Cascade Lake" + machine_type = "n2-standard-2" + } + } } \ No newline at end of file