Skip to content

Commit

Permalink
urlLists into network services (GoogleCloudPlatform#7592)
Browse files Browse the repository at this point in the history
  • Loading branch information
diogoEsteves42 authored and hao-nan-li committed Apr 11, 2023
1 parent d99948a commit 07c6aa8
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 0 deletions.
103 changes: 103 additions & 0 deletions mmv1/products/networksecurity/UrlLists.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# 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: "UrlLists"
base_url: "projects/{{project}}/locations/{{location}}/urlLists"
create_url: "projects/{{project}}/locations/{{location}}/urlLists?urlListId={{name}}"
self_link: "projects/{{project}}/locations/{{location}}/urlLists/{{name}}"
min_version: beta
update_verb: :PATCH
update_mask: true
description: |
UrlList proto helps users to set reusable, independently manageable lists of hosts, host patterns, URLs, URL patterns.
references:
!ruby/object:Api::Resource::ReferenceLinks # TODO(diogoesteves): change the url to beta once it is available.
guides:
"Use UrlLists": " https://cloud.google.com/secure-web-proxy/docs/use-url-list"
api: "https://cloud.google.com/secure-web-proxy/docs/reference/network-security/rest/v1alpha1/projects.locations.urlLists"
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}}/urlLists/{{name}}"]
examples:
- !ruby/object:Provider::Terraform::Examples
min_version: beta
name: "network_security_url_lists_basic"
primary_resource_id: "default"
vars:
resource_name: "my-url-lists"
- !ruby/object:Provider::Terraform::Examples
min_version: beta
name: "network_security_url_lists_advanced"
primary_resource_id: "default"
vars:
resource_name: "my-url-lists"
parameters:
- !ruby/object:Api::Type::String
name: "name"
required: true
url_param_only: true
description: |
Short name of the UrlList resource to be created.
This value should be 1-63 characters long, containing only letters, numbers, hyphens, and underscores, and should not start with a number. E.g. 'urlList'.
- !ruby/object:Api::Type::String
name: "location"
required: true
description: |
The location of the url lists.
url_param_only: true
properties:
- !ruby/object:Api::Type::Time
name: "createTime"
description: |
Output only. Time when the security policy 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'
output: true
- !ruby/object:Api::Type::Time
name: "updateTime"
description: |
Output only. Time when the security policy was 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'.
output: true
- !ruby/object:Api::Type::String
name: "description"
description: |
Free-text description of the resource.
- !ruby/object:Api::Type::Array
name: "values"
item_type: Api::Type::String
required: true
description: |
FQDNs and URLs.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "google_network_security_url_lists" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
name = "<%= ctx[:vars]['resource_name'] %>"
location = "us-central1"
description = "my description"
values = ["www.example.com", "about.example.com", "github.com/example-org/*"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "google_network_security_url_lists" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
name = "<%= ctx[:vars]['resource_name'] %>"
location = "us-central1"
values = ["www.example.com"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<% autogen_exception -%>
package google
<% unless version == 'ga' -%>

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccNetworkSecurityUrlLists_update(t *testing.T){
t.Parallel()

urlListsName := fmt.Sprintf("tf-test-url-lists-%s", RandString(t, 10))

VcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckNetworkSecurityUrlListsDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccNetworkSecurityUrlLists_basic(urlListsName),
},
{
ResourceName: "google_network_security_url_lists.foobar",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccNetworkSecurityUrlLists_update(urlListsName),
},
{
ResourceName: "google_network_security_url_lists.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccNetworkSecurityUrlLists_basic(urlListsName string) string {
return fmt.Sprintf(`
resource "google_network_security_url_lists" "foobar" {
name = "%s"
location = "us-central1"
values = ["www.example.com"]
}
`, urlListsName)
}

func testAccNetworkSecurityUrlLists_update(urlListsName string) string {
return fmt.Sprintf(`
resource "google_network_security_url_lists" "foobar" {
name = "%s"
location = "us-central1"
description = "my description"
values = ["www.example.com", "about.example.com", "github.com/example-org/*"]
}
`, urlListsName)
}

<% end -%>

0 comments on commit 07c6aa8

Please sign in to comment.