Skip to content

Commit

Permalink
Add interconnect attachments. (#210)
Browse files Browse the repository at this point in the history
Merged PR #210.
  • Loading branch information
nat-henderson authored and modular-magician committed Oct 11, 2018
1 parent 2dd80bd commit 293bb07
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 4 deletions.
4 changes: 4 additions & 0 deletions products/compute/ansible.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ datasources: !ruby/object:Provider::ResourceOverrides
version_added: '2.7'
InstanceTemplate: !ruby/object:Provider::Ansible::ResourceOverride
version_added: '2.7'
InterconnectAttachment: !ruby/object:Provider::Ansible::ResourceOverride
version_added: '2.8'
Network: !ruby/object:Provider::Ansible::ResourceOverride
version_added: '2.7'
RegionAutoscaler: !ruby/object:Provider::Ansible::ResourceOverride
Expand Down Expand Up @@ -265,6 +267,8 @@ overrides: !ruby/object:Provider::ResourceOverrides
provider_helpers:
- 'products/compute/helpers/python/provider_instance.py'
- 'products/compute/helpers/python/instance_metadata.py'
InterconnectAttachment: !ruby/object:Provider::Ansible::ResourceOverride
version_added: '2.8'
Network: !ruby/object:Provider::Ansible::ResourceOverride
properties:
routingConfig: !ruby/object:Provider::Ansible::PropertyOverride
Expand Down
100 changes: 100 additions & 0 deletions products/compute/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,106 @@ objects:
The target number of running instances for this managed instance
group. Deleting or abandoning instances reduces this number. Resizing
the group changes this number.
- !ruby/object:Api::Resource
name: 'InterconnectAttachment'
kind: 'compute#interconnectAttachment'
base_url: 'projects/{{project}}/regions/{{region}}/interconnectAttachments'
exports:
- !ruby/object:Api::Type::SelfLink
name: 'selfLink'
input: true
description: |
Represents an InterconnectAttachment (VLAN attachment) resource. For more
information, see Creating VLAN Attachments.
<%= indent(compile_file({}, 'templates/regional_async.yaml.erb'), 4) %>
parameters:
- !ruby/object:Api::Type::ResourceRef
name: 'region'
resource: 'Region'
imports: 'selfLink'
required: true
description: |
Region where the regional interconnect attachment resides.
properties:
- !ruby/object:Api::Type::String
name: 'cloudRouterIpAddress'
description: |
IPv4 address + prefix length to be configured on Cloud Router
Interface for this interconnect attachment.
output: true
- !ruby/object:Api::Type::String
name: 'customerRouterIpAddress'
description: |
IPv4 address + prefix length to be configured on the customer
router subinterface for this interconnect attachment.
output: true
- !ruby/object:Api::Type::String
name: 'interconnect'
description: |
URL of the underlying Interconnect object that this attachment's traffic will
traverse through.
required: true
- !ruby/object:Api::Type::String
name: 'description'
description: |
An optional description of this resource.
- !ruby/object:Api::Type::NestedObject
name: 'privateInterconnectInfo'
description: |
Information specific to an InterconnectAttachment. This property
is populated if the interconnect that this is attached to is of type DEDICATED.
output: true
properties:
- !ruby/object:Api::Type::Integer
name: tag8021q
description: |
802.1q encapsulation tag to be used for traffic between
Google and the customer, going to and from this network and region.
output: true
- !ruby/object:Api::Type::String
name: 'googleReferenceId'
description: |
Google reference ID, to be used when raising support tickets with
Google or otherwise to debug backend connectivity issues.
output: true
- !ruby/object:Api::Type::String
name: 'operationalStatus'
description: |
The current status of whether or not this interconnect attachment
is functional.
output: true
exclude: true
- !ruby/object:Api::Type::ResourceRef
name: 'router'
resource: 'Router'
imports: 'selfLink'
description: |
URL of the cloud router to be used for dynamic routing. This router must be in
the same region as this InterconnectAttachment. The InterconnectAttachment will
automatically connect the Interconnect to the network & region within which the
Cloud Router is configured.
required: true
- !ruby/object:Api::Type::Time
name: 'creationTimestamp'
description: |
Creation timestamp in RFC3339 text format.
output: true
- !ruby/object:Api::Type::String
name: 'id'
description: |
The unique identifier for the resource. This identifier is
defined by the server.
output: true
- !ruby/object:Api::Type::String
name: 'name'
description: |
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.
required: true
- !ruby/object:Api::Resource
name: 'MachineType'
kind: 'compute#machineType'
Expand Down
34 changes: 34 additions & 0 deletions products/compute/examples/ansible/interconnect_attachment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2018 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.
--- !ruby/object:Provider::Ansible::Example
task:
!ruby/object:Provider::Ansible::Task
name: gcp_compute_interconnect_attachment
code:
name: <%= ctx[:name] %>
region: us-central1
project: <%= ctx[:project] %>
auth_kind: <%= ctx[:auth_kind] %>
interconnect: 'https://googleapis.com/compute/v1/projects/<%=ctx[:project]%>/global/interconnects/...'
router: 'https://googleapis.com/compute/v1/projects/<%=ctx[:project]%>/regions/us-central1/routers/...'
service_account_file: <%= ctx[:service_account_file] %>
register: disk
verifier: !ruby/object:Provider::Ansible::Verifier
command: |
gcloud compute interconnects attachments describe
"{{ resource_name }}"
--project="{{ gcp_project}}"
--region="{{ gcp_region}}"
failure: !ruby/object:Provider::Ansible::ComputeFailureCondition
region: global
type: images
35 changes: 35 additions & 0 deletions products/compute/examples/chef/interconnect_attachment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<% if false # the license inside this if block assertains to this file -%>
# 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.
<% end -%>
<% unless name == 'README.md' -%>
<%= compile 'templates/license.erb' -%>
<%= lines(autogen_notice :chef) -%>
<%= compile 'templates/chef/example~auth.rb.erb' -%>
<% else -%>
<% end # name == README.md -%>
gcompute_interconnect_attachment <%= example_resource_name('test-interconnect') -%> do
action :create
project 'google.com:graphite-playground'
region 'us-central1'
name <%= example_resource_name('test-interconnect') -%>
interconnect 'projects/$project/global/interconnects/$interconnect'
router 'projects/$project/regions/$region/routers/$router'
credential 'mycred'
end
36 changes: 36 additions & 0 deletions products/compute/examples/puppet/interconnect_attachment.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<% if false # the license inside this if block pertains to this file -%>
# Copyright 2018 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.
<% end -%>
<% unless name == "README.md" -%>
<%= compile 'templates/license.erb' -%>

<%= lines(autogen_notice :puppet) -%>

<%= compile 'templates/puppet/examples~credential.pp.erb' -%>

<% end # name == README.md -%>
gcompute_region { 'us-central1':
project => 'google.com:graphite-playground',
credential => 'mycred',
}

gcompute_interconnect_attachment { <%= example_resource_name('test-attachment') -%>:
ensure => present,
region => 'us-central1',
name => <%= example_resource_name('test-attachment') -%>,
interconnect => 'https://googleapis.com/compute/v1/projects/...global/interconnects/...',
router => 'https://googleapis.com/compute/v1/projects/...regions/.../routers/...',
project => 'google.com:graphite-playground',
credential => 'mycred',
}
2 changes: 2 additions & 0 deletions products/compute/puppet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ examples: !ruby/object:Api::Resource::HashArray
Instance:
- delete_instance.pp
- instance.pp
InterconnectAttachment:
- interconnect_attachment.pp
# License -- useful?
License:
- license.pp
Expand Down
27 changes: 27 additions & 0 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,33 @@ overrides: !ruby/object:Provider::ResourceOverrides
exclude: true
InstanceTemplate: !ruby/object:Provider::Terraform::ResourceOverride
exclude: true
InterconnectAttachment: !ruby/object:Provider::Terraform::ResourceOverride
properties:
id: !ruby/object:Provider::Terraform::PropertyOverride
exclude: true
name: !ruby/object:Provider::Terraform::PropertyOverride
validation: !ruby/object:Provider::Terraform::Validation
regex: '^[a-z]([-a-z0-9]*[a-z0-9])?$'
region: !ruby/object:Provider::Terraform::PropertyOverride
required: false
default_from_api: true
router: !ruby/object:Provider::Terraform::PropertyOverride
diff_suppress_func: 'compareSelfLinkOrResourceName'
interconnect: !ruby/object:Provider::Terraform::PropertyOverride
diff_suppress_func: 'compareSelfLinkOrResourceName'
examples: |
```hcl
resource "google_compute_router" "foobar" {
name = "my-router"
network = "${google_compute_network.foobar.name}"
}
resource "google_compute_interconnect_attachment" "default" {
name = "test-interconnect"
interconnect = "my-interconnect-id"
router = "${google_compute_router.foobar.self_link}"
}
```
License: !ruby/object:Provider::Terraform::ResourceOverride
exclude: true
MachineType: !ruby/object:Provider::Terraform::ResourceOverride
Expand Down
14 changes: 13 additions & 1 deletion provider/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,21 @@ def format_expand_variables(obj_url)
else
vars = quote_string(obj_url[0])
vars_parts = obj_url[0].split('/')
# What's going on here? :) Here we have an API-defined string
# (the self-link format), which we are doggedly trying to fit
# into 72 characters or less (80 - the 8 of indentation). A
# very small number of our self links won't fit in 72 characters,
# especially those with long type names. Here, we're trying to
# format it into a list of arguments, so the string needs to end
# with a comma.
format([
# Option 1: 'foo/bar',
[[vars, ','].join],
# vars is too big to fit, split in half
# Option 2: [
# 'foo',
# 'bar
# ].join('/'),
['['] +
vars_parts.each_slice((vars_parts.size / 2.0).round).to_a
.map.with_index do |p, i|
# Use implicit string joining for the first line.
Expand Down

0 comments on commit 293bb07

Please sign in to comment.