Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Add network peerings for inspec (#4002) (#449)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Sep 22, 2020
1 parent 3edd18f commit da36f4c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/resources/google_compute_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ Properties that can be accessed from the `google_compute_network` resource:
* REGIONAL
* GLOBAL

* `peerings`: Peerings for a network

* `name`: Name of the peering.

* `state`: State of the peering.

* `state_details`: Details about the current state of the peering.

* `network`: URL of the peer network

* `export_custom_routes`: Whether to export the custom routes to the peer network.

* `import_custom_routes`: Whether to import the custom routes to the peer network.

* `peer_mtu`: Maximum Transmission Unit in bytes.


## GCP Permissions

Expand Down
1 change: 1 addition & 0 deletions docs/resources/google_compute_networks.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ See [google_compute_network.md](google_compute_network.md) for more detailed inf
* `auto_create_subnetworks`: an array of `google_compute_network` auto_create_subnetworks
* `creation_timestamps`: an array of `google_compute_network` creation_timestamp
* `routing_configs`: an array of `google_compute_network` routing_config
* `peerings`: an array of `google_compute_network` peerings

## Filter Criteria
This resource supports all of the above properties as filter criteria, which can be used
Expand Down
60 changes: 60 additions & 0 deletions libraries/google/compute/property/network_peerings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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 NetworkPeerings
attr_reader :name

attr_reader :state

attr_reader :state_details

attr_reader :network

attr_reader :export_custom_routes

attr_reader :import_custom_routes

attr_reader :peer_mtu

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@name = args['name']
@state = args['state']
@state_details = args['stateDetails']
@network = args['network']
@export_custom_routes = args['exportCustomRoutes']
@import_custom_routes = args['importCustomRoutes']
@peer_mtu = args['peerMtu']
end

def to_s
"#{@parent_identifier} NetworkPeerings"
end
end

class NetworkPeeringsArray
def self.parse(value, parent_identifier)
return if value.nil?
return NetworkPeerings.new(value, parent_identifier) unless value.is_a?(::Array)
value.map { |v| NetworkPeerings.new(v, parent_identifier) }
end
end
end
end
end
3 changes: 3 additions & 0 deletions libraries/google_compute_network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#
# ----------------------------------------------------------------------------
require 'gcp_backend'
require 'google/compute/property/network_peerings'
require 'google/compute/property/network_routing_config'

# A provider to manage Compute Engine resources.
Expand All @@ -31,6 +32,7 @@ class ComputeNetwork < GcpResourceBase
attr_reader :auto_create_subnetworks
attr_reader :creation_timestamp
attr_reader :routing_config
attr_reader :peerings

def initialize(params)
super(params.merge({ use_http_transport: true }))
Expand All @@ -48,6 +50,7 @@ def parse
@auto_create_subnetworks = @fetched['autoCreateSubnetworks']
@creation_timestamp = parse_time_string(@fetched['creationTimestamp'])
@routing_config = GoogleInSpec::Compute::Property::NetworkRoutingConfig.new(@fetched['routingConfig'], to_s)
@peerings = GoogleInSpec::Compute::Property::NetworkPeeringsArray.parse(@fetched['peerings'], to_s)
end

# Handles parsing RFC3339 time string
Expand Down
2 changes: 2 additions & 0 deletions libraries/google_compute_networks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ComputeNetworks < GcpResourceBase
filter_table_config.add(:auto_create_subnetworks, field: :auto_create_subnetworks)
filter_table_config.add(:creation_timestamps, field: :creation_timestamp)
filter_table_config.add(:routing_configs, field: :routing_config)
filter_table_config.add(:peerings, field: :peerings)

filter_table_config.connect(self, :table)

Expand Down Expand Up @@ -78,6 +79,7 @@ def transformers
'autoCreateSubnetworks' => ->(obj) { return :auto_create_subnetworks, obj['autoCreateSubnetworks'] },
'creationTimestamp' => ->(obj) { return :creation_timestamp, parse_time_string(obj['creationTimestamp']) },
'routingConfig' => ->(obj) { return :routing_config, GoogleInSpec::Compute::Property::NetworkRoutingConfig.new(obj['routingConfig'], to_s) },
'peerings' => ->(obj) { return :peerings, GoogleInSpec::Compute::Property::NetworkPeeringsArray.parse(obj['peerings'], to_s) },
}
end

Expand Down

0 comments on commit da36f4c

Please sign in to comment.