{{- if .Values.rbac.create }}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
  name: {{ template "appmesh-gateway.fullname" . }}
  labels:
{{ include "appmesh-gateway.labels" . | indent 4 }}
rules:
  - apiGroups:
      - ""
    resources:
      - services
    verbs: ["*"]
  - apiGroups:
      - appmesh.k8s.aws
    resources:
      - meshes
      - meshes/status
      - virtualnodes
      - virtualnodes/status
      - virtualservices
      - virtualservices/status
    verbs: ["*"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: {{ template "appmesh-gateway.fullname" . }}
  labels:
{{ include "appmesh-gateway.labels" . | indent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ template "appmesh-gateway.fullname" . }}
subjects:
- name: {{ template "appmesh-gateway.serviceAccountName" . }}
  namespace: {{ .Release.Namespace }}
  kind: ServiceAccount
{{- end }}
