apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
  name: mesh-route-outbound-traffic-to-external-svc-via-egress-gw
spec:
  hosts:
  - external.{{ .externalNamespace }}.svc.cluster.local
  gateways:
  - mesh
  tcp:
  - match:
    - port: {{ .externalSvcTcpPort }}
    route:
    - destination:
        host: {{ .EgressGatewayServiceName | default "istio-egressgateway" }}.{{ .EgressGatewayServiceNamespace | default "istio-system" }}.svc.cluster.local
        subset: originate-tls-for-plain-traffic
        port:
          number: 443
  tls:
  - match:
    - port: {{ .externalSvcTlsPort }}
      sniHosts:
      - external.{{ .externalNamespace }}.svc.cluster.local
    route:
    - destination:
        host: {{ .EgressGatewayServiceName | default "istio-egressgateway" }}.{{ .EgressGatewayServiceNamespace | default "istio-system" }}.svc.cluster.local
        port:
          number: 443
---
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
  name: egress-gw-route-outbound-traffic-to-external-svc-via-external-forward-proxy
spec:
  hosts:
  - external.{{ .externalNamespace }}.svc.cluster.local
  gateways:
  - {{ .EgressGatewayServiceName | default "istio-egressgateway" }}
  tls:
  - match:
    - gateways:
      - {{ .EgressGatewayServiceName | default "istio-egressgateway" }}
      port: 443
      sniHosts:
      - external.{{ .externalNamespace }}.svc.cluster.local
    route:
    - destination:
        host: external-forward-proxy.{{ .externalNamespace }}.svc.cluster.local
        subset: external-svc-tls
        port:
          number: {{ .forwardProxyPort }}
