From 57d66ee060998a35dbdbbb0abc046244c0ea781f Mon Sep 17 00:00:00 2001 From: Vivian Cox Date: Mon, 18 Sep 2023 14:53:39 -0700 Subject: [PATCH] Add Network and Subnet resources for edgenetwork (#8905) * Add Network and Subnet resources for edgenetwork * Fix lint * Added labels field to acceptance tests; Removed send_empty_value:false from vlan_id field in Subnet * Skip edgenetwork acceptance tests --- mmv1/products/edgenetwork/Network.yaml | 97 ++++++++++++ mmv1/products/edgenetwork/Subnet.yaml | 138 ++++++++++++++++++ mmv1/products/edgenetwork/product.yaml | 42 ++++++ .../terraform/env_var_context.go.erb | 2 + .../examples/edgenetwork_network.tf.erb | 12 ++ .../examples/edgenetwork_subnet.tf.erb | 20 +++ .../edgenetwork_subnet_with_vlan_id.tf.erb | 22 +++ 7 files changed, 333 insertions(+) create mode 100644 mmv1/products/edgenetwork/Network.yaml create mode 100644 mmv1/products/edgenetwork/Subnet.yaml create mode 100644 mmv1/products/edgenetwork/product.yaml create mode 100644 mmv1/templates/terraform/examples/edgenetwork_network.tf.erb create mode 100644 mmv1/templates/terraform/examples/edgenetwork_subnet.tf.erb create mode 100644 mmv1/templates/terraform/examples/edgenetwork_subnet_with_vlan_id.tf.erb diff --git a/mmv1/products/edgenetwork/Network.yaml b/mmv1/products/edgenetwork/Network.yaml new file mode 100644 index 000000000000..6044713555d0 --- /dev/null +++ b/mmv1/products/edgenetwork/Network.yaml @@ -0,0 +1,97 @@ +# Copyright 2023 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:Api::Resource +name: 'Network' +description: | + A Distributed Cloud Edge network, which provides L3 isolation within a zone. +references: !ruby/object:Api::Resource::ReferenceLinks + api: 'https://cloud.google.com/distributed-cloud/edge/latest/docs/reference/network/rest/v1/projects.locations.zones.networks' + guides: + 'Create and manage networks': 'https://cloud.google.com/distributed-cloud/edge/latest/docs/networks#api' +base_url: 'projects/{{project}}/locations/{{location}}/zones/{{zone}}/networks' +self_link: 'projects/{{project}}/locations/{{location}}/zones/{{zone}}/networks/{{network_id}}' +create_url: 'projects/{{project}}/locations/{{location}}/zones/{{zone}}/networks?networkId={{network_id}}' +immutable: true +autogen_async: true +timeouts: !ruby/object:Api::Timeouts + delete_minutes: 30 +import_format: ['projects/{{project}}/locations/{{location}}/zones/{{zone}}/networks/{{network_id}}', '{{name}}'] +examples: + - !ruby/object:Provider::Terraform::Examples + name: 'edgenetwork_network' + primary_resource_id: 'example_network' + skip_test: true + vars: + edgenetwork_network_id: 'example-network' + test_env_vars: + location: :REGION + zone: :ZONE +parameters: + - !ruby/object:Api::Type::String + name: 'location' + required: true + immutable: true + url_param_only: true + description: | + The Google Cloud region to which the target Distributed Cloud Edge zone belongs. + - !ruby/object:Api::Type::String + name: 'zone' + required: true + immutable: true + url_param_only: true + description: | + The name of the target Distributed Cloud Edge zone. + - !ruby/object:Api::Type::String + name: 'network_id' + required: true + immutable: true + url_param_only: true + description: | + A unique ID that identifies this network. +properties: + - !ruby/object:Api::Type::String + name: 'name' + output: true + description: | + The canonical name of this resource, with format + `projects/{{project}}/locations/{{location}}/zones/{{zone}}/networks/{{network_id}}` + - !ruby/object:Api::Type::KeyValuePairs + name: 'labels' + required: false + description: | + Labels associated with this resource. + - !ruby/object:Api::Type::String + name: 'description' + required: false + description: | + A free-text description of the resource. Max length 1024 characters. + - !ruby/object:Api::Type::String + name: 'createTime' + output: true + description: | + The time when the subnet was created. + A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine + fractional digits. Examples: `2014-10-02T15:01:23Z` and `2014-10-02T15:01:23.045123456Z`. + - !ruby/object:Api::Type::String + name: 'updateTime' + output: true + description: | + The time when the subnet was last updated. + A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine + fractional digits. Examples: `2014-10-02T15:01:23Z` and `2014-10-02T15:01:23.045123456Z`. + - !ruby/object:Api::Type::Integer + name: 'mtu' + default_value: 1500 + description: | + IP (L3) MTU value of the network. Default value is `1500`. Possible values are: `1500`, `9000`. diff --git a/mmv1/products/edgenetwork/Subnet.yaml b/mmv1/products/edgenetwork/Subnet.yaml new file mode 100644 index 000000000000..8c0a6cfe9872 --- /dev/null +++ b/mmv1/products/edgenetwork/Subnet.yaml @@ -0,0 +1,138 @@ +# Copyright 2023 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:Api::Resource +name: 'Subnet' +description: | + A Distributed Cloud Edge subnet, which provides L2 isolation within a network. +references: !ruby/object:Api::Resource::ReferenceLinks + api: 'https://cloud.google.com/distributed-cloud/edge/latest/docs/reference/network/rest/v1/projects.locations.zones.subnets' + guides: + 'Create and manage subnetworks': 'https://cloud.google.com/distributed-cloud/edge/latest/docs/subnetworks#api' +base_url: 'projects/{{project}}/locations/{{location}}/zones/{{zone}}/subnets' +self_link: 'projects/{{project}}/locations/{{location}}/zones/{{zone}}/subnets/{{subnet_id}}' +create_url: 'projects/{{project}}/locations/{{location}}/zones/{{zone}}/subnets?subnetId={{subnet_id}}' +immutable: true +autogen_async: true +timeouts: !ruby/object:Api::Timeouts + delete_minutes: 30 +import_format: ['projects/{{project}}/locations/{{location}}/zones/{{zone}}/subnets/{{subnet_id}}', '{{name}}'] +examples: + - !ruby/object:Provider::Terraform::Examples + name: 'edgenetwork_subnet' + primary_resource_id: 'example_subnet' + skip_test: true + vars: + edgenetwork_subnet_id: 'example-subnet' + edgenetwork_network_id: 'example-network' + test_env_vars: + location: :REGION + zone: :ZONE + - !ruby/object:Provider::Terraform::Examples + name: 'edgenetwork_subnet_with_vlan_id' + primary_resource_id: 'example_subnet_with_vlan_id' + skip_test: true + vars: + edgenetwork_subnet_id: 'example-subnet-with-vlan-id' + edgenetwork_network_id: 'example-network' + test_env_vars: + location: :REGION + zone: :ZONE +parameters: + - !ruby/object:Api::Type::String + name: 'location' + required: true + immutable: true + url_param_only: true + description: | + The Google Cloud region to which the target Distributed Cloud Edge zone belongs. + - !ruby/object:Api::Type::String + name: 'zone' + required: true + immutable: true + url_param_only: true + description: | + The name of the target Distributed Cloud Edge zone. + - !ruby/object:Api::Type::String + name: 'subnet_id' + required: true + immutable: true + url_param_only: true + description: | + A unique ID that identifies this subnet. +properties: + - !ruby/object:Api::Type::String + name: 'name' + output: true + description: | + The canonical name of this resource, with format + `projects/{{project}}/locations/{{location}}/zones/{{zone}}/subnets/{{subnet_id}}` + - !ruby/object:Api::Type::KeyValuePairs + name: 'labels' + required: false + description: | + Labels associated with this resource. + - !ruby/object:Api::Type::String + name: 'description' + required: false + description: | + A free-text description of the resource. Max length 1024 characters. + - !ruby/object:Api::Type::String + name: 'createTime' + output: true + description: | + The time when the subnet was created. + A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine + fractional digits. Examples: `2014-10-02T15:01:23Z` and `2014-10-02T15:01:23.045123456Z`. + - !ruby/object:Api::Type::String + name: 'updateTime' + output: true + description: | + The time when the subnet was last updated. + A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine + fractional digits. Examples: `2014-10-02T15:01:23Z` and `2014-10-02T15:01:23.045123456Z`. + - !ruby/object:Api::Type::ResourceRef + name: 'network' + resource: 'Network' + imports: 'name' + required: true + custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.erb' + description: | + The ID of the network to which this router belongs. + Must be of the form: `projects/{{project}}/locations/{{location}}/zones/{{zone}}/networks/{{network_id}}` + - !ruby/object:Api::Type::Array + name: 'ipv4Cidr' + item_type: Api::Type::String + description: | + The ranges of ipv4 addresses that are owned by this subnetwork, in CIDR format. + - !ruby/object:Api::Type::Array + name: 'ipv6Cidr' + item_type: Api::Type::String + description: | + The ranges of ipv6 addresses that are owned by this subnetwork, in CIDR format. + - !ruby/object:Api::Type::Integer + name: 'vlanId' + default_from_api: true + description: | + VLAN ID for this subnetwork. If not specified, one is assigned automatically. + - !ruby/object:Api::Type::Enum + name: 'state' + output: true + values: + - :STATE_PENDING + - :STATE_PROVISIONING + - :STATE_RUNNING + - :STATE_SUSPENDED + - :STATE_DELETING + description: | + Current stage of the resource to the device by config push. diff --git a/mmv1/products/edgenetwork/product.yaml b/mmv1/products/edgenetwork/product.yaml new file mode 100644 index 000000000000..29be977b4df3 --- /dev/null +++ b/mmv1/products/edgenetwork/product.yaml @@ -0,0 +1,42 @@ +# Copyright 2023 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:Api::Product +name: Edgenetwork +display_name: Distributed Cloud Edge Network +versions: + - !ruby/object:Api::Product::Version + name: ga + base_url: https://edgenetwork.googleapis.com/v1/ +scopes: + - https://www.googleapis.com/auth/cloud-platform +apis_required: + - !ruby/object:Api::Product::ApiReference + name: Distributed Cloud Edge Network API + url: https://console.cloud.google.com/apis/library/edgenetwork.googleapis.com +async: !ruby/object:Api::OpAsync + operation: !ruby/object:Api::OpAsync::Operation + path: 'name' + base_url: '{{op_id}}' + wait_ms: 1000 + result: !ruby/object:Api::OpAsync::Result + path: 'response' + status: !ruby/object:Api::OpAsync::Status + path: 'done' + complete: true + allowed: + - true + - false + error: !ruby/object:Api::OpAsync::Error + path: 'error' + message: 'message' diff --git a/mmv1/templates/terraform/env_var_context.go.erb b/mmv1/templates/terraform/env_var_context.go.erb index de227f2d3ac6..55e0766acb25 100644 --- a/mmv1/templates/terraform/env_var_context.go.erb +++ b/mmv1/templates/terraform/env_var_context.go.erb @@ -25,5 +25,7 @@ "<%= var_name -%>": envvar.GetTestIdentityUserFromEnv(t), <% elsif var_type == :PAP_DESCRIPTION -%> "<%= var_name -%>": envvar.GetTestPublicAdvertisedPrefixDescriptionFromEnv(t), + <% elsif var_type == :ZONE -%> + "<%= var_name -%>": envvar.GetTestZoneFromEnv(), <% end -%> <% end -%> diff --git a/mmv1/templates/terraform/examples/edgenetwork_network.tf.erb b/mmv1/templates/terraform/examples/edgenetwork_network.tf.erb new file mode 100644 index 000000000000..f8e872cb5c16 --- /dev/null +++ b/mmv1/templates/terraform/examples/edgenetwork_network.tf.erb @@ -0,0 +1,12 @@ +resource "google_edgenetwork_network" "<%= ctx[:primary_resource_id] %>" { + network_id = "<%= ctx[:vars]['edgenetwork_network_id'] %>" + location = "<%= ctx[:test_env_vars]['location'] %>" + zone = "<%= ctx[:test_env_vars]['zone'] %>" + description = "Example network." + mtu = 9000 + labels = { + "environment" : "dev" + } +} + + diff --git a/mmv1/templates/terraform/examples/edgenetwork_subnet.tf.erb b/mmv1/templates/terraform/examples/edgenetwork_subnet.tf.erb new file mode 100644 index 000000000000..8d84feca775f --- /dev/null +++ b/mmv1/templates/terraform/examples/edgenetwork_subnet.tf.erb @@ -0,0 +1,20 @@ + +resource "google_edgenetwork_subnet" "<%= ctx[:primary_resource_id] %>" { + subnet_id = "<%= ctx[:vars]['edgenetwork_subnet_id'] %>" + location = "<%= ctx[:test_env_vars]['location'] %>" + zone = "<%= ctx[:test_env_vars]['zone'] %>" + description = "Example subnet." + network = google_edgenetwork_network.example_network.id + ipv4_cidr = ["4.4.4.1/24"] + labels = { + "environment" : "dev" + } +} + +resource "google_edgenetwork_network" "example_network" { + network_id = "<%= ctx[:vars]['edgenetwork_network_id'] %>" + location = "<%= ctx[:test_env_vars]['location'] %>" + zone = "<%= ctx[:test_env_vars]['zone'] %>" + description = "Example network." + mtu = 9000 +} diff --git a/mmv1/templates/terraform/examples/edgenetwork_subnet_with_vlan_id.tf.erb b/mmv1/templates/terraform/examples/edgenetwork_subnet_with_vlan_id.tf.erb new file mode 100644 index 000000000000..d8a6fc6018f7 --- /dev/null +++ b/mmv1/templates/terraform/examples/edgenetwork_subnet_with_vlan_id.tf.erb @@ -0,0 +1,22 @@ + +resource "google_edgenetwork_subnet" "<%= ctx[:primary_resource_id] %>" { + subnet_id = "<%= ctx[:vars]['edgenetwork_subnet_id'] %>" + location = "<%= ctx[:test_env_vars]['location'] %>" + zone = "<%= ctx[:test_env_vars]['zone'] %>" + description = "Example subnet with VLAN ID." + network = google_edgenetwork_network.example_network.id + ipv6_cidr = ["4444:4444:4444:4444::1/64"] + vlan_id = 44 + labels = { + "environment" : "dev" + } +} + +resource "google_edgenetwork_network" "example_network" { + network_id = "<%= ctx[:vars]['edgenetwork_network_id'] %>" + location = "<%= ctx[:test_env_vars]['location'] %>" + zone = "<%= ctx[:test_env_vars]['zone'] %>" + description = "Example network." + mtu = 9000 +} +