apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: stackinstances.terraform.silvios.me
spec:
  group: terraform.silvios.me
  scope: Namespaced
  names:
    kind: StackInstance
    plural: stackinstances
    shortNames:
      - si
      - stack
      - stacks
  versions:
    - name: v1alpha1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              description: "Specification of the desired behavior of the StackInstance."
              properties:
                stack:
                  type: object
                  properties:
                    provider:
                      type: string
                      default: azurerm
                      description: "Terraform Provider. Example: google"
                      enum:
                        - aws
                        - azurerm
                        - cloudamqp
                        - google
                        - imperva
                        - mongodbatlas
                    backend:
                      type: string
                      default: azurerm
                      description: "Terraform Backend. Example: azurerm"
                      enum:
                        - azurerm
                        - gcs
                        - s3
                    registry:
                      type: string
                      default: azure
                      description: "Container Registry. Example: docker.io"
                    image:
                      type: string
                      description: "Stack Base Image Name. Example: silviosilva/google-bucket"
                    version:
                      type: string
                      description: "Stack Base Image Version. Example: 0.3.1"

                vars:
                  type: object
                  description: "Map of string keys that can be used to define the input variables and it's value."
                  x-kubernetes-preserve-unknown-fields: true

                outputs:
                  type: array
                  description: "Map of string keys that will be used to get values from JSON Outputs."
                  items:
                    type: string

            status:
              type: object
              properties:
                message:
                  type: string
                  default: "NOT READY"

      additionalPrinterColumns:
        - jsonPath: .spec.stack.provider
          name: Provider
          type: string

        - jsonPath: .spec.stack.backend
          name: Backend
          type: string

        - jsonPath: .spec.stack.image
          name: Image
          type: string

        - jsonPath: .spec.stack.version
          name: Version
          type: string

        - jsonPath: .metadata.creationTimestamp
          name: Age
          type: date

        - jsonPath: .status.message
          name: Status
          type: string
