diff --git a/docs/resources/google_compute_backend_service.md b/docs/resources/google_compute_backend_service.md index 15bf8789c..a0cf77f12 100644 --- a/docs/resources/google_compute_backend_service.md +++ b/docs/resources/google_compute_backend_service.md @@ -79,7 +79,7 @@ Properties that can be accessed from the `google_compute_backend_service` resour * `oauth2_client_secret_sha256`: OAuth2 Client Secret SHA-256 for IAP - * `load_balancing_scheme`: Indicates whether the backend service will be used with internal or external load balancing. A backend service created for one type of load balancing cannot be used with the other. + * `load_balancing_scheme`: Indicates whether the backend service will be used with internal or external load balancing. A backend service created for one type of load balancing cannot be used with the other. One of `INTERNAL` or `EXTERNAL`. Defaults to `EXTERNAL`. * `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. diff --git a/docs/resources/google_compute_global_address.md b/docs/resources/google_compute_global_address.md index 824cc9a7d..96d3f496b 100644 --- a/docs/resources/google_compute_global_address.md +++ b/docs/resources/google_compute_global_address.md @@ -25,13 +25,13 @@ Properties that can be accessed from the `google_compute_global_address` resourc * `creation_timestamp`: Creation timestamp in RFC3339 text format. - * `description`: An optional description of this resource. Provide this property when you create the resource. + * `description`: An optional description of this resource. * `id`: The unique identifier for the resource. This identifier is defined by the server. * `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. - * `ip_version`: The IP Version that will be used by this address. Valid options are IPV4 or IPV6. The default value is IPV4. + * `ip_version`: The IP Version that will be used by this address. Valid options are `IPV4` or `IPV6`. The default value is `IPV4`. * `region`: A reference to the region where the regional address resides. diff --git a/docs/resources/google_compute_instance_template.md b/docs/resources/google_compute_instance_template.md index c110c1ff8..9b9371389 100644 --- a/docs/resources/google_compute_instance_template.md +++ b/docs/resources/google_compute_instance_template.md @@ -12,7 +12,7 @@ describe google_compute_instance_template(project: 'chef-gcp-inspec', name: 'ins it { should exist } its('description') { should eq 'A description of the instance template' } its('properties.description') { should eq 'A description of the instance itself' } - its('properties.machine_type') { should eq 'n1-standard-1' } + its('properties.machine_type') { should eq 'f1-micro' } its('properties.tags.items') { should include 'foo' } its('properties.disks.count') { should eq 1 } its('properties.disks.first.auto_delete') { should eq 'true' } diff --git a/docs/resources/google_compute_subnetwork_iam_policy.md b/docs/resources/google_compute_subnetwork_iam_policy.md new file mode 100644 index 000000000..21b421837 --- /dev/null +++ b/docs/resources/google_compute_subnetwork_iam_policy.md @@ -0,0 +1,39 @@ +--- +title: About the google_compute_subnetwork_iam_policy resource +platform: gcp +--- + +## Syntax +A `google_compute_subnetwork_iam_policy` is used to test a Google Subnetwork Iam Policy resource + +## Examples +``` +describe google_compute_subnetwork_iam_policy(project: "project", region: "region", name: "name") do + it { should exist } +end + +describe google_compute_subnetwork_iam_policy(project: "project", region: "region", name: "name").bindings do |binding| + its('role') { should_not eq 'roles/owner' } +end +``` + +## Properties +Properties that can be accessed from the `google_compute_subnetwork_iam_policy` resource: + + * `bindings`: Associates a list of members to a role. + + * `role`: Role that is assigned to members. For example, roles/viewer, roles/editor, or roles/owner. + + * `members`: Specifies the identities requesting access for a Cloud Platform resource. + + * `audit_configs`: Specifies cloud audit logging configuration for this policy. + + * `service`: Specifies a service that will be enabled for audit logging. For example, `storage.googleapis.com`, `cloudsql.googleapis.com`. `allServices` is a special value that covers all services. + + * `audit_log_configs`: The configuration for logging of each type of permission. + + + +## 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_container_regional_node_pool.md b/docs/resources/google_container_regional_node_pool.md new file mode 100644 index 000000000..d8a100f72 --- /dev/null +++ b/docs/resources/google_container_regional_node_pool.md @@ -0,0 +1,76 @@ +--- +title: About the google_container_regional_node_pool resource +platform: gcp +--- + +## Syntax +A `google_container_regional_node_pool` is used to test a Google RegionalNodePool resource + +## Examples +``` +describe google_container_regional_node_pool(project: 'chef-gcp-inspec', location: 'europe-west2', cluster: 'inspec-gcp-regional-cluster', name: 'inspec-gcp-regional-node-pool') do + it { should exist } + its('initial_node_count') { should eq '1'} +end + +describe google_container_regional_node_pool(project: 'chef-gcp-inspec', location: 'europe-west2', cluster: 'inspec-gcp-regional-cluster', name: 'nonexistent') do + it { should_not exist } +end +``` + +## Properties +Properties that can be accessed from the `google_container_regional_node_pool` resource: + + * `name`: The name of the node pool. + + * `config`: The node configuration of the pool. + + * `machine_type`: The name of a Google Compute Engine machine type (e.g. n1-standard-1). If unspecified, the default machine type is n1-standard-1. + + * `disk_size_gb`: Size of the disk attached to each node, specified in GB. The smallest allowed disk size is 10GB. If unspecified, the default disk size is 100GB. + + * `oauth_scopes`: The set of Google API scopes to be made available on all of the node VMs under the "default" service account. The following scopes are recommended, but not required, and by default are not included: https://www.googleapis.com/auth/compute is required for mounting persistent storage on your nodes. https://www.googleapis.com/auth/devstorage.read_only is required for communicating with gcr.io (the Google Container Registry). If unspecified, no scopes are added, unless Cloud Logging or Cloud Monitoring are enabled, in which case their required scopes will be added. + + * `service_account`: The Google Cloud Platform Service Account to be used by the node VMs. If no Service Account is specified, the "default" service account is used. + + * `metadata`: The metadata key/value pairs assigned to instances in the cluster. Keys must conform to the regexp [a-zA-Z0-9-_]+ and be less than 128 bytes in length. These are reflected as part of a URL in the metadata server. Additionally, to avoid ambiguity, keys must not conflict with any other metadata keys for the project or be one of the four reserved keys: "instance-template", "kube-env", "startup-script", and "user-data" Values are free-form strings, and only have meaning as interpreted by the image running in the instance. The only restriction placed on them is that each value's size must be less than or equal to 32 KB. The total size of all keys and values must be less than 512 KB. An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }. + + * `image_type`: The image type to use for this node. Note that for a given image type, the latest version of it will be used. + + * `labels`: The map of Kubernetes labels (key/value pairs) to be applied to each node. These will added in addition to any default label(s) that Kubernetes may apply to the node. In case of conflict in label keys, the applied set may differ depending on the Kubernetes version -- it's best to assume the behavior is undefined and conflicts should be avoided. For more information, including usage and the valid values, see: http://kubernetes.io/v1.1/docs/user-guide/labels.html An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }. + + * `local_ssd_count`: The number of local SSD disks to be attached to the node. The limit for this value is dependant upon the maximum number of disks available on a machine per zone. See: https://cloud.google.com/compute/docs/disks/local-ssd#local_ssd_limits for more information. + + * `tags`: The list of instance tags applied to all nodes. Tags are used to identify valid sources or targets for network firewalls and are specified by the client during cluster or node pool creation. Each tag within the list must comply with RFC1035. + + * `preemptible`: Whether the nodes are created as preemptible VM instances. See: https://cloud.google.com/compute/docs/instances/preemptible for more information about preemptible VM instances. + + * `initial_node_count`: The initial node count for the pool. You must ensure that your Compute Engine resource quota is sufficient for this number of instances. You must also have available firewall and routes quota. + + * `version`: The version of the Kubernetes of this node. + + * `autoscaling`: Autoscaler configuration for this NodePool. Autoscaler is enabled only if a valid configuration is present. + + * `enabled`: Is autoscaling enabled for this node pool. + + * `min_node_count`: Minimum number of nodes in the NodePool. Must be >= 1 and <= maxNodeCount. + + * `max_node_count`: Maximum number of nodes in the NodePool. Must be >= minNodeCount. There has to enough quota to scale up the cluster. + + * `management`: Management configuration for this NodePool. + + * `auto_upgrade`: A flag that specifies whether node auto-upgrade is enabled for the node pool. If enabled, node auto-upgrade helps keep the nodes in your node pool up to date with the latest release version of Kubernetes. + + * `auto_repair`: A flag that specifies whether the node auto-repair is enabled for the node pool. If enabled, the nodes in this node pool will be monitored and, if they fail health checks too many times, an automatic repair action will be triggered. + + * `upgrade_options`: Specifies the Auto Upgrade knobs for the node pool. + + * `cluster`: The cluster this node pool belongs to. + + * `location`: The location where the node pool is deployed + + + +## GCP Permissions + +Ensure the [Kubernetes Engine API](https://console.cloud.google.com/apis/library/container.googleapis.com/) is enabled for the current project. diff --git a/docs/resources/google_container_regional_node_pools.md b/docs/resources/google_container_regional_node_pools.md new file mode 100644 index 000000000..c08eeb067 --- /dev/null +++ b/docs/resources/google_container_regional_node_pools.md @@ -0,0 +1,35 @@ +--- +title: About the google_container_regional_node_pools resource +platform: gcp +--- + +## Syntax +A `google_container_regional_node_pools` is used to test a Google RegionalNodePool resource + +## Examples +``` +describe google_container_regional_node_pools(project: 'chef-gcp-inspec', location: 'europe-west2', cluster: 'inspec-gcp-regional-cluster') do + its('initial_node_counts') { should include '1'} +end +``` + +## Properties +Properties that can be accessed from the `google_container_regional_node_pools` resource: + +See [google_container_regional_node_pool.md](google_container_regional_node_pool.md) for more detailed information + * `names`: an array of `google_container_regional_node_pool` name + * `configs`: an array of `google_container_regional_node_pool` config + * `initial_node_counts`: an array of `google_container_regional_node_pool` initial_node_count + * `versions`: an array of `google_container_regional_node_pool` version + * `autoscalings`: an array of `google_container_regional_node_pool` autoscaling + * `managements`: an array of `google_container_regional_node_pool` management + * `clusters`: an array of `google_container_regional_node_pool` cluster + * `locations`: an array of `google_container_regional_node_pool` location + +## 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 [Kubernetes Engine API](https://console.cloud.google.com/apis/library/container.googleapis.com/) is enabled for the current project. diff --git a/libraries/google/container/property/regionalnodepool_autoscaling.rb b/libraries/google/container/property/regionalnodepool_autoscaling.rb new file mode 100644 index 000000000..78a74bf97 --- /dev/null +++ b/libraries/google/container/property/regionalnodepool_autoscaling.rb @@ -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 Container + module Property + class RegionalNodePoolAutoscaling + attr_reader :enabled + + attr_reader :min_node_count + + attr_reader :max_node_count + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @enabled = args['enabled'] + @min_node_count = args['minNodeCount'] + @max_node_count = args['maxNodeCount'] + end + + def to_s + "#{@parent_identifier} RegionalNodePoolAutoscaling" + end + end + end + end +end diff --git a/libraries/google/container/property/regionalnodepool_config.rb b/libraries/google/container/property/regionalnodepool_config.rb new file mode 100644 index 000000000..c56f9cfd1 --- /dev/null +++ b/libraries/google/container/property/regionalnodepool_config.rb @@ -0,0 +1,61 @@ +# 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 Container + module Property + class RegionalNodePoolConfig + attr_reader :machine_type + + attr_reader :disk_size_gb + + attr_reader :oauth_scopes + + attr_reader :service_account + + attr_reader :metadata + + attr_reader :image_type + + attr_reader :labels + + attr_reader :local_ssd_count + + attr_reader :tags + + attr_reader :preemptible + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @machine_type = args['machineType'] + @disk_size_gb = args['diskSizeGb'] + @oauth_scopes = args['oauthScopes'] + @service_account = args['serviceAccount'] + @metadata = args['metadata'] + @image_type = args['imageType'] + @labels = args['labels'] + @local_ssd_count = args['localSsdCount'] + @tags = args['tags'] + @preemptible = args['preemptible'] + end + + def to_s + "#{@parent_identifier} RegionalNodePoolConfig" + end + end + end + end +end diff --git a/libraries/google/container/property/regionalnodepool_management.rb b/libraries/google/container/property/regionalnodepool_management.rb new file mode 100644 index 000000000..790674859 --- /dev/null +++ b/libraries/google/container/property/regionalnodepool_management.rb @@ -0,0 +1,41 @@ +# 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/container/property/regionalnodepool_management_upgrade_options' +module GoogleInSpec + module Container + module Property + class RegionalNodePoolManagement + attr_reader :auto_upgrade + + attr_reader :auto_repair + + attr_reader :upgrade_options + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @auto_upgrade = args['autoUpgrade'] + @auto_repair = args['autoRepair'] + @upgrade_options = GoogleInSpec::Container::Property::RegionalNodePoolManagementUpgradeOptions.new(args['upgradeOptions'], to_s) + end + + def to_s + "#{@parent_identifier} RegionalNodePoolManagement" + end + end + end + end +end diff --git a/libraries/google/container/property/regionalnodepool_management_upgrade_options.rb b/libraries/google/container/property/regionalnodepool_management_upgrade_options.rb new file mode 100644 index 000000000..9628a3dbe --- /dev/null +++ b/libraries/google/container/property/regionalnodepool_management_upgrade_options.rb @@ -0,0 +1,37 @@ +# 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 Container + module Property + class RegionalNodePoolManagementUpgradeOptions + attr_reader :auto_upgrade_start_time + + attr_reader :description + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @auto_upgrade_start_time = parse_time_string(args['autoUpgradeStartTime']) + @description = args['description'] + end + + def to_s + "#{@parent_identifier} RegionalNodePoolManagementUpgradeOptions" + end + end + end + end +end diff --git a/libraries/google/iam/property/iam_policy_audit_configs.rb b/libraries/google/iam/property/iam_policy_audit_configs.rb new file mode 100644 index 000000000..e960b9b1f --- /dev/null +++ b/libraries/google/iam/property/iam_policy_audit_configs.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: false + +# Copyright 2017 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'google/iam/property/iam_policy_audit_configs_audit_log_configs' +module GoogleInSpec + module Iam + module Property + class IamPolicyAuditConfigs + attr_reader :service + + attr_reader :audit_log_configs + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @service = args['service'] + @audit_log_configs = GoogleInSpec::Iam::Property::IamPolicyAuditConfigsAuditLogConfigsArray.parse(args['auditLogConfigs'], to_s) + end + + def to_s + "#{@parent_identifier} IamPolicyAuditConfigs" + end + end + + class IamPolicyAuditConfigsArray + def self.parse(value, parent_identifier) + return if value.nil? + return IamPolicyAuditConfigs.new(value, parent_identifier) unless value.is_a?(::Array) + value.map { |v| IamPolicyAuditConfigs.new(v, parent_identifier) } + end + end + end + end +end diff --git a/libraries/google/iam/property/iam_policy_audit_configs_audit_log_configs.rb b/libraries/google/iam/property/iam_policy_audit_configs_audit_log_configs.rb new file mode 100644 index 000000000..371e49b38 --- /dev/null +++ b/libraries/google/iam/property/iam_policy_audit_configs_audit_log_configs.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: false + +# Copyright 2017 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module GoogleInSpec + module Iam + module Property + class IamPolicyAuditConfigsAuditLogConfigs + attr_reader :log_type + + attr_reader :exempted_members + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @log_type = args['logType'] + @exempted_members = args['exemptedMembers'] + end + + def to_s + "#{@parent_identifier} IamPolicyAuditConfigsAuditLogConfigs" + end + end + + class IamPolicyAuditConfigsAuditLogConfigsArray + def self.parse(value, parent_identifier) + return if value.nil? + return IamPolicyAuditConfigsAuditLogConfigs.new(value, parent_identifier) unless value.is_a?(::Array) + value.map { |v| IamPolicyAuditConfigsAuditLogConfigs.new(v, parent_identifier) } + end + end + end + end +end diff --git a/libraries/google/iam/property/iam_policy_bindings.rb b/libraries/google/iam/property/iam_policy_bindings.rb new file mode 100644 index 000000000..c2dc42449 --- /dev/null +++ b/libraries/google/iam/property/iam_policy_bindings.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: false + +# Copyright 2017 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +module GoogleInSpec + module Iam + module Property + class IamPolicyBindings + attr_reader :role + + attr_reader :members + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @role = args['role'] + @members = args['members'] + end + + def to_s + "#{@parent_identifier} IamPolicyBindings" + end + end + + class IamPolicyBindingsArray + def self.parse(value, parent_identifier) + return if value.nil? + return IamPolicyBindings.new(value, parent_identifier) unless value.is_a?(::Array) + value.map { |v| IamPolicyBindings.new(v, parent_identifier) } + end + end + end + end +end diff --git a/libraries/google_compute_subnetwork_iam_policy.rb b/libraries/google_compute_subnetwork_iam_policy.rb new file mode 100644 index 000000000..cfdaf8443 --- /dev/null +++ b/libraries/google_compute_subnetwork_iam_policy.rb @@ -0,0 +1,59 @@ +# 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/iam/property/iam_policy_audit_configs' +require 'google/iam/property/iam_policy_bindings' + +# A provider to manage Compute Engine IAM Policy resources. +class SubnetworkIamPolicy < GcpResourceBase + name 'google_compute_subnetwork_iam_policy' + desc 'Subnetwork Iam Policy' + supports platform: 'gcp' + + attr_reader :params + attr_reader :bindings + attr_reader :audit_configs + + def initialize(params) + super(params.merge({ use_http_transport: true })) + @params = params + @fetched = @connection.fetch(product_url, resource_base_url, params) + parse unless @fetched.nil? + end + + def parse + @bindings = GoogleInSpec::Iam::Property::IamPolicyBindingsArray.parse(@fetched['bindings'], to_s) + @audit_configs = GoogleInSpec::Iam::Property::IamPolicyAuditConfigsArray.parse(@fetched['auditConfigs'], to_s) + end + + def exists? + !@fetched.nil? + end + + def to_s + "Subnetwork IamPolicy #{@params[:name]}" + end + + private + + def product_url + 'https://www.googleapis.com/compute/v1/' + end + + def resource_base_url + 'projects/{{project}}/regions/{{region}}/subnetworks/{{name}}/getIamPolicy' + end +end diff --git a/libraries/google_container_regional_node_pool.rb b/libraries/google_container_regional_node_pool.rb new file mode 100644 index 000000000..5a5928818 --- /dev/null +++ b/libraries/google_container_regional_node_pool.rb @@ -0,0 +1,78 @@ +# 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/container/property/regionalnodepool_autoscaling' +require 'google/container/property/regionalnodepool_config' +require 'google/container/property/regionalnodepool_management' +require 'google/container/property/regionalnodepool_management_upgrade_options' + +# A provider to manage Google Kubernetes Engine resources. +class RegionalNodePool < GcpResourceBase + name 'google_container_regional_node_pool' + desc 'RegionalNodePool' + supports platform: 'gcp' + + attr_reader :params + attr_reader :name + attr_reader :config + attr_reader :initial_node_count + attr_reader :version + attr_reader :autoscaling + attr_reader :management + attr_reader :cluster + attr_reader :location + + def initialize(params) + super(params.merge({ use_http_transport: true })) + @params = params + @fetched = @connection.fetch(product_url, resource_base_url, params) + parse unless @fetched.nil? + end + + def parse + @name = @fetched['name'] + @config = GoogleInSpec::Container::Property::RegionalNodePoolConfig.new(@fetched['config'], to_s) + @initial_node_count = @fetched['initialNodeCount'] + @version = @fetched['version'] + @autoscaling = GoogleInSpec::Container::Property::RegionalNodePoolAutoscaling.new(@fetched['autoscaling'], to_s) + @management = GoogleInSpec::Container::Property::RegionalNodePoolManagement.new(@fetched['management'], to_s) + @cluster = @fetched['cluster'] + @location = @fetched['location'] + end + + # Handles parsing RFC3339 time string + def parse_time_string(time_string) + time_string ? Time.parse(time_string) : nil + end + + def exists? + !@fetched.nil? + end + + def to_s + "RegionalNodePool #{@params[:name]}" + end + + private + + def product_url + 'https://container.googleapis.com/v1/' + end + + def resource_base_url + 'projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/nodePools/{{name}}' + end +end diff --git a/libraries/google_container_regional_node_pools.rb b/libraries/google_container_regional_node_pools.rb new file mode 100644 index 000000000..4bc01130b --- /dev/null +++ b/libraries/google_container_regional_node_pools.rb @@ -0,0 +1,98 @@ +# 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 RegionalNodePools < GcpResourceBase + name 'google_container_regional_node_pools' + desc 'RegionalNodePool plural resource' + supports platform: 'gcp' + + attr_reader :table + + filter_table_config = FilterTable.create + + filter_table_config.add(:names, field: :name) + filter_table_config.add(:configs, field: :config) + filter_table_config.add(:initial_node_counts, field: :initial_node_count) + filter_table_config.add(:versions, field: :version) + filter_table_config.add(:autoscalings, field: :autoscaling) + filter_table_config.add(:managements, field: :management) + filter_table_config.add(:clusters, field: :cluster) + filter_table_config.add(:locations, field: :location) + + filter_table_config.connect(self, :table) + + def initialize(params = {}) + super(params.merge({ use_http_transport: true })) + @params = params + @table = fetch_wrapped_resource('nodePools') + 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) + 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 + { + 'name' => ->(obj) { return :name, obj['name'] }, + 'config' => ->(obj) { return :config, GoogleInSpec::Container::Property::RegionalNodePoolConfig.new(obj['config'], to_s) }, + 'initialNodeCount' => ->(obj) { return :initial_node_count, obj['initialNodeCount'] }, + 'version' => ->(obj) { return :version, obj['version'] }, + 'autoscaling' => ->(obj) { return :autoscaling, GoogleInSpec::Container::Property::RegionalNodePoolAutoscaling.new(obj['autoscaling'], to_s) }, + 'management' => ->(obj) { return :management, GoogleInSpec::Container::Property::RegionalNodePoolManagement.new(obj['management'], to_s) }, + 'cluster' => ->(obj) { return :cluster, obj['cluster'] }, + 'location' => ->(obj) { return :location, obj['location'] }, + } + end + + # Handles parsing RFC3339 time string + def parse_time_string(time_string) + time_string ? Time.parse(time_string) : nil + end + + private + + def product_url + 'https://container.googleapis.com/v1/' + end + + def resource_base_url + 'projects/{{project}}/locations/{{location}}/clusters/{{cluster}}/nodePools' + end +end diff --git a/test/integration/build/gcp-mm.tf b/test/integration/build/gcp-mm.tf index 4114f24b2..81f437f55 100644 --- a/test/integration/build/gcp-mm.tf +++ b/test/integration/build/gcp-mm.tf @@ -129,6 +129,10 @@ variable "backend_bucket" { variable "gcp_cloud_function_region" {} +variable "regional_node_pool" { + type = "map" +} + resource "google_compute_ssl_policy" "custom-ssl-policy" { name = "${var.ssl_policy["name"]}" min_tls_version = "${var.ssl_policy["min_tls_version"]}" @@ -369,7 +373,8 @@ resource "google_container_cluster" "gcp-inspec-regional-cluster" { project = "${var.gcp_project_id}" name = "${var.regional_cluster["name"]}" region = "${var.gcp_location}" - initial_node_count = "${var.regional_cluster["initial_node_count"]}" + initial_node_count = 1 + remove_default_node_pool = true } resource "google_compute_route" "gcp-inspec-route" { @@ -501,4 +506,12 @@ resource "google_compute_backend_bucket" "image_backend" { description = "${var.backend_bucket["description"]}" bucket_name = "${google_storage_bucket.generic-storage-bucket.name}" enable_cdn = "${var.backend_bucket["enable_cdn"]}" +} + +resource "google_container_node_pool" "inspec-gcp-regional-node-pool" { + project = "${var.gcp_project_id}" + name = "${var.regional_node_pool["name"]}" + region = "${var.gcp_location}" + cluster = "${google_container_cluster.gcp-inspec-regional-cluster.name}" + node_count = "${var.regional_node_pool["node_count"]}" } \ No newline at end of file diff --git a/test/integration/configuration/mm-attributes.yml b/test/integration/configuration/mm-attributes.yml index bb88e413c..346ed5b9d 100644 --- a/test/integration/configuration/mm-attributes.yml +++ b/test/integration/configuration/mm-attributes.yml @@ -79,7 +79,7 @@ instance_template: name: inspec-gcp-instance-template description: A description of the instance template instance_description: A description of the instance itself - machine_type: n1-standard-1 + machine_type: f1-micro tag: foo can_ip_forward: false scheduling_automatic_restart: true @@ -202,4 +202,10 @@ cloudfunction: backend_bucket: name: inspec-gcp-backend-bucket description: Backend bucket example - enable_cdn: true \ No newline at end of file + enable_cdn: true + +regional_node_pool: + name: inspec-gcp-regional-node-pool + cluster_name: inspec-gcp-regional-node-pool-cluster + node_count: 1 + initial_node_count: 1 \ No newline at end of file diff --git a/test/integration/verify/controls/google_compute_instance_template.rb b/test/integration/verify/controls/google_compute_instance_template.rb index 5c159d01e..32e55128b 100644 --- a/test/integration/verify/controls/google_compute_instance_template.rb +++ b/test/integration/verify/controls/google_compute_instance_template.rb @@ -19,7 +19,7 @@ "name": "inspec-gcp-instance-template", "description": "A description of the instance template", "instance_description": "A description of the instance itself", - "machine_type": "n1-standard-1", + "machine_type": "f1-micro", "tag": "foo", "can_ip_forward": false, "scheduling_automatic_restart": true, diff --git a/test/integration/verify/controls/google_compute_instance_templates.rb b/test/integration/verify/controls/google_compute_instance_templates.rb index 8708cb0b3..e2702203a 100644 --- a/test/integration/verify/controls/google_compute_instance_templates.rb +++ b/test/integration/verify/controls/google_compute_instance_templates.rb @@ -19,7 +19,7 @@ "name": "inspec-gcp-instance-template", "description": "A description of the instance template", "instance_description": "A description of the instance itself", - "machine_type": "n1-standard-1", + "machine_type": "f1-micro", "tag": "foo", "can_ip_forward": false, "scheduling_automatic_restart": true, diff --git a/test/integration/verify/controls/google_container_regional_node_pool.rb b/test/integration/verify/controls/google_container_regional_node_pool.rb new file mode 100644 index 000000000..c4bda4f78 --- /dev/null +++ b/test/integration/verify/controls/google_container_regional_node_pool.rb @@ -0,0 +1,41 @@ +# ---------------------------------------------------------------------------- +# +# *** 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. +# +# ---------------------------------------------------------------------------- + +title 'Test GCP google_container_regional_node_pool resource.' + +gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.') +gcp_location = attribute(:gcp_location, default: 'gcp_location', description: 'The GCP project region.') +regional_node_pool = attribute('regional_node_pool', default: { + "name": "inspec-gcp-regional-node-pool", + "cluster_name": "inspec-gcp-regional-node-pool-cluster", + "node_count": 1, + "initial_node_count": 1 +}, description: 'Regional Node Pool definition') +regional_cluster = attribute('regional_cluster', default: { + "name": "inspec-gcp-regional-cluster", + "initial_node_count": 1 +}, description: 'Regional container cluster definition') +control 'google_container_regional_node_pool-1.0' do + impact 1.0 + title 'google_container_regional_node_pool resource test' + + describe google_container_regional_node_pool(project: gcp_project_id, location: gcp_location, cluster: regional_cluster['name'], name: regional_node_pool['name']) do + it { should exist } + its('initial_node_count') { should eq regional_node_pool['initial_node_count']} + end + + describe google_container_regional_node_pool(project: gcp_project_id, location: gcp_location, cluster: regional_cluster['name'], name: 'nonexistent') do + it { should_not exist } + end +end diff --git a/test/integration/verify/controls/google_container_regional_node_pools.rb b/test/integration/verify/controls/google_container_regional_node_pools.rb new file mode 100644 index 000000000..a07dd3d77 --- /dev/null +++ b/test/integration/verify/controls/google_container_regional_node_pools.rb @@ -0,0 +1,36 @@ +# ---------------------------------------------------------------------------- +# +# *** 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. +# +# ---------------------------------------------------------------------------- + +title 'Test GCP google_container_regional_node_pools resource.' + +gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.') +gcp_location = attribute(:gcp_location, default: 'gcp_location', description: 'The GCP project region.') +regional_node_pool = attribute('regional_node_pool', default: { + "name": "inspec-gcp-regional-node-pool", + "cluster_name": "inspec-gcp-regional-node-pool-cluster", + "node_count": 1, + "initial_node_count": 1 +}, description: 'Regional Node Pool definition') +regional_cluster = attribute('regional_cluster', default: { + "name": "inspec-gcp-regional-cluster", + "initial_node_count": 1 +}, description: 'Regional container cluster definition') +control 'google_container_regional_node_pools-1.0' do + impact 1.0 + title 'google_container_regional_node_pools resource test' + + describe google_container_regional_node_pools(project: gcp_project_id, location: gcp_location, cluster: regional_cluster['name']) do + its('initial_node_counts') { should include regional_node_pool['initial_node_count']} + end +end