This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
forked from inspec/inspec-gcp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
b93eebd
commit cccc87a
Showing
21 changed files
with
724 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
title: About the Autoscaler resource | ||
platform: gcp | ||
--- | ||
|
||
|
||
## Syntax | ||
A `google_compute_autoscaler` is used to test a Google Autoscaler resource | ||
|
||
## Examples | ||
``` | ||
describe google_compute_autoscaler(project: 'chef-gcp-inspec', zone: 'zone', name: 'inspec-gcp-autoscaler') do | ||
it { should exist } | ||
its('target') { should match /\/inspec-gcp-igm$/ } | ||
its('autoscaling_policy.max_num_replicas') { should eq '5' } | ||
its('autoscaling_policy.min_num_replicas') { should eq '1' } | ||
its('autoscaling_policy.cool_down_period_sec') { should eq '60' } | ||
its('autoscaling_policy.cpu_utilization.utilization_target') { should eq '0.5' } | ||
end | ||
describe google_compute_autoscaler(project: 'chef-gcp-inspec', zone: 'zone', name: 'nonexistent') do | ||
it { should_not exist } | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_compute_autoscaler` resource: | ||
|
||
* `id`: Unique identifier for the resource. | ||
|
||
* `creation_timestamp`: Creation timestamp in RFC3339 text format. | ||
|
||
* `name`: Name of the resource. 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. | ||
|
||
* `autoscaling_policy`: The configuration parameters for the autoscaling algorithm. You can define one or more of the policies for an autoscaler: cpuUtilization, customMetricUtilizations, and loadBalancingUtilization. If none of these are specified, the default will be to autoscale based on cpuUtilization to 0.6 or 60%. | ||
|
||
* `minNumReplicas`: The minimum number of replicas that the autoscaler can scale down to. This cannot be less than 0. If not provided, autoscaler will choose a default value depending on maximum number of instances allowed. | ||
|
||
* `maxNumReplicas`: The maximum number of instances that the autoscaler can scale up to. This is required when creating or updating an autoscaler. The maximum number of replicas should not be lower than minimal number of replicas. | ||
|
||
* `coolDownPeriodSec`: The number of seconds that the autoscaler should wait before it starts collecting information from a new instance. This prevents the autoscaler from collecting information when the instance is initializing, during which the collected usage would not be reliable. The default time autoscaler waits is 60 seconds. Virtual machine initialization times might vary because of numerous factors. We recommend that you test how long an instance may take to initialize. To do this, create an instance and time the startup process. | ||
|
||
* `cpuUtilization`: Defines the CPU utilization policy that allows the autoscaler to scale based on the average CPU utilization of a managed instance group. | ||
|
||
* `customMetricUtilizations`: Defines the CPU utilization policy that allows the autoscaler to scale based on the average CPU utilization of a managed instance group. | ||
|
||
* `loadBalancingUtilization`: Configuration parameters of autoscaling based on a load balancer. | ||
|
||
* `target`: URL of the managed instance group that this autoscaler will scale. | ||
|
||
* `zone`: URL of the zone where the instance group resides. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
title: About the Autoscaler resource | ||
platform: gcp | ||
--- | ||
|
||
|
||
## Syntax | ||
A `google_compute_autoscalers` is used to test a Google Autoscaler resource | ||
|
||
## Examples | ||
``` | ||
autoscalers = google_compute_autoscalers(project: 'chef-gcp-inspec', zone: 'zone') | ||
describe.one do | ||
autoscalers.autoscaling_policies.each do |autoscaling_policy| | ||
describe autoscaling_policy do | ||
its('max_num_replicas') { should eq '5' } | ||
its('min_num_replicas') { should eq '1' } | ||
its('cool_down_period_sec') { should eq '60' } | ||
its('cpu_utilization.utilization_target') { should eq '0.5' } | ||
end | ||
end | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_compute_autoscalers` resource: | ||
|
||
See [google_compute_autoscaler.md](google_compute_autoscaler.md) for more detailed information | ||
* `ids`: an array of `google_compute_autoscaler` id | ||
* `creation_timestamps`: an array of `google_compute_autoscaler` creation_timestamp | ||
* `names`: an array of `google_compute_autoscaler` name | ||
* `descriptions`: an array of `google_compute_autoscaler` description | ||
* `autoscaling_policies`: an array of `google_compute_autoscaler` autoscaling_policy | ||
* `targets`: an array of `google_compute_autoscaler` target | ||
* `zones`: an array of `google_compute_autoscaler` zone | ||
|
||
## Filter Criteria | ||
This resource supports all of the above properties as filter criteria, which can be used | ||
with `where` as a block or a method. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
libraries/google/compute/property/autoscaler_autoscaling_policy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: false | ||
|
||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# This file is automatically generated by Magic Modules and manual | ||
# changes will be clobbered when the file is regenerated. | ||
# | ||
# Please read more about how to change this file in README.md and | ||
# CONTRIBUTING.md located at the root of this package. | ||
# | ||
# ---------------------------------------------------------------------------- | ||
require 'google/compute/property/autoscaler_cpu_utilization' | ||
require 'google/compute/property/autoscaler_custom_metric_utilizations' | ||
require 'google/compute/property/autoscaler_load_balancing_utilization' | ||
module GoogleInSpec | ||
module Compute | ||
module Property | ||
class AutoscalerAutoscalingpolicy | ||
attr_reader :min_num_replicas | ||
|
||
attr_reader :max_num_replicas | ||
|
||
attr_reader :cool_down_period_sec | ||
|
||
attr_reader :cpu_utilization | ||
|
||
attr_reader :custom_metric_utilizations | ||
|
||
attr_reader :load_balancing_utilization | ||
|
||
def initialize(args = nil) | ||
return if args.nil? | ||
@min_num_replicas = args['minNumReplicas'] | ||
@max_num_replicas = args['maxNumReplicas'] | ||
@cool_down_period_sec = args['coolDownPeriodSec'] | ||
@cpu_utilization = GoogleInSpec::Compute::Property::AutoscalerCpuutilization.new(args['cpuUtilization']) | ||
@custom_metric_utilizations = GoogleInSpec::Compute::Property::AutoscalerCustommetricutilizationsArray.parse(args['customMetricUtilizations']) | ||
@load_balancing_utilization = GoogleInSpec::Compute::Property::AutoscalerLoadbalancingutilization.new(args['loadBalancingUtilization']) | ||
end | ||
end | ||
end | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
libraries/google/compute/property/autoscaler_cpu_utilization.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: false | ||
|
||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# This file is automatically generated by Magic Modules and manual | ||
# changes will be clobbered when the file is regenerated. | ||
# | ||
# Please read more about how to change this file in README.md and | ||
# CONTRIBUTING.md located at the root of this package. | ||
# | ||
# ---------------------------------------------------------------------------- | ||
module GoogleInSpec | ||
module Compute | ||
module Property | ||
class AutoscalerCpuutilization | ||
attr_reader :utilization_target | ||
|
||
def initialize(args = nil) | ||
return if args.nil? | ||
@utilization_target = args['utilizationTarget'] | ||
end | ||
end | ||
end | ||
end | ||
end |
43 changes: 43 additions & 0 deletions
43
libraries/google/compute/property/autoscaler_custom_metric_utilizations.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: false | ||
|
||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# This file is automatically generated by Magic Modules and manual | ||
# changes will be clobbered when the file is regenerated. | ||
# | ||
# Please read more about how to change this file in README.md and | ||
# CONTRIBUTING.md located at the root of this package. | ||
# | ||
# ---------------------------------------------------------------------------- | ||
module GoogleInSpec | ||
module Compute | ||
module Property | ||
class AutoscalerCustommetricutilizations | ||
attr_reader :metric | ||
|
||
attr_reader :utilization_target | ||
|
||
attr_reader :utilization_target_type | ||
|
||
def initialize(args = nil) | ||
return if args.nil? | ||
@metric = args['metric'] | ||
@utilization_target = args['utilizationTarget'] | ||
@utilization_target_type = args['utilizationTargetType'] | ||
end | ||
end | ||
|
||
class AutoscalerCustommetricutilizationsArray | ||
def self.parse(value) | ||
return if value.nil? | ||
return AutoscalerCustommetricutilizations.new(value) unless value.is_a?(::Array) | ||
value.map { |v| AutoscalerCustommetricutilizations.new(v) } | ||
end | ||
end | ||
end | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
libraries/google/compute/property/autoscaler_load_balancing_utilization.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: false | ||
|
||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# This file is automatically generated by Magic Modules and manual | ||
# changes will be clobbered when the file is regenerated. | ||
# | ||
# Please read more about how to change this file in README.md and | ||
# CONTRIBUTING.md located at the root of this package. | ||
# | ||
# ---------------------------------------------------------------------------- | ||
module GoogleInSpec | ||
module Compute | ||
module Property | ||
class AutoscalerLoadbalancingutilization | ||
attr_reader :utilization_target | ||
|
||
def initialize(args = nil) | ||
return if args.nil? | ||
@utilization_target = args['utilizationTarget'] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# frozen_string_literal: false | ||
|
||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# This file is automatically generated by Magic Modules and manual | ||
# changes will be clobbered when the file is regenerated. | ||
# | ||
# Please read more about how to change this file in README.md and | ||
# CONTRIBUTING.md located at the root of this package. | ||
# | ||
# ---------------------------------------------------------------------------- | ||
require 'gcp_backend' | ||
require 'google/compute/property/autoscaler_autoscaling_policy' | ||
require 'google/compute/property/autoscaler_cpu_utilization' | ||
require 'google/compute/property/autoscaler_custom_metric_utilizations' | ||
require 'google/compute/property/autoscaler_load_balancing_utilization' | ||
|
||
# A provider to manage Google Compute Engine resources. | ||
class Autoscaler < GcpResourceBase | ||
name 'google_compute_autoscaler' | ||
desc 'Autoscaler' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :id | ||
attr_reader :creation_timestamp | ||
attr_reader :name | ||
attr_reader :description | ||
attr_reader :autoscaling_policy | ||
attr_reader :target | ||
attr_reader :zone | ||
def base | ||
'https://www.googleapis.com/compute/v1/' | ||
end | ||
|
||
def url | ||
'projects/{{project}}/zones/{{zone}}/autoscalers/{{name}}' | ||
end | ||
|
||
def initialize(params) | ||
super(params.merge({ use_http_transport: true })) | ||
@fetched = @connection.fetch(base, url, params) | ||
parse unless @fetched.nil? | ||
end | ||
|
||
def parse | ||
@id = @fetched['id'] | ||
@creation_timestamp = parse_time_string(@fetched['creationTimestamp']) | ||
@name = @fetched['name'] | ||
@description = @fetched['description'] | ||
@autoscaling_policy = GoogleInSpec::Compute::Property::AutoscalerAutoscalingpolicy.new(@fetched['autoscalingPolicy']) | ||
@target = @fetched['target'] | ||
@zone = @fetched['zone'] | ||
end | ||
|
||
# Handles parsing RFC3339 time string | ||
def parse_time_string(time_string) | ||
time_string ? Time.parse(time_string) : nil | ||
end | ||
|
||
def exists? | ||
!@fetched.nil? | ||
end | ||
end |
Oops, something went wrong.