From 383ce4fd1b6a6f77f21e00d7732e63d2d3bc5726 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 29 Mar 2021 14:57:21 -0700 Subject: [PATCH] Added data source monitoring istio canonical service (#4623) (#3092) Co-authored-by: franz-net Signed-off-by: Modular Magician Co-authored-by: franz-net --- .changelog/4623.txt | 3 + ...urce_monitoring_istio_canonical_service.go | 54 ++++++++++++ google-beta/provider.go | 1 + ...ring_istio_canonical_service.html.markdown | 84 +++++++++++++++++++ website/google.erb | 4 + 5 files changed, 146 insertions(+) create mode 100644 .changelog/4623.txt create mode 100644 google-beta/data_source_monitoring_istio_canonical_service.go create mode 100644 website/docs/d/monitoring_istio_canonical_service.html.markdown diff --git a/.changelog/4623.txt b/.changelog/4623.txt new file mode 100644 index 0000000000..f289dcf1f9 --- /dev/null +++ b/.changelog/4623.txt @@ -0,0 +1,3 @@ +```release-note:new-datasource +`google_monitoring_istio_canonical_service` +``` diff --git a/google-beta/data_source_monitoring_istio_canonical_service.go b/google-beta/data_source_monitoring_istio_canonical_service.go new file mode 100644 index 0000000000..0d7d18f6af --- /dev/null +++ b/google-beta/data_source_monitoring_istio_canonical_service.go @@ -0,0 +1,54 @@ +package google + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// No tests are added in this PR as currently there is no TF-supported method that can be used to +// enable either services (Cluster Istio, Mesh Istio and Istio Canonical Service) in GKE +func dataSourceMonitoringIstioCanonicalService() *schema.Resource { + csSchema := map[string]*schema.Schema{ + "mesh_uid": { + Type: schema.TypeString, + Required: true, + Description: `Identifier for the Istio mesh in which this canonical service is defined. + Corresponds to the meshUid metric label in Istio metrics.`, + }, + "canonical_service_namespace": { + Type: schema.TypeString, + Required: true, + Description: `The namespace of the canonical service underlying this service. + Corresponds to the destination_service_namespace metric label in Istio metrics.`, + }, + "canonical_service": { + Type: schema.TypeString, + Required: true, + Description: `The name of the canonical service underlying this service.. + Corresponds to the destination_service_name metric label in Istio metrics.`, + }, + } + t := `istio_canonical_service.mesh_uid="{{mesh_uid}}" AND + istio_canonical_service.canonical_service="{{canonical_service}}" AND + istio_canonical_service.canonical_service_namespace="{{canonical_service_namespace}}"` + return dataSourceMonitoringServiceType(csSchema, t, dataSourceMonitoringIstioCanonicalServiceRead) +} + +func dataSourceMonitoringIstioCanonicalServiceRead(res map[string]interface{}, d *schema.ResourceData, meta interface{}) error { + var istioCanonicalService map[string]interface{} + if v, ok := res["istio_canonical_service"]; ok { + istioCanonicalService = v.(map[string]interface{}) + } + if len(istioCanonicalService) == 0 { + return nil + } + if err := d.Set("canonical_service", istioCanonicalService["canonical_service"]); err != nil { + return err + } + if err := d.Set("canonical_service_namespace", istioCanonicalService["canonical_service_namespace"]); err != nil { + return err + } + if err := d.Set("mesh_name", istioCanonicalService["mesh_name"]); err != nil { + return err + } + return nil +} diff --git a/google-beta/provider.go b/google-beta/provider.go index 7205e3e064..83198a1393 100644 --- a/google-beta/provider.go +++ b/google-beta/provider.go @@ -804,6 +804,7 @@ func Provider() *schema.Provider { "google_folder_organization_policy": dataSourceGoogleFolderOrganizationPolicy(), "google_monitoring_notification_channel": dataSourceMonitoringNotificationChannel(), "google_monitoring_cluster_istio_service": dataSourceMonitoringServiceClusterIstio(), + "google_monitoring_istio_canonical_service": dataSourceMonitoringIstioCanonicalService(), "google_monitoring_mesh_istio_service": dataSourceMonitoringServiceMeshIstio(), "google_monitoring_app_engine_service": dataSourceMonitoringServiceAppEngine(), "google_monitoring_uptime_check_ips": dataSourceGoogleMonitoringUptimeCheckIps(), diff --git a/website/docs/d/monitoring_istio_canonical_service.html.markdown b/website/docs/d/monitoring_istio_canonical_service.html.markdown new file mode 100644 index 0000000000..79e6737db5 --- /dev/null +++ b/website/docs/d/monitoring_istio_canonical_service.html.markdown @@ -0,0 +1,84 @@ +--- +subcategory: "Cloud (Stackdriver) Monitoring" +layout: "google" +page_title: "Google: google_monitoring_istio_canonical_service" +sidebar_current: "docs-google-datasource-monitoring-istio-canonical-service" +description: |- + An Monitoring Service resource created automatically by GCP to monitor an + Istio Canonical service. +--- + +# google\_monitoring\_istio\_canonical\_service + +A Monitoring Service is the root resource under which operational aspects of a +generic service are accessible. A service is some discrete, autonomous, and +network-accessible unit, designed to solve an individual concern + +A monitoring Istio Canonical Service is automatically created by GCP to monitor +Istio Canonical Services. + + +To get more information about Service, see: + +* [API documentation](https://cloud.google.com/monitoring/api/ref_v3/rest/v3/services) +* How-to Guides + * [Service Monitoring](https://cloud.google.com/monitoring/service-monitoring) + * [Monitoring API Documentation](https://cloud.google.com/monitoring/api/v3/) + +## Example Usage - Monitoring Istio Canonical Service + + +```hcl +# Monitors the default MeshIstio service +data "google_monitoring_istio_canonical_service" "default" { + mesh_uid = "proj-573164786102" + canonical_service_namespace = "istio-system" + canonical_service = "prometheus" +} +``` + +## Argument Reference + +The arguments of this data source act as filters for identifying a given -created service. + +The given filters must match exactly one service whose data will be exported as attributes. The following arguments are supported: + +The following fields must be specified: + +* `mesh_uid` - (Required) Identifier for the mesh in which this Istio service is defined. + Corresponds to the meshUid metric label in Istio metrics. + +* `canonical_service_namespace` - (Required) The namespace of the canonical service underlying this service. + Corresponds to the destination_canonical_service_namespace metric label in Istio metrics. + +* `canonical_service` - (Required) The name of the canonical service underlying this service. + Corresponds to the destination_canonical_service_name metric label in label in Istio metrics. + +- - - + +Other optional fields include: + +* `project` - (Optional) The ID of the project in which the resource belongs. + If it is not provided, the provider project is used. + +## Attributes Reference + +In addition to the arguments listed above, the following computed attributes are exported: + +* `name` - + The full REST resource name for this channel. The syntax is: + `projects/[PROJECT_ID]/services/[SERVICE_ID]`. + +* `display_name` - + Name used for UI elements listing this (Monitoring) Service. + +* `telemetry` - + Configuration for how to query telemetry on the Service. Structure is documented below. + +The `telemetry` block includes: + +* `resource_name` - + (Optional) + The full name of the resource that defines this service. + Formatted as described in + https://cloud.google.com/apis/design/resource_names. diff --git a/website/google.erb b/website/google.erb index 0a78e06356..03e546b154 100644 --- a/website/google.erb +++ b/website/google.erb @@ -486,6 +486,10 @@ google_monitoring_cluster_istio_service +
  • + google_monitoring_istio_canonical_service +
  • +
  • google_monitoring_mesh_istio_service