resource "kubectl_manifest" "ClusterRole_multus" {
  yaml_body  = <<-EOF
    kind: ClusterRole
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: multus
      ownerReferences: ${jsonencode(var.install_owner)}
      labels: ${jsonencode(local.common-labels)}
    rules:
    - apiGroups:
      - k8s.cni.cncf.io
      resources:
      - '*'
      verbs:
      - '*'
    - apiGroups:
      - ''
      resources:
      - pods
      - pods/status
      verbs:
      - get
      - update
    - apiGroups:
      - ''
      - events.k8s.io
      resources:
      - events
      verbs:
      - create
      - patch
      - update
EOF
}

resource "kubectl_manifest" "ClusterRoleBinding_multus" {
  yaml_body  = <<-EOF
    kind: ClusterRoleBinding
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: multus
      ownerReferences: ${jsonencode(var.install_owner)}
      labels: ${jsonencode(local.common-labels)}
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: multus
    subjects:
    - kind: ServiceAccount
      name: multus
      namespace:  ${var.namespace}
EOF
}

resource "kubectl_manifest" "ServiceAccount_multus" {
  yaml_body  = <<-EOF
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: multus
      namespace: ${var.namespace}
      ownerReferences: ${jsonencode(var.install_owner)}
      labels: ${jsonencode(local.common-labels)}
EOF
}

