Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoints service IAM #2318

Merged
merged 10 commits into from
Feb 13, 2020
38 changes: 38 additions & 0 deletions products/servicemanagement/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2020 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: Endpoints
display_name: Endpoints
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
40 changes: 40 additions & 0 deletions products/servicemanagement/terraform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2020 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
legacy_name: google_endpoints_service
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")}"
}
2 changes: 0 additions & 2 deletions third_party/terraform/utils/config.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ type Config struct {
clientIAP *iap.Service
<% end -%>

ServiceManagementBasePath string
clientServiceMan *servicemanagement.APIService

ServiceUsageBasePath string
Expand Down Expand Up @@ -681,7 +680,6 @@ func ConfigureBasePaths(c *Config) {
c.IamCredentialsBasePath = IamCredentialsDefaultBasePath
c.ResourceManagerV2Beta1BasePath = ResourceManagerV2Beta1DefaultBasePath
c.IAMBasePath = IAMDefaultBasePath
c.ServiceManagementBasePath = ServiceManagementDefaultBasePath
c.ServiceNetworkingBasePath = ServiceNetworkingDefaultBasePath
c.ServiceUsageBasePath = ServiceUsageDefaultBasePath
c.BigQueryBasePath = BigQueryDefaultBasePath
Expand Down
2 changes: 0 additions & 2 deletions third_party/terraform/utils/provider.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ func Provider() terraform.ResourceProvider {
ResourceManagerV2Beta1CustomEndpointEntryKey: ResourceManagerV2Beta1CustomEndpointEntry,
RuntimeConfigCustomEndpointEntryKey: RuntimeConfigCustomEndpointEntry,
IAMCustomEndpointEntryKey: IAMCustomEndpointEntry,
ServiceManagementCustomEndpointEntryKey: ServiceManagementCustomEndpointEntry,
ServiceNetworkingCustomEndpointEntryKey: ServiceNetworkingCustomEndpointEntry,
ServiceUsageCustomEndpointEntryKey: ServiceUsageCustomEndpointEntry,
CloudIoTCustomEndpointEntryKey: CloudIoTCustomEndpointEntry,
Expand Down Expand Up @@ -461,7 +460,6 @@ func providerConfigure(d *schema.ResourceData, p *schema.Provider, terraformVers
config.ResourceManagerV2Beta1BasePath = d.Get(ResourceManagerV2Beta1CustomEndpointEntryKey).(string)
config.RuntimeConfigBasePath = d.Get(RuntimeConfigCustomEndpointEntryKey).(string)
config.IAMBasePath = d.Get(IAMCustomEndpointEntryKey).(string)
config.ServiceManagementBasePath = d.Get(ServiceManagementCustomEndpointEntryKey).(string)
config.ServiceNetworkingBasePath = d.Get(ServiceNetworkingCustomEndpointEntryKey).(string)
config.ServiceUsageBasePath = d.Get(ServiceUsageCustomEndpointEntryKey).(string)
config.CloudIoTBasePath = d.Get(CloudIoTCustomEndpointEntryKey).(string)
Expand Down
11 changes: 0 additions & 11 deletions third_party/terraform/utils/provider_handwritten_endpoint.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,6 @@ var RuntimeConfigCustomEndpointEntry = &schema.Schema{
}, RuntimeConfigDefaultBasePath),
}

var ServiceManagementDefaultBasePath = "https://servicemanagement.googleapis.com/v1/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I think we do need to leave these in until 4.0.0 so that anyone that was setting the custom endpoint still can

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh gosh, I keep changing the product name to make the docs line up right but the product name also goes in here 🤦‍♂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by changing the docs to use the product's display name and moving the product that produces this IAM resource to use the same namespace as the existing handwritten one.

var ServiceManagementCustomEndpointEntryKey = "service_management_custom_endpoint"
var ServiceManagementCustomEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_SERVICE_MANAGEMENT_CUSTOM_ENDPOINT",
}, ServiceManagementDefaultBasePath),
}

var ServiceNetworkingDefaultBasePath = "https://servicenetworking.googleapis.com/v1/"
var ServiceNetworkingCustomEndpointEntryKey = "service_networking_custom_endpoint"
var ServiceNetworkingCustomEndpointEntry = &schema.Schema{
Expand Down
9 changes: 9 additions & 0 deletions third_party/terraform/website-compiled/google.erb
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,15 @@
<li<%%= sidebar_current("docs-google-endpoints-service") %>>
<a href="/docs/providers/google/r/endpoints_service.html">google_endpoints_service</a>
</li>
<li<%%= sidebar_current("docs-google-endpoints-service-iam") %>>
<a href="/docs/providers/google/r/endpoints_service_iam.html">google_endpoints_service_iam_binding</a>
</li>
<li<%%= sidebar_current("docs-google-endpoints-service-iam") %>>
<a href="/docs/providers/google/r/endpoints_service_iam.html">google_endpoints_service_iam_member</a>
</li>
<li<%%= sidebar_current("docs-google-endpoints-service-iam") %>>
<a href="/docs/providers/google/r/endpoints_service_iam.html">google_endpoints_service_iam_policy</a>
</li>
</ul>
</li>

Expand Down