# Copyright 2021 Google LLC
#
# 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
#
#     https://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.

# Cloud SQL Proxy makes requests to `www.googleapis.com`
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: sql
  namespace: accounts
spec:
  hosts:
  - sql-component.googleapis.com
  ports:
  - number: 443
    name: https
    protocol: HTTPS
  - number: 80
    name: http
    protocol: HTTP
  resolution: DNS
  location: MESH_EXTERNAL
---
# see https://istio.io/blog/2018/egress-tcp/
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: cloud-sql-instance
  namespace: accounts
spec:
  # use `gcloud sql instances list --project ${SQL_PROJECT_ID}` and include replicas as well
  hosts:
  - boa-sql-2-d-us-west1-73f70f52-replica-example0
  - boa-sql-1-d-us-east1-3976a685-replica-example1
  - boa-sql-2-d-us-west1-73f70f52-replica-example1
  - boa-sql-1-d-us-east1-3976a685-replica-example0
  - boa-sql-1-d-us-east1-3976a685
  - boa-sql-2-d-us-west1-73f70f52
  addresses:
  # use `gcloud sql instances list --project ${SQL_PROJECT_ID}` to find out the IP address of your Google Cloud Instance
  - 10.16.66.13/32 # a single IP in CIDR notation
  - 10.16.66.16/32
  - 10.16.66.17/32
  - 10.16.66.12/32
  - 10.16.64.5/32
  - 10.16.65.5/32
  ports:
  - name: tcp
    number: 3307
    protocol: tcp # enable TCP traffic
  location: MESH_EXTERNAL
