Skip to content

Commit

Permalink
Merge pull request #535 from inspec/CHEF-MAGIC-MODULE-compute-Service…
Browse files Browse the repository at this point in the history
…Attachment

CHEF-7384: MAGIC-MODULE-compute-ServiceAttachment - Resource Implementation
  • Loading branch information
sa-progress authored Dec 12, 2023
2 parents a17da32 + 899fd97 commit 03dc826
Show file tree
Hide file tree
Showing 12 changed files with 706 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ The following resources are available in the InSpec GCP Profile
| [google_vertex_ai_tensorboard_experiment_run_time_series_resource](docs/resources/google_vertex_ai_tensorboard_experiment_run_time_series_resource.md) | [google_vertex_ai_tensorboard_experiment_run_time_series_resources](docs/resources/google_vertex_ai_tensorboard_experiment_run_time_series_resources.md) |
| [google_vertex_ai_training_pipeline](docs/resources/google_vertex_ai_training_pipeline.md) | [google_vertex_ai_training_pipelines](docs/resources/google_vertex_ai_training_pipelines.md) |
| [google_composer_project_location_environment](docs/resources/google_composer_project_location_environment.md) | [google_composer_project_location_environments](docs/resources/google_composer_project_location_environment.md) |
| [google_compute_service_attachment](docs/resources/google_compute_service_attachment.md) | [google_compute_service_attachments](docs/resources/google_compute_service_attachments.md) |

## Examples

Expand Down
106 changes: 106 additions & 0 deletions docs/resources/google_compute_service_attachment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
title: About the google_compute_service_attachment resource
platform: gcp
---

## Syntax
A `google_compute_service_attachment` is used to test a Google ServiceAttachment resource

## Examples
```
describe google_compute_service_attachment(project: 'chef-gcp-inspec', region: ' value_region', service_attachment: ' ') 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('self_link') { should cmp 'value_selflink' }
its('region') { should cmp 'value_region' }
its('producer_forwarding_rule') { should cmp 'value_producerforwardingrule' }
its('target_service') { should cmp 'value_targetservice' }
its('connection_preference') { should cmp 'value_connectionpreference' }
its('fingerprint') { should cmp 'value_fingerprint' }
end
describe google_compute_service_attachment(project: 'chef-gcp-inspec', region: ' value_region', service_attachment: ' ') do
it { should_not exist }
end
```

## Properties
Properties that can be accessed from the `google_compute_service_attachment` resource:


* `kind`: [Output Only] Type of the resource. Always compute#serviceAttachment for service attachments.

* `id`: [Output Only] The unique identifier for the resource type. The server generates this identifier.

