forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create resource gateway (GoogleCloudPlatform#7489)
* creating gateway resource * creating gateway basic test * adding update test and shipping only to beta * adapting the network services gateway terraform examples and tests * setting location to global because dynamic one is not working * adding serverTlsPolicy field in gateway properties * removing useless comments * changing gateway scopes for each test scenario * fixing PR comments: updating attributes in properties spec * allowing the location to be parametrized
- Loading branch information
1 parent
73fd153
commit 71c29a5
Showing
4 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# 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: 'Gateway' | ||
base_url: 'projects/{{project}}/locations/{{location}}/gateways' | ||
create_url: 'projects/{{project}}/locations/{{location}}/gateways?gatewayId={{name}}' | ||
self_link: 'projects/{{project}}/locations/{{location}}/gateways/{{name}}' | ||
min_version: beta | ||
update_verb: :PATCH | ||
update_mask: true | ||
description: | | ||
Gateway represents the configuration for a proxy, typically a load balancer. | ||
It captures the ip:port over which the services are exposed by the proxy, | ||
along with any policy configurations. Routes have reference to to Gateways | ||
to dictate how requests should be routed by this Gateway. | ||
references: !ruby/object:Api::Resource::ReferenceLinks | ||
api: 'https://cloud.google.com/traffic-director/docs/reference/network-services/rest/v1beta1/projects.locations.gateways' | ||
async: !ruby/object:Api::OpAsync | ||
operation: !ruby/object:Api::OpAsync::Operation | ||
path: 'name' | ||
base_url: '{{op_id}}' | ||
wait_ms: 1000 | ||
timeouts: !ruby/object:Api::Timeouts | ||
insert_minutes: 30 | ||
update_minutes: 30 | ||
delete_minutes: 30 | ||
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' | ||
autogen_async: true | ||
import_format: ['projects/{{project}}/locations/{{location}}/gateways/{{name}}'] | ||
examples: | ||
- !ruby/object:Provider::Terraform::Examples | ||
min_version: beta | ||
name: 'network_services_gateway_basic' | ||
primary_resource_id: 'default' | ||
vars: | ||
resource_name: 'my-gateway' | ||
- !ruby/object:Provider::Terraform::Examples | ||
min_version: beta | ||
name: 'network_services_gateway_advanced' | ||
primary_resource_id: 'default' | ||
vars: | ||
resource_name: 'my-gateway' | ||
parameters: | ||
- !ruby/object:Api::Type::String | ||
name: 'name' | ||
required: true | ||
url_param_only: true | ||
description: | | ||
Short name of the Gateway resource to be created. | ||
- !ruby/object:Api::Type::String | ||
name: 'location' | ||
default_value: 'global' | ||
description: | | ||
The location of the gateway. | ||
The default value is `global`. | ||
url_param_only: true | ||
properties: | ||
- !ruby/object:Api::Type::String | ||
name: 'selfLink' | ||
description: | | ||
Server-defined URL of this resource. | ||
output: true | ||
- !ruby/object:Api::Type::Time | ||
name: 'createTime' | ||
description: | | ||
Time the AccessPolicy was created in UTC. | ||
output: true | ||
- !ruby/object:Api::Type::Time | ||
name: 'updateTime' | ||
description: | | ||
Time the AccessPolicy was updated in UTC. | ||
output: true | ||
- !ruby/object:Api::Type::KeyValuePairs | ||
name: 'labels' | ||
description: Set of label tags associated with the Gateway resource. | ||
- !ruby/object:Api::Type::String | ||
name: 'description' | ||
description: | | ||
A free-text description of the resource. Max length 1024 characters. | ||
- !ruby/object:Api::Type::Enum | ||
name: 'type' | ||
required: true | ||
immutable: true | ||
description: | | ||
Immutable. The type of the customer-managed gateway. Possible values are: * OPEN_MESH * SECURE_WEB_GATEWAY. | ||
values: | ||
- :TYPE_UNSPECIFIED | ||
- :OPEN_MESH | ||
- :SECURE_WEB_GATEWAY | ||
- !ruby/object:Api::Type::Array | ||
name: 'ports' | ||
required: true | ||
immutable: true | ||
description: | | ||
One or more port numbers (1-65535), on which the Gateway will receive traffic. | ||
The proxy binds to the specified ports. Gateways of type 'SECURE_WEB_GATEWAY' are | ||
limited to 1 port. Gateways of type 'OPEN_MESH' listen on 0.0.0.0 and support multiple ports. | ||
item_type: Api::Type::Integer | ||
- !ruby/object:Api::Type::String | ||
name: 'scope' | ||
required: true | ||
description: | | ||
Immutable. Scope determines how configuration across multiple Gateway instances are merged. | ||
The configuration for multiple Gateway instances with the same scope will be merged as presented as | ||
a single coniguration to the proxy/load balancer. | ||
Max length 64 characters. Scope should start with a letter and can only have letters, numbers, hyphens. | ||
- !ruby/object:Api::Type::String | ||
name: 'serverTlsPolicy' | ||
description: | | ||
A fully-qualified ServerTLSPolicy URL reference. Specifies how TLS traffic is terminated. | ||
If empty, TLS termination is disabled. |
11 changes: 11 additions & 0 deletions
11
mmv1/templates/terraform/examples/network_services_gateway_advanced.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
resource "google_network_services_gateway" "<%= ctx[:primary_resource_id] %>" { | ||
provider = google-beta | ||
name = "<%= ctx[:vars]['resource_name'] %>" | ||
labels = { | ||
foo = "bar" | ||
} | ||
description = "my description" | ||
type = "OPEN_MESH" | ||
ports = [443] | ||
scope = "default-scope-advance" | ||
} |
7 changes: 7 additions & 0 deletions
7
mmv1/templates/terraform/examples/network_services_gateway_basic.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
resource "google_network_services_gateway" "<%= ctx[:primary_resource_id] %>" { | ||
provider = google-beta | ||
name = "<%= ctx[:vars]['resource_name'] %>" | ||
scope = "default-scope-basic" | ||
type = "OPEN_MESH" | ||
ports = [443] | ||
} |
69 changes: 69 additions & 0 deletions
69
mmv1/third_party/terraform/tests/resource_network_services_gateway_test.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<% autogen_exception -%> | ||
package google | ||
<% unless version == 'ga' -%> | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccNetworkServicesGateway_update(t *testing.T) { | ||
t.Parallel() | ||
|
||
gatewayName := fmt.Sprintf("tf-test-gateway-%s", RandString(t, 10)) | ||
|
||
VcrTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: TestAccProviders, | ||
CheckDestroy: testAccCheckNetworkServicesGatewayDestroyProducer(t), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccNetworkServicesGateway_basic(gatewayName), | ||
}, | ||
{ | ||
ResourceName: "google_network_services_gateway.foobar", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
{ | ||
Config: testAccNetworkServicesGateway_update(gatewayName), | ||
}, | ||
{ | ||
ResourceName: "google_network_services_gateway.foobar", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccNetworkServicesGateway_basic(gatewayName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_network_services_gateway" "foobar" { | ||
name = "%s" | ||
scope = "default-scope-update" | ||
type = "OPEN_MESH" | ||
ports = [443] | ||
description = "my description" | ||
} | ||
`, gatewayName) | ||
} | ||
|
||
func testAccNetworkServicesGateway_update(gatewayName string) string { | ||
return fmt.Sprintf(` | ||
resource "google_network_services_gateway" "foobar" { | ||
name = "%s" | ||
scope = "default-scope-update" | ||
type = "OPEN_MESH" | ||
ports = [443] | ||
description = "update description" | ||
labels = { | ||
foo = "bar" | ||
} | ||
} | ||
`, gatewayName) | ||
} | ||
|
||
<% end -%> |