From 6356ce628c7d1a4016ace335f6091473e12d8d74 Mon Sep 17 00:00:00 2001 From: Lorenzo Caggioni Date: Wed, 24 Jun 2020 15:52:30 +0200 Subject: [PATCH] Fixes based on comments on the PR --- modules/endpoint/README.md | 9 ++++----- modules/endpoint/main.tf | 16 +++------------- modules/endpoint/variables.tf | 21 +++++++++------------ 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/modules/endpoint/README.md b/modules/endpoint/README.md index c61b00a52..5ae3195dd 100644 --- a/modules/endpoint/README.md +++ b/modules/endpoint/README.md @@ -19,26 +19,25 @@ module "endpoint" { } ``` -[Here](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/endpoints/getting-started/openapi.yaml) you can find an example of an openapi.yaml file. +[Here](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/endpoints/getting-started/openapi.yaml) you can find an example of an openapi.yaml file. Once created the endpoint, remember to activate the service at project level. ## Variables | name | description | type | required | default | |---|---|:---: |:---:|:---:| +| grpc_config | The configuration for a gRPC enpoint. Either this, openapi_config must be specified. | object({...}) | ✓ | | +| openapi_config | The configuration for an OpenAPI endopoint. Either this, grpc_config must be specified. | object({...}) | ✓ | | | service_name | The name of the service. Usually of the form '$apiname.endpoints.$projectid.cloud.goog'. | string | ✓ | | -| *grpc_config* | The path to the full text of the Service Config YAML file. | string | | null | | *iam_members* | Authoritative for a given role. Updates the IAM policy to grant a role to a list of members. Other roles within the IAM policy for the instance are preserved. | map(list(string)) | | {} | | *iam_roles* | Authoritative for a given role. Updates the IAM policy to grant a role to a list of members. | list(string) | | [] | -| *openapi_config* | The path to the full text of the OpenAPI YAML configuration. Either this, or both of grpc_config and protoc_output_base64 must be specified. | string | | null | | *project_id* | The project ID that the service belongs to. | string | | null | -| *protoc_output_base64* | The path to the full contents of the Service Descriptor File generated by protoc. | string | | null | ## Outputs | name | description | sensitive | |---|---|:---:| -| endpoint_service | The Endpoint service resource. | | | endpoints | A list of Endpoint objects. | | +| endpoints_service | The Endpoint service resource. | | | service_name | The name of the service.. | | diff --git a/modules/endpoint/main.tf b/modules/endpoint/main.tf index 6bb96670b..1b9cedbe0 100644 --- a/modules/endpoint/main.tf +++ b/modules/endpoint/main.tf @@ -23,23 +23,13 @@ locals { resource "google_endpoints_service" "default" { project = var.project_id service_name = var.service_name - - openapi_config = var.openapi_config != null ? file(var.openapi_config) : null - grpc_config = var.grpc_config != null ? file(var.grpc_config) : null - - protoc_output_base64 = var.protoc_output_base64 != null ? base64encode(file(var.protoc_output_base64)) : null -} - -resource "google_project_service" "default" { - project = var.project_id - service = google_endpoints_service.default.service_name - disable_on_destroy = true - disable_dependent_services = true + openapi_config = var.openapi_config != null ? file(var.openapi_config.yaml_path) : null + grpc_config = var.grpc_config != null ? file(var.grpc_config.yaml_path) : null + protoc_output_base64 = var.grpc_config != null ? base64encode(file(var.grpc_config.protoc_output_path)) : null } resource "google_endpoints_service_iam_binding" "default" { for_each = local.iam_roles_bindings - service_name = google_endpoints_service.default.service_name role = "roles/${each.key}" members = each.value diff --git a/modules/endpoint/variables.tf b/modules/endpoint/variables.tf index 93a534bab..8ece3e76c 100644 --- a/modules/endpoint/variables.tf +++ b/modules/endpoint/variables.tf @@ -15,9 +15,11 @@ */ variable "grpc_config" { - description = "The path to the full text of the Service Config YAML file." - type = string - default = null + description = "The configuration for a gRPC enpoint. Either this, openapi_config must be specified." + type = object({ + yaml_path = string + protoc_output_path = string + }) } variable "iam_roles" { @@ -33,9 +35,10 @@ variable "iam_members" { } variable "openapi_config" { - description = "The path to the full text of the OpenAPI YAML configuration. Either this, or both of grpc_config and protoc_output_base64 must be specified." - type = string - default = null + description = "The configuration for an OpenAPI endopoint. Either this, grpc_config must be specified." + type = object({ + yaml_path = string + }) } variable "project_id" { @@ -44,12 +47,6 @@ variable "project_id" { default = null } -variable "protoc_output_base64" { - description = "The path to the full contents of the Service Descriptor File generated by protoc." - type = string - default = null -} - variable "service_name" { description = "The name of the service. Usually of the form '$apiname.endpoints.$projectid.cloud.goog'." type = string