-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from modular-magician/codegen-pr-1246
Add instance group manager resource to InSpec
- Loading branch information
Showing
10 changed files
with
453 additions
and
0 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,74 @@ | ||
--- | ||
title: About the InstanceGroupManager resource | ||
platform: gcp | ||
--- | ||
|
||
|
||
## Syntax | ||
A `google_compute_instance_group_manager` is used to test a Google InstanceGroupManager resource | ||
|
||
## Examples | ||
``` | ||
describe google_compute_instance_group_manager(project: 'chef-gcp-inspec', zone: 'zone', name: 'inspec-gcp-igm') do | ||
it { should exist } | ||
its('base_instance_name') { should eq 'igm' } | ||
its('named_ports.count') { should cmp 1 } | ||
its('named_ports.first.name') { should eq 'port' } | ||
its('named_ports.first.port') { should eq '80' } | ||
its('instance_template') { should match 'gcp-managed-group-name' } | ||
end | ||
describe google_compute_instance_group_manager(project: 'chef-gcp-inspec', zone: 'zone', name: 'nonexistent') do | ||
it { should_not exist } | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_compute_instance_group_manager` resource: | ||
|
||
* `base_instance_name`: The base instance name to use for instances in this group. The value must be 1-58 characters long. Instances are named by appending a hyphen and a random four-character string to the base instance name. The base instance name must comply with RFC1035. | ||
|
||
* `creation_timestamp`: The creation timestamp for this managed instance group in RFC3339 text format. | ||
|
||
* `current_actions`: The list of instance actions and the number of instances in this managed instance group that are scheduled for each of those actions. | ||
|
||
* `abandoning`: The total number of instances in the managed instance group that are scheduled to be abandoned. Abandoning an instance removes it from the managed instance group without deleting it. | ||
|
||
* `creating`: The number of instances in the managed instance group that are scheduled to be created or are currently being created. If the group fails to create any of these instances, it tries again until it creates the instance successfully. If you have disabled creation retries, this field will not be populated; instead, the creatingWithoutRetries field will be populated. | ||
|
||
* `creatingWithoutRetries`: The number of instances that the managed instance group will attempt to create. The group attempts to create each instance only once. If the group fails to create any of these instances, it decreases the group's targetSize value accordingly. | ||
|
||
* `deleting`: The number of instances in the managed instance group that are scheduled to be deleted or are currently being deleted. | ||
|
||
* `none`: The number of instances in the managed instance group that are running and have no scheduled actions. | ||
|
||
* `recreating`: The number of instances in the managed instance group that are scheduled to be recreated or are currently being being recreated. Recreating an instance deletes the existing root persistent disk and creates a new disk from the image that is defined in the instance template. | ||
|
||
* `refreshing`: The number of instances in the managed instance group that are being reconfigured with properties that do not require a restart or a recreate action. For example, setting or removing target pools for the instance. | ||
|
||
* `restarting`: The number of instances in the managed instance group that are scheduled to be restarted or are currently being restarted. | ||
|
||
* `description`: An optional description of this resource. Provide this property when you create the resource. | ||
|
||
* `id`: A unique identifier for this resource | ||
|
||
* `instance_group`: The instance group being managed | ||
|
||
* `instance_template`: The instance template that is specified for this managed instance group. The group uses this template to create all new instances in the managed instance group. | ||
|
||
* `name`: The name of the managed instance group. The name must be 1-63 characters long, and comply with RFC1035. | ||
|
||
* `named_ports`: Named ports configured for the Instance Groups complementary to this Instance Group Manager. | ||
|
||
* `name`: The name for this named port. The name must be 1-63 characters long, and comply with RFC1035. | ||
|
||
* `port`: The port number, which can be a value between 1 and 65535. | ||
|
||
* `region`: The region this managed instance group resides (for regional resources). | ||
|
||
* `target_pools`: TargetPool resources to which instances in the instanceGroup field are added. The target pools automatically apply to all of the instances in the managed instance group. | ||
|
||
* `target_size`: The target number of running instances for this managed instance group. Deleting or abandoning instances reduces this number. Resizing the group changes this number. | ||
|
||
* `zone`: The zone the managed 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,38 @@ | ||
--- | ||
title: About the InstanceGroupManager resource | ||
platform: gcp | ||
--- | ||
|
||
|
||
## Syntax | ||
A `google_compute_instance_group_managers` is used to test a Google InstanceGroupManager resource | ||
|
||
## Examples | ||
``` | ||
describe google_compute_instance_group_managers(project: 'chef-gcp-inspec', zone: 'zone') do | ||
its('base_instance_names') { should include 'igm' } | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_compute_instance_group_managers` resource: | ||
|
||
See [google_compute_instance_group_manager.md](google_compute_instance_group_manager.md) for more detailed information | ||
* `base_instance_names`: an array of `google_compute_instance_group_manager` base_instance_name | ||
* `creation_timestamps`: an array of `google_compute_instance_group_manager` creation_timestamp | ||
* `current_actions`: an array of `google_compute_instance_group_manager` current_actions | ||
* `descriptions`: an array of `google_compute_instance_group_manager` description | ||
* `ids`: an array of `google_compute_instance_group_manager` id | ||
* `instance_groups`: an array of `google_compute_instance_group_manager` instance_group | ||
* `instance_templates`: an array of `google_compute_instance_group_manager` instance_template | ||
* `names`: an array of `google_compute_instance_group_manager` name | ||
* `named_ports`: an array of `google_compute_instance_group_manager` named_ports | ||
* `regions`: an array of `google_compute_instance_group_manager` region | ||
* `target_pools`: an array of `google_compute_instance_group_manager` target_pools | ||
* `target_sizes`: an array of `google_compute_instance_group_manager` target_size | ||
* `zones`: an array of `google_compute_instance_group_manager` 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. |
50 changes: 50 additions & 0 deletions
50
libraries/google/compute/property/instancegroupmanager_current_actions.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,50 @@ | ||
# 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 InstanceGroupManagerCurrentactions | ||
attr_reader :abandoning | ||
|
||
attr_reader :creating | ||
|
||
attr_reader :creating_without_retries | ||
|
||
attr_reader :deleting | ||
|
||
attr_reader :none | ||
|
||
attr_reader :recreating | ||
|
||
attr_reader :refreshing | ||
|
||
attr_reader :restarting | ||
|
||
def initialize(args = nil) | ||
return if args.nil? | ||
@abandoning = args['abandoning'] | ||
@creating = args['creating'] | ||
@creating_without_retries = args['creatingWithoutRetries'] | ||
@deleting = args['deleting'] | ||
@none = args['none'] | ||
@recreating = args['recreating'] | ||
@refreshing = args['refreshing'] | ||
@restarting = args['restarting'] | ||
end | ||
end | ||
end | ||
end | ||
end |
40 changes: 40 additions & 0 deletions
40
libraries/google/compute/property/instancegroupmanager_named_ports.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,40 @@ | ||
# 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 InstanceGroupManagerNamedports | ||
attr_reader :name | ||
|
||
attr_reader :port | ||
|
||
def initialize(args = nil) | ||
return if args.nil? | ||
@name = args['name'] | ||
@port = args['port'] | ||
end | ||
end | ||
|
||
class InstanceGroupManagerNamedportsArray | ||
def self.parse(value) | ||
return if value.nil? | ||
return InstanceGroupManagerNamedports.new(value) unless value.is_a?(::Array) | ||
value.map { |v| InstanceGroupManagerNamedports.new(v) } | ||
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,77 @@ | ||
# 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/instancegroupmanager_current_actions' | ||
require 'google/compute/property/instancegroupmanager_named_ports' | ||
|
||
# A provider to manage Google Compute Engine resources. | ||
class InstanceGroupManager < GcpResourceBase | ||
name 'google_compute_instance_group_manager' | ||
desc 'InstanceGroupManager' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :base_instance_name | ||
attr_reader :creation_timestamp | ||
attr_reader :current_actions | ||
attr_reader :description | ||
attr_reader :id | ||
attr_reader :instance_group | ||
attr_reader :instance_template | ||
attr_reader :name | ||
attr_reader :named_ports | ||
attr_reader :region | ||
attr_reader :target_pools | ||
attr_reader :target_size | ||
attr_reader :zone | ||
def base | ||
'https://www.googleapis.com/compute/v1/' | ||
end | ||
|
||
def url | ||
'projects/{{project}}/zones/{{zone}}/instanceGroupManagers/{{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 | ||
@base_instance_name = @fetched['baseInstanceName'] | ||
@creation_timestamp = parse_time_string(@fetched['creationTimestamp']) | ||
@current_actions = GoogleInSpec::Compute::Property::InstanceGroupManagerCurrentactions.new(@fetched['currentActions']) | ||
@description = @fetched['description'] | ||
@id = @fetched['id'] | ||
@instance_group = @fetched['instanceGroup'] | ||
@instance_template = @fetched['instanceTemplate'] | ||
@name = @fetched['name'] | ||
@named_ports = GoogleInSpec::Compute::Property::InstanceGroupManagerNamedportsArray.parse(@fetched['namedPorts']) | ||
@region = @fetched['region'] | ||
@target_pools = @fetched['targetPools'] | ||
@target_size = @fetched['targetSize'] | ||
@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 |
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,74 @@ | ||
# frozen_string_literal: false | ||
|
||
# ---------------------------------------------------------------------------- | ||
# | ||
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** | ||
# | ||
# ---------------------------------------------------------------------------- | ||
# | ||
# This file is automatically generated by Magic Modules and manual | ||
# changes will be clobbered when the file is regenerated. | ||
# | ||
# Please read more about how to change this file in README.md and | ||
# CONTRIBUTING.md located at the root of this package. | ||
# | ||
# ---------------------------------------------------------------------------- | ||
require 'gcp_backend' | ||
class InstanceGroupManagers < GcpResourceBase | ||
name 'google_compute_instance_group_managers' | ||
desc 'InstanceGroupManager plural resource' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :table | ||
|
||
filter_table_config = FilterTable.create | ||
|
||
filter_table_config.add(:base_instance_names, field: :baseInstanceName) | ||
filter_table_config.add(:creation_timestamps, field: :creationTimestamp) | ||
filter_table_config.add(:current_actions, field: :currentActions) | ||
filter_table_config.add(:descriptions, field: :description) | ||
filter_table_config.add(:ids, field: :id) | ||
filter_table_config.add(:instance_groups, field: :instanceGroup) | ||
filter_table_config.add(:instance_templates, field: :instanceTemplate) | ||
filter_table_config.add(:names, field: :name) | ||
filter_table_config.add(:named_ports, field: :namedPorts) | ||
filter_table_config.add(:regions, field: :region) | ||
filter_table_config.add(:target_pools, field: :targetPools) | ||
filter_table_config.add(:target_sizes, field: :targetSize) | ||
filter_table_config.add(:zones, field: :zone) | ||
|
||
filter_table_config.connect(self, :table) | ||
|
||
def base | ||
'https://www.googleapis.com/compute/v1/' | ||
end | ||
|
||
def url | ||
'projects/{{project}}/zones/{{zone}}/instanceGroupManagers' | ||
end | ||
|
||
def initialize(params = {}) | ||
super(params.merge({ use_http_transport: true })) | ||
@params = params | ||
@table = fetch_wrapped_resource('items') | ||
end | ||
|
||
def fetch_wrapped_resource(wrap_path) | ||
# fetch_resource returns an array of responses (to handle pagination) | ||
result = @connection.fetch_all(base, url, @params) | ||
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_pair { |k, v| hash_with_symbols[k.to_sym] = v } | ||
converted.push(hash_with_symbols) | ||
end | ||
end | ||
|
||
converted | ||
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
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
Oops, something went wrong.