* `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.

* `self_link`: [Output Only] Server-defined URL for the resource.

* `region`: [Output Only] URL of the region where the service attachment resides. This field applies only to the region resource. You must specify this field as part of the HTTP request URL. It is not settable as a field in the request body.

* `producer_forwarding_rule`: The URL of a forwarding rule with loadBalancingScheme INTERNAL* that is serving the endpoint identified by this service attachment.

* `target_service`: The URL of a service serving the endpoint identified by this service attachment.

* `connection_preference`: The connection preference of service attachment. The value can be set to ACCEPT_AUTOMATIC. An ACCEPT_AUTOMATIC service attachment is one that always accepts the connection from consumer forwarding rules.
Possible values:
* ACCEPT_AUTOMATIC
* ACCEPT_MANUAL
* CONNECTION_PREFERENCE_UNSPECIFIED

* `connected_endpoints`: [Output Only] An array of connections for all the consumers connected to this service attachment.

* `status`: The status of a connected endpoint to this service attachment.
Possible values:
* ACCEPTED
* CLOSED
* NEEDS_ATTENTION
* PENDING
* REJECTED
* STATUS_UNSPECIFIED

* `psc_connection_id`: The PSC connection id of the connected endpoint.

* `endpoint`: The url of a connected endpoint.

* `consumer_network`: The url of the consumer network.

* `nat_subnets`: An array of URLs where each entry is the URL of a subnet provided by the service producer to use for NAT in this service attachment.

* `enable_proxy_protocol`: If true, enable the proxy protocol which is for supplying client TCP/IP address data in TCP connections that traverse proxies on their way to destination servers.

* `consumer_reject_lists`: Projects that are not allowed to connect to this service attachment. The project can be specified using its id or number.

* `consumer_accept_lists`: Projects that are allowed to connect to this service attachment.

* `project_id_or_num`: The project id or number for the project to set the limit for.

* `network_url`: The network URL for the network to set the limit for.

* `connection_limit`: The value of the limit to set.

* `psc_service_attachment_id`:

* `high`:

* `low`:

* `fingerprint`: Fingerprint of this resource. A hash of the contents stored in this object. This field is used in optimistic locking. This field will be ignored when inserting a ServiceAttachment. An up-to-date fingerprint must be provided in order to patch/update the ServiceAttachment; otherwise, the request will fail with error 412 conditionNotMet. To see the latest fingerprint, make a get() request to retrieve the ServiceAttachment.

* `domain_names`: If specified, the domain name will be used during the integration between the PSC connected endpoints and the Cloud DNS. For example, this is a valid domain name: "p.mycompany.com.". Current max number of domain names supported is 1.

* `reconcile_connections`: This flag determines whether a consumer accept/reject list change can reconcile the statuses of existing ACCEPTED or REJECTED PSC endpoints. - If false, connection policy update will only affect existing PENDING PSC endpoints. Existing ACCEPTED/REJECTED endpoints will remain untouched regardless how the connection policy is modified . - If true, update will affect both PENDING and ACCEPTED/REJECTED PSC endpoints. For example, an ACCEPTED PSC endpoint will be moved to REJECTED if its project is added to the reject list. For newly created service attachment, this boolean defaults to false.


## GCP Permissions

Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the current project.
46 changes: 46 additions & 0 deletions docs/resources/google_compute_service_attachments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: About the google_compute_service_attachments resource
platform: gcp
---

## Syntax
A `google_compute_service_attachments` is used to test a Google ServiceAttachment resource

## Examples
```
describe google_compute_service_attachments(project: 'chef-gcp-inspec', region: ' value_region') do
it { should exist }
end
```

## Properties
Properties that can be accessed from the `google_compute_service_attachments` resource:

See [google_compute_service_attachment.md](google_compute_service_attachment.md) for more detailed information
* `kinds`: an array of `google_compute_service_attachment` kind
* `ids`: an array of `google_compute_service_attachment` id
* `creation_timestamps`: an array of `google_compute_service_attachment` creation_timestamp
* `names`: an array of `google_compute_service_attachment` name
* `descriptions`: an array of `google_compute_service_attachment` description
* `self_links`: an array of `google_compute_service_attachment` self_link
* `regions`: an array of `google_compute_service_attachment` region
* `producer_forwarding_rules`: an array of `google_compute_service_attachment` producer_forwarding_rule
* `target_services`: an array of `google_compute_service_attachment` target_service
* `connection_preferences`: an array of `google_compute_service_attachment` connection_preference
* `connected_endpoints`: an array of `google_compute_service_attachment` connected_endpoints
* `nat_subnets`: an array of `google_compute_service_attachment` nat_subnets
* `enable_proxy_protocols`: an array of `google_compute_service_attachment` enable_proxy_protocol
* `consumer_reject_lists`: an array of `google_compute_service_attachment` consumer_reject_lists
* `consumer_accept_lists`: an array of `google_compute_service_attachment` consumer_accept_lists
* `psc_service_attachment_ids`: an array of `google_compute_service_attachment` psc_service_attachment_id
* `fingerprints`: an array of `google_compute_service_attachment` fingerprint
* `domain_names`: an array of `google_compute_service_attachment` domain_names
* `reconcile_connections`: an array of `google_compute_service_attachment` reconcile_connections

## 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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 ServiceAttachmentConnectedEndpoints
attr_reader :status

attr_reader :psc_connection_id

attr_reader :endpoint

attr_reader :consumer_network

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@status = args['status']
@psc_connection_id = args['pscConnectionId']
@endpoint = args['endpoint']
@consumer_network = args['consumerNetwork']
end

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

class ServiceAttachmentConnectedEndpointsArray
def self.parse(value, parent_identifier)
return if value.nil?
return ServiceAttachmentConnectedEndpoints.new(value, parent_identifier) unless value.is_a?(::Array)
value.map { |v| ServiceAttachmentConnectedEndpoints.new(v, parent_identifier) }
end
end
end
end
end
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 ServiceAttachmentConsumerAcceptLists
attr_reader :project_id_or_num

attr_reader :network_url

attr_reader :connection_limit

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@project_id_or_num = args['projectIdOrNum']
@network_url = args['networkUrl']
@connection_limit = args['connectionLimit']
end

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

class ServiceAttachmentConsumerAcceptListsArray
def self.parse(value, parent_identifier)
return if value.nil?
return ServiceAttachmentConsumerAcceptLists.new(value, parent_identifier) unless value.is_a?(::Array)
value.map { |v| ServiceAttachmentConsumerAcceptLists.new(v, parent_identifier) }
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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 ServiceAttachmentPscServiceAttachmentId
attr_reader :high

attr_reader :low

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@high = args['high']
@low = args['low']
end

def to_s
"#{@parent_identifier} ServiceAttachmentPscServiceAttachmentId"
end
end
end
end
end
94 changes: 94 additions & 0 deletions libraries/google_compute_service_attachment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# 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/serviceattachment_connected_endpoints'
require 'google/compute/property/serviceattachment_consumer_accept_lists'
require 'google/compute/property/serviceattachment_psc_service_attachment_id'

# A provider to manage Compute Engine resources.
class ComputeServiceAttachment < GcpResourceBase
name 'google_compute_service_attachment'
desc 'ServiceAttachment'
supports platform: 'gcp'

attr_reader :params
attr_reader :kind
attr_reader :id
attr_reader :creation_timestamp
attr_reader :name
attr_reader :description
attr_reader :self_link
attr_reader :region
attr_reader :producer_forwarding_rule
attr_reader :target_service
attr_reader :connection_preference
attr_reader :connected_endpoints
attr_reader :nat_subnets
attr_reader :enable_proxy_protocol
attr_reader :consumer_reject_lists
attr_reader :consumer_accept_lists
attr_reader :psc_service_attachment_id
attr_reader :fingerprint
attr_reader :domain_names
attr_reader :reconcile_connections

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']
@self_link = @fetched['selfLink']
@region = @fetched['region']
@producer_forwarding_rule = @fetched['producerForwardingRule']
@target_service = @fetched['targetService']
@connection_preference = @fetched['connectionPreference']
@connected_endpoints = GoogleInSpec::Compute::Property::ServiceAttachmentConnectedEndpointsArray.parse(@fetched['connectedEndpoints'], to_s)
@nat_subnets = @fetched['natSubnets']
@enable_proxy_protocol = @fetched['enableProxyProtocol']
@consumer_reject_lists = @fetched['consumerRejectLists']
@consumer_accept_lists = GoogleInSpec::Compute::Property::ServiceAttachmentConsumerAcceptListsArray.parse(@fetched['consumerAcceptLists'], to_s)
@psc_service_attachment_id = GoogleInSpec::Compute::Property::ServiceAttachmentPscServiceAttachmentId.new(@fetched['pscServiceAttachmentId'], to_s)
@fingerprint = @fetched['fingerprint']
@domain_names = @fetched['domainNames']
@reconcile_connections = @fetched['reconcileConnections']
end

def exists?
!@fetched.nil?
end

def to_s
"ServiceAttachment #{@params[:service_attachment]}"
end

private

def product_url(_ = nil)
'https://compute.googleapis.com/compute/v1/'
end

def resource_base_url
'projects/{{project}}/regions/{{region}}/serviceAttachments/{{service_attachment}}'
end
end
Loading

0 comments on commit 03dc826

Please sign in to comment.