Skip to content

Commit

Permalink
Add configuration for traffic director serviceBinding resource (Googl…
Browse files Browse the repository at this point in the history
…eCloudPlatform#7605)

* Configuration for traffic director Mesh resource.

* Add more tests for Mesh resource

* Use new provider for test

* Configuration for service binding.

* Add hand written test for service binding.

* Revert "Add hand written test for service binding."

This reverts commit 367449a.

* Update service binding yaml.

* reduce timeouts.

* Update mmv1/products/networkservices/ServiceBinding.yaml

Co-authored-by: Sam Levenick <slevenick@google.com>

* Service binding update test.

* Fix compile error.

* Mark the Service Binding resource immutable.

---------

Co-authored-by: Madhura Phadnis <madhurap@google.com>
Co-authored-by: Sam Levenick <slevenick@google.com>
  • Loading branch information
3 people committed Apr 21, 2023
1 parent 4f6a2e7 commit 924ded3
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 0 deletions.
87 changes: 87 additions & 0 deletions mmv1/products/networkservices/ServiceBinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# 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: 'ServiceBinding'
base_url: 'projects/{{project}}/locations/global/serviceBindings'
create_url: 'projects/{{project}}/locations/global/serviceBindings?serviceBindingId={{name}}'
min_version: beta
description: |
ServiceBinding is the resource that defines a Service Directory Service to be used in a
BackendService resource.
immutable: true
references: !ruby/object:Api::Resource::ReferenceLinks
api: 'https://cloud.google.com/traffic-director/docs/reference/network-services/rest/v1beta1/projects.locations.serviceBindings'
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: 10
update_minutes: 10
delete_minutes: 10
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/global/serviceBindings/{{name}}']
examples:
- !ruby/object:Provider::Terraform::Examples
min_version: beta
name: 'network_services_service_binding_basic'
primary_resource_id: 'default'
vars:
resource_name: 'my-service-binding'
namespace_id: 'my-namespace'
service_id: 'my-service'
parameters:
- !ruby/object:Api::Type::String
name: 'name'
required: true
url_param_only: true
description: |
Name of the ServiceBinding resource.
properties:
- !ruby/object:Api::Type::Time
name: 'createTime'
description: |
Time the ServiceBinding was created in UTC.
output: true
- !ruby/object:Api::Type::Time
name: 'updateTime'
description: |
Time the ServiceBinding was updated in UTC.
output: true
- !ruby/object:Api::Type::KeyValuePairs
name: 'labels'
description: Set of label tags associated with the ServiceBinding resource.
- !ruby/object:Api::Type::String
name: 'description'
description: |
A free-text description of the resource. Max length 1024 characters.
- !ruby/object:Api::Type::String
name: 'service'
required: true
description: |
The full Service Directory Service name of the format
projects/*/locations/*/namespaces/*/services/*
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
resource "google_service_directory_namespace" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
namespace_id = "<%= ctx[:vars]["namespace_id"] %>"
location = "us-central1"
}

resource "google_service_directory_service" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
service_id = "<%= ctx[:vars]["service_id"] %>"
namespace = google_service_directory_namespace.<%= ctx[:primary_resource_id] %>.id

metadata = {
stage = "prod"
region = "us-central1"
}
}

resource "google_network_services_service_binding" "<%= ctx[:primary_resource_id] %>" {
provider = google-beta
name = "<%= ctx[:vars]['resource_name'] %>"
labels = {
foo = "bar"
}
description = "my description"
service = google_service_directory_service.<%= ctx[:primary_resource_id] %>.id
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<% autogen_exception -%>
package google
<% unless version == 'ga' -%>

import (
"fmt"
"testing"

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

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

serviceNamespace := fmt.Sprintf("tf-test-service-namespace-%s", RandString(t, 10))
serviceName := fmt.Sprintf("tf-test-service-%s", RandString(t, 10))
serviceBindingName := fmt.Sprintf("tf-test-service-binding-%s", RandString(t, 10))

VcrTest(t, resource.TestCase{
PreCheck: func() { AccTestPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckNetworkServicesServiceBindingDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccNetworkServicesServiceBinding_create(serviceNamespace, serviceName, serviceBindingName),
},
{
ResourceName: "google_network_services_service_binding.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccNetworkServicesServiceBinding_create(serviceNamespace string, serviceName string, serviceBindingName string) string {
return fmt.Sprintf(`

resource "google_service_directory_namespace" "foo" {
namespace_id = "%s"
location = "us-central1"
}
resource "google_service_directory_service" "bar" {
service_id = "%s"
namespace = google_service_directory_namespace.foo.id

metadata = {
stage = "prod"
region = "us-central1"
}
}
resource "google_network_services_service_binding" "foobar" {
name = "%s"
description = "my description"
service = google_service_directory_service.bar.id
}
`, serviceNamespace, serviceName, serviceBindingName)
}

<% end -%>

0 comments on commit 924ded3

Please sign in to comment.