# Copyright 2020 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
#
#     http://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.
apiVersion: iam.cnrm.cloud.google.com/v1beta1
kind: IAMPolicyMember
metadata:
  name: sql-sa-iam-roles-storageadmin
  namespace: CHANGE-NAMESPACE
  annotations:
    cnrm.cloud.google.com/blueprint: kpt-fn-live
    config.kubernetes.io/apply-time-mutation: |
      - sourceRef:
          apiVersion: sql.cnrm.cloud.google.com/v1beta1
          kind: SQLInstance
          name: sql-instance
          namespace: cloud-sql-kcc
        sourcePath: $.status.serviceAccountEmailAddress
        targetPath: $.spec.member
        token: ${sql-sa}
spec:
  member: serviceAccount:${sql-sa}
  role: roles/storage.admin
  resourceRef:
    apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1
    kind: Project
    external: CHANGE-PROJECTID # kpt-set: ${project-id}
---
apiVersion: iam.cnrm.cloud.google.com/v1beta1
kind: IAMPolicyMember
metadata:
  name: sql-sa-iam-roles-objectadmin
  namespace: CHANGE-NAMESPACE
  annotations:
    cnrm.cloud.google.com/blueprint: kpt-fn-live
    config.kubernetes.io/apply-time-mutation: |
      - sourceRef:
          apiVersion: sql.cnrm.cloud.google.com/v1beta1
          kind: SQLInstance
          name: sql-instance
          namespace: cloud-sql-kcc
        sourcePath: $.status.serviceAccountEmailAddress
        targetPath: $.spec.member
        token: ${sql-sa}
spec:
  member: serviceAccount:${sql-sa}
  role: roles/storage.objectAdmin
  resourceRef:
    apiVersion: resourcemanager.cnrm.cloud.google.com/v1beta1
    kind: Project
    external: CHANGE-PROJECTID # kpt-set: ${project-id}
