# Copyright (c) 2026 VirtRigaud Creators
# SPDX-License-Identifier: Apache-2.0

# The vCenter account these credentials belong to needs, among the usual VM
# provisioning privileges, "Virtual machine > Change Configuration > Advanced
# configuration" (VirtualMachine.Config.AdvancedConfig): every VirtRigaud create
# writes an ExtraConfig owner stamp. See docs/vm-ownership.md.
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
  name: vsphere-credentials
  namespace: virtrigaud-system
spec:
  refreshInterval: 1h
  secretStoreRef:
    name: vault-secret-store
    kind: SecretStore
  target:
    name: vsphere-credentials
    creationPolicy: Owner
    template:
      type: Opaque
      metadata:
        labels:
          virtrigaud.io/credential-type: vsphere
        annotations:
          virtrigaud.io/auto-rotation: "true"
      data:
        endpoint: "{{ .endpoint }}"
        username: "{{ .username }}"
        password: "{{ .password }}"
        insecure: '{{ .insecure | default "false" }}'
  data:
  - secretKey: endpoint
    remoteRef:
      key: infrastructure/vsphere
      property: endpoint
  - secretKey: username
    remoteRef:
      key: infrastructure/vsphere
      property: username
  - secretKey: password
    remoteRef:
      key: infrastructure/vsphere
      property: password
  - secretKey: insecure
    remoteRef:
      key: infrastructure/vsphere
      property: insecure
---
apiVersion: external-secrets.io/v1beta1
kind: SecretStore
metadata:
  name: vault-secret-store
  namespace: virtrigaud-system
spec:
  provider:
    vault:
      server: "https://vault.example.com"
      path: "secret"
      version: "v2"
      auth:
        kubernetes:
          mountPath: "kubernetes"
          role: "virtrigaud"
          serviceAccountRef:
            name: virtrigaud-external-secrets
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: virtrigaud-external-secrets
  namespace: virtrigaud-system
  annotations:
    vault.hashicorp.com/role: "virtrigaud"
