Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHEF-7382-MAGIC-MODULE-compute-VpnGateway - Resource Implementation #534

Merged
merged 6 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions docs/resources/google_compute_vpn_gateway.md
Original file line number Diff line number Diff line change
@@ -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.
39 changes: 39 additions & 0 deletions docs/resources/google_compute_vpn_gateways.md
Original file line number Diff line number Diff line change
@@ -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.
34 changes: 34 additions & 0 deletions libraries/google/compute/property/vpngateway_labels.rb
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions libraries/google/compute/property/vpngateway_vpn_interfaces.rb
Original file line number Diff line number Diff line change
@@ -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
79 changes: 79 additions & 0 deletions libraries/google_compute_vpn_gateway.rb
Original file line number Diff line number Diff line change
@@ -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
101 changes: 101 additions & 0 deletions libraries/google_compute_vpn_gateways.rb
Original file line number Diff line number Diff line change
@@ -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) { return :kind, obj['kind'] },
'id' => ->(obj) { return :id, obj['id'] },
'creationTimestamp' => ->(obj) { return :creation_timestamp, obj['creationTimestamp'] },
'name' => ->(obj) { return :name, obj['name'] },
'description' => ->(obj) { return :description, obj['description'] },
'region' => ->(obj) { return :region, obj['region'] },
'network' => ->(obj) { return :network, obj['network'] },
'selfLink' => ->(obj) { return :self_link, obj['selfLink'] },
'labels' => ->(obj) { return :labels, GoogleInSpec::Compute::Property::VpnGatewayLabels.new(obj['labels'], to_s) },
'labelFingerprint' => ->(obj) { return :label_fingerprint, obj['labelFingerprint'] },
'vpnInterfaces' => ->(obj) { return :vpn_interfaces, GoogleInSpec::Compute::Property::VpnGatewayVpnInterfacesArray.parse(obj['vpnInterfaces'], to_s) },
'stackType' => ->(obj) { return :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
Loading