From a8e8c192e2972a28363145b894da707107187700 Mon Sep 17 00:00:00 2001 From: Samir <85890442+sa-progress@users.noreply.github.com> Date: Tue, 2 Apr 2024 17:16:23 +0530 Subject: [PATCH 1/2] Automatically generated by magic modules for service: compute_v1 and resource: RegionAutoscaler. This commit includes the following changes: - Singular Resource - Plural Resource - Documentation updates - Terraform configuration - Integration tests Signed-off-by: Samir <85890442+sa-progress@users.noreply.github.com> --- .../google_compute_region_autoscaler.md | 173 ++++++++++++++++++ .../google_compute_region_autoscalers.md | 42 +++++ .../regionautoscaler_autoscaling_policy.rb | 69 +++++++ ...aler_autoscaling_policy_cpu_utilization.rb | 37 ++++ ...aling_policy_custom_metric_utilizations.rb | 54 ++++++ ...aling_policy_load_balancing_utilization.rb | 34 ++++ ...r_autoscaling_policy_scale_down_control.rb | 38 ++++ ...e_down_control_max_scaled_down_replicas.rb | 40 ++++ ...ler_autoscaling_policy_scale_in_control.rb | 38 ++++ ...scale_in_control_max_scaled_in_replicas.rb | 40 ++++ ...er_autoscaling_policy_scaling_schedules.rb | 34 ++++ ...egionautoscaler_scaling_schedule_status.rb | 34 ++++ .../regionautoscaler_status_details.rb | 45 +++++ libraries/google_compute_region_autoscaler.rb | 94 ++++++++++ .../google_compute_region_autoscalers.rb | 107 +++++++++++ .../google_compute_region_autoscaler.rb | 57 ++++++ .../google_compute_region_autoscalers.rb | 41 +++++ 17 files changed, 977 insertions(+) create mode 100644 docs/resources/google_compute_region_autoscaler.md create mode 100644 docs/resources/google_compute_region_autoscalers.md create mode 100644 libraries/google/compute/property/regionautoscaler_autoscaling_policy.rb create mode 100644 libraries/google/compute/property/regionautoscaler_autoscaling_policy_cpu_utilization.rb create mode 100644 libraries/google/compute/property/regionautoscaler_autoscaling_policy_custom_metric_utilizations.rb create mode 100644 libraries/google/compute/property/regionautoscaler_autoscaling_policy_load_balancing_utilization.rb create mode 100644 libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_down_control.rb create mode 100644 libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_down_control_max_scaled_down_replicas.rb create mode 100644 libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_in_control.rb create mode 100644 libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_in_control_max_scaled_in_replicas.rb create mode 100644 libraries/google/compute/property/regionautoscaler_autoscaling_policy_scaling_schedules.rb create mode 100644 libraries/google/compute/property/regionautoscaler_scaling_schedule_status.rb create mode 100644 libraries/google/compute/property/regionautoscaler_status_details.rb create mode 100644 libraries/google_compute_region_autoscaler.rb create mode 100644 libraries/google_compute_region_autoscalers.rb create mode 100644 test/integration/verify/controls/google_compute_region_autoscaler.rb create mode 100644 test/integration/verify/controls/google_compute_region_autoscalers.rb diff --git a/docs/resources/google_compute_region_autoscaler.md b/docs/resources/google_compute_region_autoscaler.md new file mode 100644 index 000000000..885d4465e --- /dev/null +++ b/docs/resources/google_compute_region_autoscaler.md @@ -0,0 +1,173 @@ +--- +title: About the google_compute_region_autoscaler resource +platform: gcp +--- + +## Syntax +A `google_compute_region_autoscaler` is used to test a Google RegionAutoscaler resource + +## Examples +``` +describe google_compute_region_autoscaler(name: ' value_name', 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('name') { should cmp 'value_name' } + its('description') { should cmp 'value_description' } + its('target') { should cmp 'value_target' } + its('zone') { should cmp 'value_zone' } + its('region') { should cmp 'value_region' } + its('self_link') { should cmp 'value_selflink' } + its('self_link_with_id') { should cmp 'value_selflinkwithid' } + its('status') { should cmp 'value_status' } + +end + +describe google_compute_region_autoscaler(autoscaler: ' value_autoscaler', project: 'chef-gcp-inspec', region: ' value_region') do + it { should_not exist } +end +``` + +## Properties +Properties that can be accessed from the `google_compute_region_autoscaler` resource: + + + * `kind`: [Output Only] Type of the resource. Always compute#autoscaler for autoscalers. + + * `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. + + * `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. + + * `target`: URL of the managed instance group that this autoscaler will scale. This field is required when creating an autoscaler. + + * `autoscaling_policy`: Cloud Autoscaler policy. + + * `min_num_replicas`: The minimum number of replicas that the autoscaler can scale in to. This cannot be less than 0. If not provided, autoscaler chooses a default value depending on maximum number of instances allowed. + + * `max_num_replicas`: The maximum number of instances that the autoscaler can scale out to. This is required when creating or updating an autoscaler. The maximum number of replicas must not be lower than minimal number of replicas. + + * `scale_down_control`: Configuration that allows for slower scale in so that even if Autoscaler recommends an abrupt scale in of a MIG, it will be throttled as specified by the parameters below. + + * `max_scaled_down_replicas`: Encapsulates numeric value that can be either absolute or relative. + + * `fixed`: Specifies a fixed number of VM instances. This must be a positive integer. + + * `percent`: Specifies a percentage of instances between 0 to 100%, inclusive. For example, specify 80 for 80%. + + * `calculated`: [Output Only] Absolute value of VM instances calculated based on the specific mode. - If the value is fixed, then the calculated value is equal to the fixed value. - If the value is a percent, then the calculated value is percent/100 * targetSize. For example, the calculated value of a 80% of a managed instance group with 150 instances would be (80/100 * 150) = 120 VM instances. If there is a remainder, the number is rounded. + + * `time_window_sec`: How far back autoscaling looks when computing recommendations to include directives regarding slower scale in, as described above. + + * `scale_in_control`: Configuration that allows for slower scale in so that even if Autoscaler recommends an abrupt scale in of a MIG, it will be throttled as specified by the parameters below. + + * `max_scaled_in_replicas`: Encapsulates numeric value that can be either absolute or relative. + + * `fixed`: Specifies a fixed number of VM instances. This must be a positive integer. + + * `percent`: Specifies a percentage of instances between 0 to 100%, inclusive. For example, specify 80 for 80%. + + * `calculated`: [Output Only] Absolute value of VM instances calculated based on the specific mode. - If the value is fixed, then the calculated value is equal to the fixed value. - If the value is a percent, then the calculated value is percent/100 * targetSize. For example, the calculated value of a 80% of a managed instance group with 150 instances would be (80/100 * 150) = 120 VM instances. If there is a remainder, the number is rounded. + + * `time_window_sec`: How far back autoscaling looks when computing recommendations to include directives regarding slower scale in, as described above. + + * `cool_down_period_sec`: The number of seconds that your application takes to initialize on a VM instance. This is referred to as the [initialization period](/compute/docs/autoscaler#cool_down_period). Specifying an accurate initialization period improves autoscaler decisions. For example, when scaling out, the autoscaler ignores data from VMs that are still initializing because those VMs might not yet represent normal usage of your application. The default initialization period is 60 seconds. Initialization periods might vary because of numerous factors. We recommend that you test how long your application takes to initialize. To do this, create a VM and time your application's startup process. + + * `cpu_utilization`: CPU utilization policy. + + * `utilization_target`: The target CPU utilization that the autoscaler maintains. Must be a float value in the range (0, 1]. If not specified, the default is 0.6. If the CPU level is below the target utilization, the autoscaler scales in the number of instances until it reaches the minimum number of instances you specified or until the average CPU of your instances reaches the target utilization. If the average CPU is above the target utilization, the autoscaler scales out until it reaches the maximum number of instances you specified or until the average utilization reaches the target utilization. + + * `predictive_method`: Indicates whether predictive autoscaling based on CPU metric is enabled. Valid values are: * NONE (default). No predictive method is used. The autoscaler scales the group to meet current demand based on real-time metrics. * OPTIMIZE_AVAILABILITY. Predictive autoscaling improves availability by monitoring daily and weekly load patterns and scaling out ahead of anticipated demand. + Possible values: + * NONE + * OPTIMIZE_AVAILABILITY + * PREDICTIVE_METHOD_UNSPECIFIED + * STANDARD + + * `custom_metric_utilizations`: Configuration parameters of autoscaling based on a custom metric. + + * `metric`: The identifier (type) of the Stackdriver Monitoring metric. The metric cannot have negative values. The metric must have a value type of INT64 or DOUBLE. + + * `filter`: A filter string, compatible with a Stackdriver Monitoring filter string for TimeSeries.list API call. This filter is used to select a specific TimeSeries for the purpose of autoscaling and to determine whether the metric is exporting per-instance or per-group data. For the filter to be valid for autoscaling purposes, the following rules apply: - You can only use the AND operator for joining selectors. - You can only use direct equality comparison operator (=) without any functions for each selector. - You can specify the metric in both the filter string and in the metric field. However, if specified in both places, the metric must be identical. - The monitored resource type determines what kind of values are expected for the metric. If it is a gce_instance, the autoscaler expects the metric to include a separate TimeSeries for each instance in a group. In such a case, you cannot filter on resource labels. If the resource type is any other value, the autoscaler expects this metric to contain values that apply to the entire autoscaled instance group and resource label filtering can be performed to point autoscaler at the correct TimeSeries to scale upon. This is called a *per-group metric* for the purpose of autoscaling. If not specified, the type defaults to gce_instance. Try to provide a filter that is selective enough to pick just one TimeSeries for the autoscaled group or for each of the instances (if you are using gce_instance resource type). If multiple TimeSeries are returned upon the query execution, the autoscaler will sum their respective values to obtain its scaling value. + + * `utilization_target`: The target value of the metric that autoscaler maintains. This must be a positive value. A utilization metric scales number of virtual machines handling requests to increase or decrease proportionally to the metric. For example, a good metric to use as a utilization_target is https://www.googleapis.com/compute/v1/instance/network/received_bytes_count. The autoscaler works to keep this value constant for each of the instances. + + * `single_instance_assignment`: If scaling is based on a per-group metric value that represents the total amount of work to be done or resource usage, set this value to an amount assigned for a single instance of the scaled group. Autoscaler keeps the number of instances proportional to the value of this metric. The metric itself does not change value due to group resizing. A good metric to use with the target is for example pubsub.googleapis.com/subscription/num_undelivered_messages or a custom metric exporting the total number of requests coming to your instances. A bad example would be a metric exporting an average or median latency, since this value can't include a chunk assignable to a single instance, it could be better used with utilization_target instead. + + * `utilization_target_type`: Defines how target utilization value is expressed for a Stackdriver Monitoring metric. Either GAUGE, DELTA_PER_SECOND, or DELTA_PER_MINUTE. + Possible values: + * DELTA_PER_MINUTE + * DELTA_PER_SECOND + * GAUGE + + * `load_balancing_utilization`: Configuration parameters of autoscaling based on load balancing. + + * `utilization_target`: Fraction of backend capacity utilization (set in HTTP(S) load balancing configuration) that the autoscaler maintains. Must be a positive float value. If not defined, the default is 0.8. + + * `mode`: Defines the operating mode for this policy. The following modes are available: - OFF: Disables the autoscaler but maintains its configuration. - ONLY_SCALE_OUT: Restricts the autoscaler to add VM instances only. - ON: Enables all autoscaler activities according to its policy. For more information, see "Turning off or restricting an autoscaler" + Possible values: + * OFF + * ON + * ONLY_SCALE_OUT + * ONLY_UP + + * `scaling_schedules`: Scaling schedules defined for an autoscaler. Multiple schedules can be set on an autoscaler, and they can overlap. During overlapping periods the greatest min_required_replicas of all scaling schedules is applied. Up to 128 scaling schedules are allowed. + + * `additional_properties`: Scaling based on user-defined schedule. The message describes a single scaling schedule. A scaling schedule changes the minimum number of VM instances an autoscaler can recommend, which can trigger scaling out. + + * `zone`: [Output Only] URL of the zone where the instance group resides (for autoscalers living in zonal scope). + + * `region`: [Output Only] URL of the region where the instance group resides (for autoscalers living in regional scope). + + * `self_link`: [Output Only] Server-defined URL for the resource. + + * `self_link_with_id`: [Output Only] Server-defined URL for this resource with the resource id. + + * `status`: [Output Only] The status of the autoscaler configuration. Current set of possible values: - PENDING: Autoscaler backend hasn't read new/updated configuration. - DELETING: Configuration is being deleted. - ACTIVE: Configuration is acknowledged to be effective. Some warnings might be present in the statusDetails field. - ERROR: Configuration has errors. Actionable for users. Details are present in the statusDetails field. New values might be added in the future. + Possible values: + * ACTIVE + * DELETING + * ERROR + * PENDING + + * `status_details`: [Output Only] Human-readable details about the current state of the autoscaler. Read the documentation for Commonly returned status messages for examples of status messages you might encounter. + + * `message`: The status message. + + * `type`: The type of error, warning, or notice returned. Current set of possible values: - ALL_INSTANCES_UNHEALTHY (WARNING): All instances in the instance group are unhealthy (not in RUNNING state). - BACKEND_SERVICE_DOES_NOT_EXIST (ERROR): There is no backend service attached to the instance group. - CAPPED_AT_MAX_NUM_REPLICAS (WARNING): Autoscaler recommends a size greater than maxNumReplicas. - CUSTOM_METRIC_DATA_POINTS_TOO_SPARSE (WARNING): The custom metric samples are not exported often enough to be a credible base for autoscaling. - CUSTOM_METRIC_INVALID (ERROR): The custom metric that was specified does not exist or does not have the necessary labels. - MIN_EQUALS_MAX (WARNING): The minNumReplicas is equal to maxNumReplicas. This means the autoscaler cannot add or remove instances from the instance group. - MISSING_CUSTOM_METRIC_DATA_POINTS (WARNING): The autoscaler did not receive any data from the custom metric configured for autoscaling. - MISSING_LOAD_BALANCING_DATA_POINTS (WARNING): The autoscaler is configured to scale based on a load balancing signal but the instance group has not received any requests from the load balancer. - MODE_OFF (WARNING): Autoscaling is turned off. The number of instances in the group won't change automatically. The autoscaling configuration is preserved. - MODE_ONLY_UP (WARNING): Autoscaling is in the "Autoscale only out" mode. The autoscaler can add instances but not remove any. - MORE_THAN_ONE_BACKEND_SERVICE (ERROR): The instance group cannot be autoscaled because it has more than one backend service attached to it. - NOT_ENOUGH_QUOTA_AVAILABLE (ERROR): There is insufficient quota for the necessary resources, such as CPU or number of instances. - REGION_RESOURCE_STOCKOUT (ERROR): Shown only for regional autoscalers: there is a resource stockout in the chosen region. - SCALING_TARGET_DOES_NOT_EXIST (ERROR): The target to be scaled does not exist. - UNSUPPORTED_MAX_RATE_LOAD_BALANCING_CONFIGURATION (ERROR): Autoscaling does not work with an HTTP/S load balancer that has been configured for maxRate. - ZONE_RESOURCE_STOCKOUT (ERROR): For zonal autoscalers: there is a resource stockout in the chosen zone. For regional autoscalers: in at least one of the zones you're using there is a resource stockout. New values might be added in the future. Some of the values might not be available in all API versions. + Possible values: + * ALL_INSTANCES_UNHEALTHY + * BACKEND_SERVICE_DOES_NOT_EXIST + * CAPPED_AT_MAX_NUM_REPLICAS + * CUSTOM_METRIC_DATA_POINTS_TOO_SPARSE + * CUSTOM_METRIC_INVALID + * MIN_EQUALS_MAX + * MISSING_CUSTOM_METRIC_DATA_POINTS + * MISSING_LOAD_BALANCING_DATA_POINTS + * MODE_OFF + * MODE_ONLY_SCALE_OUT + * MODE_ONLY_UP + * MORE_THAN_ONE_BACKEND_SERVICE + * NOT_ENOUGH_QUOTA_AVAILABLE + * REGION_RESOURCE_STOCKOUT + * SCALING_TARGET_DOES_NOT_EXIST + * SCHEDULED_INSTANCES_GREATER_THAN_AUTOSCALER_MAX + * SCHEDULED_INSTANCES_LESS_THAN_AUTOSCALER_MIN + * UNKNOWN + * UNSUPPORTED_MAX_RATE_LOAD_BALANCING_CONFIGURATION + * ZONE_RESOURCE_STOCKOUT + + * `recommended_size`: [Output Only] Target recommended MIG size (number of instances) computed by autoscaler. Autoscaler calculates the recommended MIG size even when the autoscaling policy mode is different from ON. This field is empty when autoscaler is not connected to an existing managed instance group or autoscaler did not generate its prediction. + + * `scaling_schedule_status`: [Output Only] Status information of existing scaling schedules. + + * `additional_properties`: + + +## 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_autoscalers.md b/docs/resources/google_compute_region_autoscalers.md new file mode 100644 index 000000000..806967ce0 --- /dev/null +++ b/docs/resources/google_compute_region_autoscalers.md @@ -0,0 +1,42 @@ +--- +title: About the google_compute_region_autoscalers resource +platform: gcp +--- + +## Syntax +A `google_compute_region_autoscalers` is used to test a Google RegionAutoscaler resource + +## Examples +``` + describe google_compute_region_autoscalers(project: 'chef-gcp-inspec', region: ' value_region') do + it { should exist } + end +``` + +## Properties +Properties that can be accessed from the `google_compute_region_autoscalers` resource: + +See [google_compute_region_autoscaler.md](google_compute_region_autoscaler.md) for more detailed information + * `kinds`: an array of `google_compute_region_autoscaler` kind + * `ids`: an array of `google_compute_region_autoscaler` id + * `creation_timestamps`: an array of `google_compute_region_autoscaler` creation_timestamp + * `names`: an array of `google_compute_region_autoscaler` name + * `descriptions`: an array of `google_compute_region_autoscaler` description + * `targets`: an array of `google_compute_region_autoscaler` target + * `autoscaling_policies`: an array of `google_compute_region_autoscaler` autoscaling_policy + * `zones`: an array of `google_compute_region_autoscaler` zone + * `regions`: an array of `google_compute_region_autoscaler` region + * `self_links`: an array of `google_compute_region_autoscaler` self_link + * `self_link_with_ids`: an array of `google_compute_region_autoscaler` self_link_with_id + * `statuses`: an array of `google_compute_region_autoscaler` status + * `status_details`: an array of `google_compute_region_autoscaler` status_details + * `recommended_sizes`: an array of `google_compute_region_autoscaler` recommended_size + * `scaling_schedule_statuses`: an array of `google_compute_region_autoscaler` scaling_schedule_status + +## 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/regionautoscaler_autoscaling_policy.rb b/libraries/google/compute/property/regionautoscaler_autoscaling_policy.rb new file mode 100644 index 000000000..0cbac1827 --- /dev/null +++ b/libraries/google/compute/property/regionautoscaler_autoscaling_policy.rb @@ -0,0 +1,69 @@ +# 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/regionautoscaler_autoscaling_policy_cpu_utilization' +require 'google/compute/property/regionautoscaler_autoscaling_policy_custom_metric_utilizations' +require 'google/compute/property/regionautoscaler_autoscaling_policy_load_balancing_utilization' +require 'google/compute/property/regionautoscaler_autoscaling_policy_scale_down_control' +require 'google/compute/property/regionautoscaler_autoscaling_policy_scale_down_control_max_scaled_down_replicas' +require 'google/compute/property/regionautoscaler_autoscaling_policy_scale_in_control' +require 'google/compute/property/regionautoscaler_autoscaling_policy_scale_in_control_max_scaled_in_replicas' +require 'google/compute/property/regionautoscaler_autoscaling_policy_scaling_schedules' +module GoogleInSpec + module Compute + module Property + class RegionAutoscalerAutoscalingPolicy + attr_reader :min_num_replicas + + attr_reader :max_num_replicas + + attr_reader :scale_down_control + + attr_reader :scale_in_control + + attr_reader :cool_down_period_sec + + attr_reader :cpu_utilization + + attr_reader :custom_metric_utilizations + + attr_reader :load_balancing_utilization + + attr_reader :mode + + attr_reader :scaling_schedules + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @min_num_replicas = args['minNumReplicas'] + @max_num_replicas = args['maxNumReplicas'] + @scale_down_control = GoogleInSpec::Compute::Property::RegionAutoscalerAutoscalingPolicyScaleDownControl.new(args['scaleDownControl'], to_s) + @scale_in_control = GoogleInSpec::Compute::Property::RegionAutoscalerAutoscalingPolicyScaleInControl.new(args['scaleInControl'], to_s) + @cool_down_period_sec = args['coolDownPeriodSec'] + @cpu_utilization = GoogleInSpec::Compute::Property::RegionAutoscalerAutoscalingPolicyCpuUtilization.new(args['cpuUtilization'], to_s) + @custom_metric_utilizations = GoogleInSpec::Compute::Property::RegionAutoscalerAutoscalingPolicyCustomMetricUtilizationsArray.parse(args['customMetricUtilizations'], to_s) + @load_balancing_utilization = GoogleInSpec::Compute::Property::RegionAutoscalerAutoscalingPolicyLoadBalancingUtilization.new(args['loadBalancingUtilization'], to_s) + @mode = args['mode'] + @scaling_schedules = GoogleInSpec::Compute::Property::RegionAutoscalerAutoscalingPolicyScalingSchedules.new(args['scalingSchedules'], to_s) + end + + def to_s + "#{@parent_identifier} RegionAutoscalerAutoscalingPolicy" + end + end + end + end +end diff --git a/libraries/google/compute/property/regionautoscaler_autoscaling_policy_cpu_utilization.rb b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_cpu_utilization.rb new file mode 100644 index 000000000..1715b4f32 --- /dev/null +++ b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_cpu_utilization.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 RegionAutoscalerAutoscalingPolicyCpuUtilization + attr_reader :utilization_target + + attr_reader :predictive_method + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @utilization_target = args['utilizationTarget'] + @predictive_method = args['predictiveMethod'] + end + + def to_s + "#{@parent_identifier} RegionAutoscalerAutoscalingPolicyCpuUtilization" + end + end + end + end +end diff --git a/libraries/google/compute/property/regionautoscaler_autoscaling_policy_custom_metric_utilizations.rb b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_custom_metric_utilizations.rb new file mode 100644 index 000000000..635623d4a --- /dev/null +++ b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_custom_metric_utilizations.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. +# +# ---------------------------------------------------------------------------- +module GoogleInSpec + module Compute + module Property + class RegionAutoscalerAutoscalingPolicyCustomMetricUtilizations + attr_reader :metric + + attr_reader :filter + + attr_reader :utilization_target + + attr_reader :single_instance_assignment + + attr_reader :utilization_target_type + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @metric = args['metric'] + @filter = args['filter'] + @utilization_target = args['utilizationTarget'] + @single_instance_assignment = args['singleInstanceAssignment'] + @utilization_target_type = args['utilizationTargetType'] + end + + def to_s + "#{@parent_identifier} RegionAutoscalerAutoscalingPolicyCustomMetricUtilizations" + end + end + + class RegionAutoscalerAutoscalingPolicyCustomMetricUtilizationsArray + def self.parse(value, parent_identifier) + return if value.nil? + return RegionAutoscalerAutoscalingPolicyCustomMetricUtilizations.new(value, parent_identifier) unless value.is_a?(::Array) + value.map { |v| RegionAutoscalerAutoscalingPolicyCustomMetricUtilizations.new(v, parent_identifier) } + end + end + end + end +end diff --git a/libraries/google/compute/property/regionautoscaler_autoscaling_policy_load_balancing_utilization.rb b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_load_balancing_utilization.rb new file mode 100644 index 000000000..39329f911 --- /dev/null +++ b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_load_balancing_utilization.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 RegionAutoscalerAutoscalingPolicyLoadBalancingUtilization + attr_reader :utilization_target + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @utilization_target = args['utilizationTarget'] + end + + def to_s + "#{@parent_identifier} RegionAutoscalerAutoscalingPolicyLoadBalancingUtilization" + end + end + end + end +end diff --git a/libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_down_control.rb b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_down_control.rb new file mode 100644 index 000000000..0752b390c --- /dev/null +++ b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_down_control.rb @@ -0,0 +1,38 @@ +# 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/regionautoscaler_autoscaling_policy_scale_down_control_max_scaled_down_replicas' +module GoogleInSpec + module Compute + module Property + class RegionAutoscalerAutoscalingPolicyScaleDownControl + attr_reader :max_scaled_down_replicas + + attr_reader :time_window_sec + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @max_scaled_down_replicas = GoogleInSpec::Compute::Property::RegionAutoscalerAutoscalingPolicyScaleDownControlMaxScaledDownReplicas.new(args['maxScaledDownReplicas'], to_s) + @time_window_sec = args['timeWindowSec'] + end + + def to_s + "#{@parent_identifier} RegionAutoscalerAutoscalingPolicyScaleDownControl" + end + end + end + end +end diff --git a/libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_down_control_max_scaled_down_replicas.rb b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_down_control_max_scaled_down_replicas.rb new file mode 100644 index 000000000..beeee70d9 --- /dev/null +++ b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_down_control_max_scaled_down_replicas.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 RegionAutoscalerAutoscalingPolicyScaleDownControlMaxScaledDownReplicas + attr_reader :fixed + + attr_reader :percent + + attr_reader :calculated + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @fixed = args['fixed'] + @percent = args['percent'] + @calculated = args['calculated'] + end + + def to_s + "#{@parent_identifier} RegionAutoscalerAutoscalingPolicyScaleDownControlMaxScaledDownReplicas" + end + end + end + end +end diff --git a/libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_in_control.rb b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_in_control.rb new file mode 100644 index 000000000..92d80dd1c --- /dev/null +++ b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_in_control.rb @@ -0,0 +1,38 @@ +# 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/regionautoscaler_autoscaling_policy_scale_in_control_max_scaled_in_replicas' +module GoogleInSpec + module Compute + module Property + class RegionAutoscalerAutoscalingPolicyScaleInControl + attr_reader :max_scaled_in_replicas + + attr_reader :time_window_sec + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @max_scaled_in_replicas = GoogleInSpec::Compute::Property::RegionAutoscalerAutoscalingPolicyScaleInControlMaxScaledInReplicas.new(args['maxScaledInReplicas'], to_s) + @time_window_sec = args['timeWindowSec'] + end + + def to_s + "#{@parent_identifier} RegionAutoscalerAutoscalingPolicyScaleInControl" + end + end + end + end +end diff --git a/libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_in_control_max_scaled_in_replicas.rb b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_in_control_max_scaled_in_replicas.rb new file mode 100644 index 000000000..fe505de52 --- /dev/null +++ b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_scale_in_control_max_scaled_in_replicas.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 RegionAutoscalerAutoscalingPolicyScaleInControlMaxScaledInReplicas + attr_reader :fixed + + attr_reader :percent + + attr_reader :calculated + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @fixed = args['fixed'] + @percent = args['percent'] + @calculated = args['calculated'] + end + + def to_s + "#{@parent_identifier} RegionAutoscalerAutoscalingPolicyScaleInControlMaxScaledInReplicas" + end + end + end + end +end diff --git a/libraries/google/compute/property/regionautoscaler_autoscaling_policy_scaling_schedules.rb b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_scaling_schedules.rb new file mode 100644 index 000000000..188bb0ae5 --- /dev/null +++ b/libraries/google/compute/property/regionautoscaler_autoscaling_policy_scaling_schedules.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 RegionAutoscalerAutoscalingPolicyScalingSchedules + 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} RegionAutoscalerAutoscalingPolicyScalingSchedules" + end + end + end + end +end diff --git a/libraries/google/compute/property/regionautoscaler_scaling_schedule_status.rb b/libraries/google/compute/property/regionautoscaler_scaling_schedule_status.rb new file mode 100644 index 000000000..aca579dee --- /dev/null +++ b/libraries/google/compute/property/regionautoscaler_scaling_schedule_status.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 RegionAutoscalerScalingScheduleStatus + 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} RegionAutoscalerScalingScheduleStatus" + end + end + end + end +end diff --git a/libraries/google/compute/property/regionautoscaler_status_details.rb b/libraries/google/compute/property/regionautoscaler_status_details.rb new file mode 100644 index 000000000..dfa940713 --- /dev/null +++ b/libraries/google/compute/property/regionautoscaler_status_details.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 RegionAutoscalerStatusDetails + attr_reader :message + + attr_reader :type + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @message = args['message'] + @type = args['type'] + end + + def to_s + "#{@parent_identifier} RegionAutoscalerStatusDetails" + end + end + + class RegionAutoscalerStatusDetailsArray + def self.parse(value, parent_identifier) + return if value.nil? + return RegionAutoscalerStatusDetails.new(value, parent_identifier) unless value.is_a?(::Array) + value.map { |v| RegionAutoscalerStatusDetails.new(v, parent_identifier) } + end + end + end + end +end diff --git a/libraries/google_compute_region_autoscaler.rb b/libraries/google_compute_region_autoscaler.rb new file mode 100644 index 000000000..0425797aa --- /dev/null +++ b/libraries/google_compute_region_autoscaler.rb @@ -0,0 +1,94 @@ +# 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/regionautoscaler_autoscaling_policy' +require 'google/compute/property/regionautoscaler_autoscaling_policy_cpu_utilization' +require 'google/compute/property/regionautoscaler_autoscaling_policy_custom_metric_utilizations' +require 'google/compute/property/regionautoscaler_autoscaling_policy_load_balancing_utilization' +require 'google/compute/property/regionautoscaler_autoscaling_policy_scale_down_control' +require 'google/compute/property/regionautoscaler_autoscaling_policy_scale_down_control_max_scaled_down_replicas' +require 'google/compute/property/regionautoscaler_autoscaling_policy_scale_in_control' +require 'google/compute/property/regionautoscaler_autoscaling_policy_scale_in_control_max_scaled_in_replicas' +require 'google/compute/property/regionautoscaler_autoscaling_policy_scaling_schedules' +require 'google/compute/property/regionautoscaler_scaling_schedule_status' +require 'google/compute/property/regionautoscaler_status_details' + +# A provider to manage Compute Engine resources. +class ComputeRegionAutoscaler < GcpResourceBase + name 'google_compute_region_autoscaler' + desc 'RegionAutoscaler' + supports platform: 'gcp' + + attr_reader :params + attr_reader :kind + attr_reader :id + attr_reader :creation_timestamp + attr_reader :name + attr_reader :description + attr_reader :target + attr_reader :autoscaling_policy + attr_reader :zone + attr_reader :region + attr_reader :self_link + attr_reader :self_link_with_id + attr_reader :status + attr_reader :status_details + attr_reader :recommended_size + attr_reader :scaling_schedule_status + + 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'] + @name = @fetched['name'] + @description = @fetched['description'] + @target = @fetched['target'] + @autoscaling_policy = GoogleInSpec::Compute::Property::RegionAutoscalerAutoscalingPolicy.new(@fetched['autoscalingPolicy'], to_s) + @zone = @fetched['zone'] + @region = @fetched['region'] + @self_link = @fetched['selfLink'] + @self_link_with_id = @fetched['selfLinkWithId'] + @status = @fetched['status'] + @status_details = GoogleInSpec::Compute::Property::RegionAutoscalerStatusDetailsArray.parse(@fetched['statusDetails'], to_s) + @recommended_size = @fetched['recommendedSize'] + @scaling_schedule_status = GoogleInSpec::Compute::Property::RegionAutoscalerScalingScheduleStatus.new(@fetched['scalingScheduleStatus'], to_s) + end + + def exists? + !@fetched.nil? + end + + def to_s + "RegionAutoscaler #{@params[:autoscaler]}" + end + + private + + def product_url(_ = nil) + 'https://compute.googleapis.com/compute/v1/' + end + + def resource_base_url + 'projects/{{project}}/regions/{{region}}/autoscalers/{{autoscaler}}' + end +end diff --git a/libraries/google_compute_region_autoscalers.rb b/libraries/google_compute_region_autoscalers.rb new file mode 100644 index 000000000..e3b7f7671 --- /dev/null +++ b/libraries/google_compute_region_autoscalers.rb @@ -0,0 +1,107 @@ +# 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 ComputeRegionAutoscalers < GcpResourceBase + name 'google_compute_region_autoscalers' + desc 'RegionAutoscaler 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(:names, field: :name) + filter_table_config.add(:descriptions, field: :description) + filter_table_config.add(:targets, field: :target) + filter_table_config.add(:autoscaling_policies, field: :autoscaling_policy) + filter_table_config.add(:zones, field: :zone) + filter_table_config.add(:regions, field: :region) + 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(:statuses, field: :status) + filter_table_config.add(:status_details, field: :status_details) + filter_table_config.add(:recommended_sizes, field: :recommended_size) + filter_table_config.add(:scaling_schedule_statuses, field: :scaling_schedule_status) + + filter_table_config.connect(self, :table) + + def initialize(params = {}) + super(params.merge({ use_http_transport: true })) + @params = params + @table = fetch_wrapped_resource('regionAutoscalers') + 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']] }, + 'name' => ->(obj) { [:name, obj['name']] }, + 'description' => ->(obj) { [:description, obj['description']] }, + 'target' => ->(obj) { [:target, obj['target']] }, + 'autoscalingPolicy' => ->(obj) { [:autoscaling_policy, GoogleInSpec::Compute::Property::RegionAutoscalerAutoscalingPolicy.new(obj['autoscalingPolicy'], to_s)] }, + 'zone' => ->(obj) { [:zone, obj['zone']] }, + 'region' => ->(obj) { [:region, obj['region']] }, + 'selfLink' => ->(obj) { [:self_link, obj['selfLink']] }, + 'selfLinkWithId' => ->(obj) { [:self_link_with_id, obj['selfLinkWithId']] }, + 'status' => ->(obj) { [:status, obj['status']] }, + 'statusDetails' => ->(obj) { [:status_details, GoogleInSpec::Compute::Property::RegionAutoscalerStatusDetailsArray.parse(obj['statusDetails'], to_s)] }, + 'recommendedSize' => ->(obj) { [:recommended_size, obj['recommendedSize']] }, + 'scalingScheduleStatus' => ->(obj) { [:scaling_schedule_status, GoogleInSpec::Compute::Property::RegionAutoscalerScalingScheduleStatus.new(obj['scalingScheduleStatus'], to_s)] }, + } + end + + private + + def product_url(_ = nil) + 'https://compute.googleapis.com/compute/v1/' + end + + def resource_base_url + 'projects/{{project}}/regions/{{region}}/autoscalers' + end +end diff --git a/test/integration/verify/controls/google_compute_region_autoscaler.rb b/test/integration/verify/controls/google_compute_region_autoscaler.rb new file mode 100644 index 000000000..2e72417ef --- /dev/null +++ b/test/integration/verify/controls/google_compute_region_autoscaler.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_region_autoscaler resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + region_autoscaler = input('region_autoscaler', value: { + "autoscaler": "value_autoscaler", + "project": "value_project", + "region": "value_region", + "kind": "value_kind", + "id": "value_id", + "creation_timestamp": "value_creationtimestamp", + "name": "value_name", + "description": "value_description", + "target": "value_target", + "zone": "value_zone", + "self_link": "value_selflink", + "self_link_with_id": "value_selflinkwithid", + "status": "value_status" +}, description: 'region_autoscaler description') +control 'google_compute_region_autoscaler-1.0' do + impact 1.0 + title 'google_compute_region_autoscaler resource test' + + describe google_compute_region_autoscaler(name: region_autoscaler['name'], project: gcp_project_id, region: region_autoscaler['region']) do + it { should exist } + its('kind') { should cmp region_autoscaler['kind'] } + its('id') { should cmp region_autoscaler['id'] } + its('creation_timestamp') { should cmp region_autoscaler['creation_timestamp'] } + its('name') { should cmp region_autoscaler['name'] } + its('description') { should cmp region_autoscaler['description'] } + its('target') { should cmp region_autoscaler['target'] } + its('zone') { should cmp region_autoscaler['zone'] } + its('region') { should cmp region_autoscaler['region'] } + its('self_link') { should cmp region_autoscaler['self_link'] } + its('self_link_with_id') { should cmp region_autoscaler['self_link_with_id'] } + its('status') { should cmp region_autoscaler['status'] } + + end + + describe google_compute_region_autoscaler(autoscaler: region_autoscaler['autoscaler'], project: gcp_project_id, region: region_autoscaler['region']) do + it { should_not exist } + end +end diff --git a/test/integration/verify/controls/google_compute_region_autoscalers.rb b/test/integration/verify/controls/google_compute_region_autoscalers.rb new file mode 100644 index 000000000..d9b135c2f --- /dev/null +++ b/test/integration/verify/controls/google_compute_region_autoscalers.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_region_autoscalers resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + region_autoscaler = input('region_autoscaler', value: { + "autoscaler": "value_autoscaler", + "project": "value_project", + "region": "value_region", + "kind": "value_kind", + "id": "value_id", + "creation_timestamp": "value_creationtimestamp", + "name": "value_name", + "description": "value_description", + "target": "value_target", + "zone": "value_zone", + "self_link": "value_selflink", + "self_link_with_id": "value_selflinkwithid", + "status": "value_status" +}, description: 'region_autoscaler description') +control 'google_compute_region_autoscalers-1.0' do + impact 1.0 + title 'google_compute_region_autoscalers resource test' + + describe google_compute_region_autoscalers(project: gcp_project_id, region: region_autoscaler['region']) do + it { should exist } + end +end From d7893794a628e9e53aebd8a508061a0a8b855ddb Mon Sep 17 00:00:00 2001 From: balasubramanian-s Date: Thu, 4 Apr 2024 18:00:34 +0530 Subject: [PATCH 2/2] modify attributes Signed-off-by: balasubramanian-s --- docs/resources/google_compute_region_autoscaler.md | 10 +++++----- docs/resources/google_compute_region_autoscalers.md | 2 +- libraries/google_compute_region_autoscaler.rb | 4 ++-- libraries/google_compute_region_autoscalers.rb | 2 +- .../controls/google_compute_region_autoscaler.rb | 9 ++++----- .../controls/google_compute_region_autoscalers.rb | 9 ++++----- 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/docs/resources/google_compute_region_autoscaler.md b/docs/resources/google_compute_region_autoscaler.md index 885d4465e..758c31855 100644 --- a/docs/resources/google_compute_region_autoscaler.md +++ b/docs/resources/google_compute_region_autoscaler.md @@ -8,7 +8,7 @@ A `google_compute_region_autoscaler` is used to test a Google RegionAutoscaler r ## Examples ``` -describe google_compute_region_autoscaler(name: ' value_name', project: 'chef-gcp-inspec', region: ' value_region') do +describe google_compute_region_autoscaler(name: 'value_name', project: 'chef-gcp-inspec', region: 'value_region') do it { should exist } its('kind') { should cmp 'value_kind' } its('id') { should cmp 'value_id' } @@ -24,7 +24,7 @@ describe google_compute_region_autoscaler(name: ' value_name', project: 'chef-gc end -describe google_compute_region_autoscaler(autoscaler: ' value_autoscaler', project: 'chef-gcp-inspec', region: ' value_region') do +describe google_compute_region_autoscaler(name: 'value_name', project: 'chef-gcp-inspec', region: ' value_region') do it { should_not exist } end ``` @@ -59,7 +59,7 @@ Properties that can be accessed from the `google_compute_region_autoscaler` reso * `percent`: Specifies a percentage of instances between 0 to 100%, inclusive. For example, specify 80 for 80%. - * `calculated`: [Output Only] Absolute value of VM instances calculated based on the specific mode. - If the value is fixed, then the calculated value is equal to the fixed value. - If the value is a percent, then the calculated value is percent/100 * targetSize. For example, the calculated value of a 80% of a managed instance group with 150 instances would be (80/100 * 150) = 120 VM instances. If there is a remainder, the number is rounded. + * `calculated`: [Output Only] Absolute value of VM instances calculated based on the specific mode. - If the value is fixed, then the calculated value is equal to the fixed value. - If the value is a percent, then the calculated value is percent/100 * targetSize. For example, the calculated value of a 80% of a managed instance group with 150 instances would be (80/100 * 150) = 120 VM instances. If there is a remainder, the number is rounded. * `time_window_sec`: How far back autoscaling looks when computing recommendations to include directives regarding slower scale in, as described above. @@ -71,7 +71,7 @@ Properties that can be accessed from the `google_compute_region_autoscaler` reso * `percent`: Specifies a percentage of instances between 0 to 100%, inclusive. For example, specify 80 for 80%. - * `calculated`: [Output Only] Absolute value of VM instances calculated based on the specific mode. - If the value is fixed, then the calculated value is equal to the fixed value. - If the value is a percent, then the calculated value is percent/100 * targetSize. For example, the calculated value of a 80% of a managed instance group with 150 instances would be (80/100 * 150) = 120 VM instances. If there is a remainder, the number is rounded. + * `calculated`: [Output Only] Absolute value of VM instances calculated based on the specific mode. - If the value is fixed, then the calculated value is equal to the fixed value. - If the value is a percent, then the calculated value is percent/100 * targetSize. For example, the calculated value of a 80% of a managed instance group with 150 instances would be (80/100 * 150) = 120 VM instances. If there is a remainder, the number is rounded. * `time_window_sec`: How far back autoscaling looks when computing recommendations to include directives regarding slower scale in, as described above. @@ -165,7 +165,7 @@ Properties that can be accessed from the `google_compute_region_autoscaler` reso * `scaling_schedule_status`: [Output Only] Status information of existing scaling schedules. - * `additional_properties`: + * `additional_properties`: ## GCP Permissions diff --git a/docs/resources/google_compute_region_autoscalers.md b/docs/resources/google_compute_region_autoscalers.md index 806967ce0..1b97a606a 100644 --- a/docs/resources/google_compute_region_autoscalers.md +++ b/docs/resources/google_compute_region_autoscalers.md @@ -8,7 +8,7 @@ A `google_compute_region_autoscalers` is used to test a Google RegionAutoscaler ## Examples ``` - describe google_compute_region_autoscalers(project: 'chef-gcp-inspec', region: ' value_region') do + describe google_compute_region_autoscalers(project: 'chef-gcp-inspec', region: ' value_region') do it { should exist } end ``` diff --git a/libraries/google_compute_region_autoscaler.rb b/libraries/google_compute_region_autoscaler.rb index 0425797aa..51c4aa0b4 100644 --- a/libraries/google_compute_region_autoscaler.rb +++ b/libraries/google_compute_region_autoscaler.rb @@ -79,7 +79,7 @@ def exists? end def to_s - "RegionAutoscaler #{@params[:autoscaler]}" + "RegionAutoscaler #{@params[:name]}" end private @@ -89,6 +89,6 @@ def product_url(_ = nil) end def resource_base_url - 'projects/{{project}}/regions/{{region}}/autoscalers/{{autoscaler}}' + 'projects/{{project}}/regions/{{region}}/autoscalers/{{name}}' end end diff --git a/libraries/google_compute_region_autoscalers.rb b/libraries/google_compute_region_autoscalers.rb index e3b7f7671..4d6c67072 100644 --- a/libraries/google_compute_region_autoscalers.rb +++ b/libraries/google_compute_region_autoscalers.rb @@ -44,7 +44,7 @@ class ComputeRegionAutoscalers < GcpResourceBase def initialize(params = {}) super(params.merge({ use_http_transport: true })) @params = params - @table = fetch_wrapped_resource('regionAutoscalers') + @table = fetch_wrapped_resource('items') end def fetch_wrapped_resource(wrap_path) diff --git a/test/integration/verify/controls/google_compute_region_autoscaler.rb b/test/integration/verify/controls/google_compute_region_autoscaler.rb index 2e72417ef..625be9762 100644 --- a/test/integration/verify/controls/google_compute_region_autoscaler.rb +++ b/test/integration/verify/controls/google_compute_region_autoscaler.rb @@ -17,13 +17,12 @@ gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') region_autoscaler = input('region_autoscaler', value: { - "autoscaler": "value_autoscaler", "project": "value_project", - "region": "value_region", - "kind": "value_kind", + "region": "us-central1", + "kind": "compute#autoscaler", "id": "value_id", "creation_timestamp": "value_creationtimestamp", - "name": "value_name", + "name": "inspec-test-group-2", "description": "value_description", "target": "value_target", "zone": "value_zone", @@ -51,7 +50,7 @@ end - describe google_compute_region_autoscaler(autoscaler: region_autoscaler['autoscaler'], project: gcp_project_id, region: region_autoscaler['region']) do + describe google_compute_region_autoscaler(name: region_autoscaler['name'], project: gcp_project_id, region: region_autoscaler['region']) do it { should_not exist } end end diff --git a/test/integration/verify/controls/google_compute_region_autoscalers.rb b/test/integration/verify/controls/google_compute_region_autoscalers.rb index d9b135c2f..3fb976ca1 100644 --- a/test/integration/verify/controls/google_compute_region_autoscalers.rb +++ b/test/integration/verify/controls/google_compute_region_autoscalers.rb @@ -17,13 +17,12 @@ gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') region_autoscaler = input('region_autoscaler', value: { - "autoscaler": "value_autoscaler", "project": "value_project", - "region": "value_region", - "kind": "value_kind", + "region": "us-central1", + "kind": "compute#autoscaler", "id": "value_id", "creation_timestamp": "value_creationtimestamp", - "name": "value_name", + "name": "inspec-test-group-2", "description": "value_description", "target": "value_target", "zone": "value_zone", @@ -35,7 +34,7 @@ impact 1.0 title 'google_compute_region_autoscalers resource test' - describe google_compute_region_autoscalers(project: gcp_project_id, region: region_autoscaler['region']) do + describe google_compute_region_autoscalers(project: gcp_project_id, region: region_autoscaler['region']) do it { should exist } end end