diff --git a/docs/resources/google_compute_vpn_gateway.md b/docs/resources/google_compute_vpn_gateway.md new file mode 100644 index 000000000..fa153ed43 --- /dev/null +++ b/docs/resources/google_compute_vpn_gateway.md @@ -0,0 +1,73 @@ +--- +title: About the google_compute_vpn_gateway resource +platform: gcp +--- + +## Syntax +A `google_compute_vpn_gateway` is used to test a Google VpnGateway resource + +## Examples +``` +describe google_compute_vpn_gateway(project: 'chef-gcp-inspec', region: ' value_region', vpnGateway: ' ') 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('region') { should cmp 'value_region' } + its('network') { should cmp 'value_network' } + its('self_link') { should cmp 'value_selflink' } + its('label_fingerprint') { should cmp 'value_labelfingerprint' } + its('stack_type') { should cmp 'value_stacktype' } + +end + +describe google_compute_vpn_gateway(project: 'chef-gcp-inspec', region: ' value_region', vpnGateway: ' ') do + it { should_not exist } +end +``` + +## Properties +Properties that can be accessed from the `google_compute_vpn_gateway` resource: + + + * `kind`: [Output Only] Type of resource. Always compute#vpnGateway for VPN gateways. + + * `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. + + * `region`: [Output Only] URL of the region where the VPN gateway resides. + + * `network`: URL of the network to which this VPN gateway is attached. Provided by the client when the VPN gateway is created. + + * `self_link`: [Output Only] Server-defined URL for the resource. + + * `labels`: Labels for this resource. These can only be added or modified by the setLabels method. Each label key/value pair must comply with RFC1035. Label values may be empty. + + * `additional_properties`: + + * `label_fingerprint`: A fingerprint for the labels being applied to this VpnGateway, which is essentially a hash of the labels set used for optimistic locking. The fingerprint is initially generated by Compute Engine and changes after every request to modify or update labels. You must always provide an up-to-date fingerprint hash in order to update or change labels, otherwise the request will fail with error 412 conditionNotMet. To see the latest fingerprint, make a get() request to retrieve a VpnGateway. + + * `vpn_interfaces`: The list of VPN interfaces associated with this VPN gateway. + + * `id`: [Output Only] Numeric identifier for this VPN interface associated with the VPN gateway. + + * `ip_address`: [Output Only] IP address for this VPN interface associated with the VPN gateway. The IP address could be either a regional external IP address or a regional internal IP address. The two IP addresses for a VPN gateway must be all regional external or regional internal IP addresses. There cannot be a mix of regional external IP addresses and regional internal IP addresses. For HA VPN over Cloud Interconnect, the IP addresses for both interfaces could either be regional internal IP addresses or regional external IP addresses. For regular (non HA VPN over Cloud Interconnect) HA VPN tunnels, the IP address must be a regional external IP address. + + * `interconnect_attachment`: URL of the VLAN attachment (interconnectAttachment) resource for this VPN gateway interface. When the value of this field is present, the VPN gateway is used for HA VPN over Cloud Interconnect; all egress or ingress traffic for this VPN gateway interface goes through the specified VLAN attachment resource. + + * `stack_type`: The stack type for this VPN gateway to identify the IP protocols that are enabled. Possible values are: IPV4_ONLY, IPV4_IPV6. If not specified, IPV4_ONLY will be used. + Possible values: + * IPV4_IPV6 + * IPV4_ONLY + + +## 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_vpn_gateways.md b/docs/resources/google_compute_vpn_gateways.md new file mode 100644 index 000000000..0affd25e9 --- /dev/null +++ b/docs/resources/google_compute_vpn_gateways.md @@ -0,0 +1,39 @@ +--- +title: About the google_compute_vpn_gateways resource +platform: gcp +--- + +## Syntax +A `google_compute_vpn_gateways` is used to test a Google VpnGateway resource + +## Examples +``` + describe google_compute_vpn_gateways(project: 'chef-gcp-inspec', region: ' value_region') do + it { should exist } + end +``` + +## Properties +Properties that can be accessed from the `google_compute_vpn_gateways` resource: + +See [google_compute_vpn_gateway.md](google_compute_vpn_gateway.md) for more detailed information + * `kinds`: an array of `google_compute_vpn_gateway` kind + * `ids`: an array of `google_compute_vpn_gateway` id + * `creation_timestamps`: an array of `google_compute_vpn_gateway` creation_timestamp + * `names`: an array of `google_compute_vpn_gateway` name + * `descriptions`: an array of `google_compute_vpn_gateway` description + * `regions`: an array of `google_compute_vpn_gateway` region + * `networks`: an array of `google_compute_vpn_gateway` network + * `self_links`: an array of `google_compute_vpn_gateway` self_link + * `labels`: an array of `google_compute_vpn_gateway` labels + * `label_fingerprints`: an array of `google_compute_vpn_gateway` label_fingerprint + * `vpn_interfaces`: an array of `google_compute_vpn_gateway` vpn_interfaces + * `stack_types`: an array of `google_compute_vpn_gateway` stack_type + +## 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/vpngateway_labels.rb b/libraries/google/compute/property/vpngateway_labels.rb new file mode 100644 index 000000000..f28c34ae0 --- /dev/null +++ b/libraries/google/compute/property/vpngateway_labels.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 VpnGatewayLabels + 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} VpnGatewayLabels" + end + end + end + end +end diff --git a/libraries/google/compute/property/vpngateway_vpn_interfaces.rb b/libraries/google/compute/property/vpngateway_vpn_interfaces.rb new file mode 100644 index 000000000..7119879e8 --- /dev/null +++ b/libraries/google/compute/property/vpngateway_vpn_interfaces.rb @@ -0,0 +1,48 @@ +# 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 VpnGatewayVpnInterfaces + attr_reader :id + + attr_reader :ip_address + + attr_reader :interconnect_attachment + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @id = args['id'] + @ip_address = args['ipAddress'] + @interconnect_attachment = args['interconnectAttachment'] + end + + def to_s + "#{@parent_identifier} VpnGatewayVpnInterfaces" + end + end + + class VpnGatewayVpnInterfacesArray + def self.parse(value, parent_identifier) + return if value.nil? + return VpnGatewayVpnInterfaces.new(value, parent_identifier) unless value.is_a?(::Array) + value.map { |v| VpnGatewayVpnInterfaces.new(v, parent_identifier) } + end + end + end + end +end diff --git a/libraries/google_compute_vpn_gateway.rb b/libraries/google_compute_vpn_gateway.rb new file mode 100644 index 000000000..f9691e6f1 --- /dev/null +++ b/libraries/google_compute_vpn_gateway.rb @@ -0,0 +1,79 @@ +# 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/vpngateway_labels' +require 'google/compute/property/vpngateway_vpn_interfaces' + +# A provider to manage Compute Engine resources. +class ComputeVpnGateway < GcpResourceBase + name 'google_compute_vpn_gateway' + desc 'VpnGateway' + supports platform: 'gcp' + + attr_reader :params + attr_reader :kind + attr_reader :id + attr_reader :creation_timestamp + attr_reader :name + attr_reader :description + attr_reader :region + attr_reader :network + attr_reader :self_link + attr_reader :labels + attr_reader :label_fingerprint + attr_reader :vpn_interfaces + attr_reader :stack_type + + 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'] + @region = @fetched['region'] + @network = @fetched['network'] + @self_link = @fetched['selfLink'] + @labels = GoogleInSpec::Compute::Property::VpnGatewayLabels.new(@fetched['labels'], to_s) + @label_fingerprint = @fetched['labelFingerprint'] + @vpn_interfaces = GoogleInSpec::Compute::Property::VpnGatewayVpnInterfacesArray.parse(@fetched['vpnInterfaces'], to_s) + @stack_type = @fetched['stackType'] + end + + def exists? + !@fetched.nil? + end + + def to_s + "VpnGateway #{@params[:vpnGateway]}" + end + + private + + def product_url(_ = nil) + 'https://compute.googleapis.com/compute/v1/' + end + + def resource_base_url + 'projects/{{project}}/regions/{{region}}/vpnGateways/{{vpn_gateway}}' + end +end diff --git a/libraries/google_compute_vpn_gateways.rb b/libraries/google_compute_vpn_gateways.rb new file mode 100644 index 000000000..cc49c72cf --- /dev/null +++ b/libraries/google_compute_vpn_gateways.rb @@ -0,0 +1,101 @@ +# 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 ComputeVpnGateways < GcpResourceBase + name 'google_compute_vpn_gateways' + desc 'VpnGateway 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(:regions, field: :region) + filter_table_config.add(:networks, field: :network) + filter_table_config.add(:self_links, field: :self_link) + filter_table_config.add(:labels, field: :labels) + filter_table_config.add(:label_fingerprints, field: :label_fingerprint) + filter_table_config.add(:vpn_interfaces, field: :vpn_interfaces) + filter_table_config.add(:stack_types, field: :stack_type) + + filter_table_config.connect(self, :table) + + 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(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']] }, + 'region' => ->(obj) { [:region, obj['region']] }, + 'network' => ->(obj) { [:network, obj['network']] }, + 'selfLink' => ->(obj) { [:self_link, obj['selfLink']] }, + 'labels' => ->(obj) { [:labels, GoogleInSpec::Compute::Property::VpnGatewayLabels.new(obj['labels'], to_s)] }, + 'labelFingerprint' => ->(obj) { [:label_fingerprint, obj['labelFingerprint']] }, + 'vpnInterfaces' => ->(obj) { [:vpn_interfaces, GoogleInSpec::Compute::Property::VpnGatewayVpnInterfacesArray.parse(obj['vpnInterfaces'], to_s)] }, + 'stackType' => ->(obj) { [:stack_type, obj['stackType']] }, + } + end + + private + + def product_url(_ = nil) + 'https://compute.googleapis.com/compute/v1/' + end + + def resource_base_url + 'projects/{{project}}/regions/{{region}}/vpnGateways' + end +end diff --git a/test/integration/build/gcp-mm.tf b/test/integration/build/gcp-mm.tf index 1280f9d57..0d3d82d67 100644 --- a/test/integration/build/gcp-mm.tf +++ b/test/integration/build/gcp-mm.tf @@ -236,6 +236,9 @@ variable "apigee_organization_envgroup_attachment" { variable "organization_envgroup" { type = any } +variable "vpn_gateway" { + type = any +} resource "google_compute_ssl_policy" "custom-ssl-policy" { name = var.ssl_policy["name"] @@ -1572,6 +1575,17 @@ resource "google_vertex_ai_index" "index" { } index_update_method = "STREAM_UPDATE" } +resource "google_compute_ha_vpn_gateway" "ha_vpn_gateway" { + project = var.vpn_gateway.project + region = var.vpn_gateway.region + name = var.vpn_gateway.name + network = google_compute_network.network1.id +} +resource "google_compute_network" "network1" { + project = var.vpn_gateway.project + name = "network1" + auto_create_subnetworks = false +} resource "google_artifact_registry_repository" "example" { project = var.project_location_repository.project_id diff --git a/test/integration/configuration/mm-attributes.yml b/test/integration/configuration/mm-attributes.yml index 2b28a40f0..8c37d5494 100644 --- a/test/integration/configuration/mm-attributes.yml +++ b/test/integration/configuration/mm-attributes.yml @@ -607,3 +607,17 @@ organization_envgroup: apigee_organization_envgroup_attachment: envgroup_id: "organizations/ppradhan/envgroups/test-env-group" environment: "test-env" + +vpn_gateway: + project : "ppradhan" + region : "us-central1" + vpn_gateway : "4406948336461056012" + kind : "value_kind" + id : "value_id" + creation_timestamp : "value_creationtimestamp" + name : "inspec-vpn-gateway" + description : "Inspec Test HA VPN Gateway" + network : "gcp-inspec-network" + self_link : "value_selflink" + label_fingerprint : "value_labelfingerprint" + stack_type : "IPV4_ONLY" diff --git a/test/integration/verify/controls/google_compute_vpn_gateway.rb b/test/integration/verify/controls/google_compute_vpn_gateway.rb new file mode 100644 index 000000000..54e1405bd --- /dev/null +++ b/test/integration/verify/controls/google_compute_vpn_gateway.rb @@ -0,0 +1,55 @@ +# ---------------------------------------------------------------------------- +# +# *** 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_vpn_gateway resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + vpn_gateway = input('vpn_gateway', value: { + "project": "ppradhan", + "region": "us-central1", + "vpn_gateway": "2245103640699591658", + "kind": "value_kind", + "id": "2245103640699591658", + "creation_timestamp": "2023-12-12T05:49:57.914-08:00", + "name": "inspec-vpn-gateway", + "description": "value_description", + "network": "https://www.googleapis.com/compute/v1/projects/ppradhan/global/networks/network1", + "self_link": "value_selflink", + "label_fingerprint": "value_labelfingerprint", + "stack_type": "IPV4_ONLY" +}, description: 'vpn_gateway description') +control 'google_compute_vpn_gateway-1.0' do + impact 1.0 + title 'google_compute_vpn_gateway resource test' + + describe google_compute_vpn_gateway(project: gcp_project_id, region: vpn_gateway['region'], vpnGateway: vpn_gateway['vpnGateway']) do + it { should exist } + its('kind') { should cmp vpn_gateway['kind'] } + its('id') { should cmp vpn_gateway['id'] } + its('creation_timestamp') { should cmp vpn_gateway['creation_timestamp'] } + its('name') { should cmp vpn_gateway['name'] } + its('description') { should cmp vpn_gateway['description'] } + its('region') { should cmp vpn_gateway['region'] } + its('network') { should cmp vpn_gateway['network'] } + its('self_link') { should cmp vpn_gateway['self_link'] } + its('label_fingerprint') { should cmp vpn_gateway['label_fingerprint'] } + its('stack_type') { should cmp vpn_gateway['stack_type'] } + + end + + describe google_compute_vpn_gateway(project: gcp_project_id, region: vpn_gateway['region'], vpnGateway: vpn_gateway['vpnGateway']) do + it { should_not exist } + end +end diff --git a/test/integration/verify/controls/google_compute_vpn_gateways.rb b/test/integration/verify/controls/google_compute_vpn_gateways.rb new file mode 100644 index 000000000..bc52719c0 --- /dev/null +++ b/test/integration/verify/controls/google_compute_vpn_gateways.rb @@ -0,0 +1,40 @@ +# ---------------------------------------------------------------------------- +# +# *** 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_vpn_gateways resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + vpn_gateway = input('vpn_gateway', value: { + "project": "ppradhan", + "region": "us-central1", + "vpn_gateway": "2245103640699591658", + "kind": "value_kind", + "id": "2245103640699591658", + "creation_timestamp": "2023-12-12T05:49:57.914-08:00", + "name": "inspec-vpn-gateway", + "description": "value_description", + "network": "https://www.googleapis.com/compute/v1/projects/ppradhan/global/networks/network1", + "self_link": "value_selflink", + "label_fingerprint": "value_labelfingerprint", + "stack_type": "IPV4_ONLY" +}, description: 'vpn_gateway description') +control 'google_compute_vpn_gateways-1.0' do + impact 1.0 + title 'google_compute_vpn_gateways resource test' + + describe google_compute_vpn_gateways(project: gcp_project_id, region: vpn_gateway['region']) do + it { should exist } + end +end