Skip to content

Commit

Permalink
Add endpoints service IAM
Browse files Browse the repository at this point in the history
  • Loading branch information
slevenick committed Sep 14, 2019
1 parent c8c9212 commit 489f02d
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
40 changes: 40 additions & 0 deletions products/endpoints/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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.

# TODO(nelsonjr): Make all Zone and Region resource ref

--- !ruby/object:Api::Product
name: Endpoints
display_name: Endpoints Service
versions:
- !ruby/object:Api::Product::Version
name: ga
base_url: https://servicemanagement.googleapis.com/v1/
scopes:
- https://www.googleapis.com/auth/cloudplatform
apis_required:
- !ruby/object:Api::Product::ApiReference
name: Service Management API
url: https://console.cloud.google.com/apis/library/servicemanagement.googleapis.com/
objects:
- !ruby/object:Api::Resource
name: 'Service'
base_url: services
self_link: services/{{serviceName}}
description: |
A service that is managed by Google Service Management
properties:
- !ruby/object:Api::Type::String
name: 'serviceName'
description: The name of the service.
required: true
39 changes: 39 additions & 0 deletions products/endpoints/terraform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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.

--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
Service: !ruby/object:Overrides::Terraform::ResourceOverride
id_format: 'services/{{serviceName}}'
import_format: ["services/{{serviceName}}"]
exclude_resource: true
iam_policy: !ruby/object:Api::Resource::IamPolicy
parent_resource_attribute: 'service_name'
method_name_separator: ':'
fetch_iam_policy_verb: :POST
exclude: false
examples:
- !ruby/object:Provider::Terraform::Examples
name: "endpoints_iam"
primary_resource_id: "endpoints_service"
primary_resource_name: "fmt.Sprintf(\"endpoint%s.endpoints.%s.cloud.goog\", context[\"random_suffix\"], context[\"project_name\"])"
vars:
name: "endpoint"
test_env_vars:
project_name: :PROJECT_NAME
# This is for copying files over
files: !ruby/object:Provider::Config::Files
# These files have templating (ERB) code that will be run.
# This is usually to add licensing info, autogeneration notices, etc.
compile:
<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%>
14 changes: 14 additions & 0 deletions templates/terraform/examples/endpoints_iam.tf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "google_endpoints_service" "<%= ctx[:primary_resource_id] %>" {
service_name = "<%= ctx[:vars]["name"] %>.endpoints.<%= ctx[:test_env_vars]["project_name"] %>.cloud.goog"
project = "<%= ctx[:test_env_vars]["project_name"] %>"
grpc_config = <<EOF
type: google.api.Service
config_version: 3
name: <%= ctx[:vars]["name"] %>.endpoints.<%= ctx[:test_env_vars]["project_name"] %>.cloud.goog
usage:
rules:
- selector: endpoints.examples.bookstore.Bookstore.ListShelves
allow_unregistered_calls: true
EOF
protoc_output_base64 = "${filebase64("test-fixtures/test_api_descriptor.pb")}"
}
3 changes: 3 additions & 0 deletions templates/terraform/iam/iam_context.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ context := map[string]interface{}{
<% if var_type == :ORG_ID -%>
"<%= var_name -%>": getTestOrgFromEnv(t),
<% end -%>
<% if var_type == :PROJECT_NAME -%>
"<%= var_name -%>": getTestProjectFromEnv(),
<% end -%>
<% end -%>
<% unless example.test_custom_context.nil? -%>
<% example.test_custom_context.each do |var_name, custom_val| -%>
Expand Down

0 comments on commit 489f02d

Please sign in to comment.