apiVersion: xl/v1
kind: Blueprint

metadata:
  projectName: Azure-Microservice-AKS-with-JHipster
  description: |
    The blueprint deploys an e-commerce microservice application to Azure AKS.
    XL Deploy does the provisioning and deployment, while XL Release orchestrates everything.
  author: XebiaLabs
  version: 1.0
  instructions: Please read the generated file "xebialabs/USAGE.md" for further usage instructions.

spec:
  parameters:
  - name: AppName
    type: Input
    description: What do you want to name the application?

  - name: ProvisionCluster
    type: Confirm
    description: Do you want to provision a new Azure AKS cluster?

  # ############################################################################
  # Own cluster
  # ############################################################################
  - name: ClusterEndpoint
    type: Input
    description: What is the endpoint for the existing cluster, example https://104.155.109.230
    dependsOnTrue: !expression "!ProvisionCluster"

  - name: PasswordToken
    type: Input
    description: What is the token for accessing the existing cluster
    dependsOnTrue: !expression "!ProvisionCluster"
    secret: true
  # ############################################################################

  # ############################################################################
  # New cluster
  # ############################################################################
  - name: AKSRegion
    type: Select
    description: "Select the AKS region for the cluster:"
    dependsOnTrue: ProvisionCluster
    options:
    - eastasia
    - southeastasia
    - centralus
    - eastus
    - eastus2
    - westus
    - northcentralus
    - southcentralus
    - northeurope
    - westeurope
    - japanwest
    - japaneast
    - brazilsouth
    - australiaeast
    - australiasoutheast
    - southindia
    - centralindia
    - westindia
    - canadacentral
    - canadaeast
    - uksouth
    - ukwest
    - westcentralus
    - westus2
    - koreacentral
    - koreasouth
    - francecentral
    - francesouth
    - australiacentral
    - australiacentral2
    - southafricanorth
    - southafricawest

    # ############################################################################
  # Authentication
  # ############################################################################
  - name: SubscriptionID
    type: Input
    description: "Enter you Azure subscription id:"
    dependsOnTrue: ProvisionCluster

  - name: TenantID
    type: Input
    description: "Enter your Azure tenant id:"
    dependsOnTrue: ProvisionCluster

  - name: ClientID
    type: Input
    description: "Enter your Azure client id:"
    dependsOnTrue: ProvisionCluster

  - name: ClientSecret
    type: Input
    description: "Enter your Azure client secret:"
    secret: true
    dependsOnTrue: ProvisionCluster

  # ############################################################################
  # For the Terraform backend storage
  # ############################################################################
  - name: ResourceGroup
    # Resource group names only allow alphanumeric characters, periods, underscores, hyphens and parenthesis and cannot end in a period
    type: Input
    description: "The blueprint will create a new Resource Group for the cluster. Please supply a name:"
    pattern: "[\\w._()-]{2,50}[\\w_()-]"
    dependsOnTrue: ProvisionCluster

  - name: StorageAccountName
    type: Input
    description: "Enter the Storage Account where Terraform will store its state (see README.md step 3.2):"
    dependsOnTrue: ProvisionCluster

  - name: StorageAccessKey
    type: Input
    description: "Enter the Storage Account key for accessing the storage (see README.md step 3.3):"
    dependsOnTrue: ProvisionCluster

  - name: StorageContainerName
    type: Input
    description: "Enter the Storage Container name (see README.md step 3.4):"
    default: terraform-state
    dependsOnTrue: ProvisionCluster
  # ############################################################################

  - name: ClusterName
    type: Input
    description: What name do you want to give the cluster?
    pattern: "[a-zA-Z][\\w-]{1,29}[\\w]"
    # dependsOnTrue: ProvisionCluster

  - name: Namespace
    type: Input
    value: xl-demo

  - name: XLDUrlForXLR
    type: Input
    description: XL Deploy URL for XL Release (This will only be used in the XL Release template)
    default: http://xl-deploy:4516

  # ############################################################################
  # Jenkins
  # ############################################################################
  - name: enableCICD
    type: Confirm
    description: Do you want to enable CI/CD integration with Jenkins?

  - name: StoreAdminUsername
    type: Input
    description: Store Admin username
    value: admin

  - name: StoreAdminPassword
    type: Input
    description: Store Admin password
    value: admin
    secret: true
  # ############################################################################

  files:
  - path: xebialabs.yaml
  - path: README.md
  - path: xebialabs/xld-infra-env.yaml.tmpl
  - path: xebialabs/xld-terraform-apps.yaml.tmpl
  - path: xebialabs/xld-kubernetes-invoice-app.yaml.tmpl
  - path: xebialabs/xld-kubernetes-store-app.yaml.tmpl
  - path: xebialabs/xld-kubernetes-notification-app.yaml.tmpl
  - path: xebialabs/xlr-pipeline-ci-cd.yaml.tmpl
  - path: xebialabs/xlr-pipeline-destroy.yaml.tmpl
  - path: xebialabs/USAGE.md.tmpl
  # Terraform
  - path: terraform/main.tf
    dependsOnTrue: ProvisionCluster
  - path: terraform/variables.tf
    dependsOnTrue: ProvisionCluster
  - path: terraform/backend.tf.tmpl
    dependsOnTrue: ProvisionCluster
  - path: terraform/outputs.tf
    dependsOnTrue: ProvisionCluster
  - path: terraform/.gitignore
    dependsOnTrue: ProvisionCluster
  - path: terraform/aks/main.tf
    dependsOnTrue: ProvisionCluster
  - path: terraform/aks/variables.tf
    dependsOnTrue: ProvisionCluster
  - path: terraform/aks/outputs.tf
    dependsOnTrue: ProvisionCluster
  - path: terraform/vpc/main.tf
    dependsOnTrue: ProvisionCluster
  - path: terraform/vpc/variables.tf
    dependsOnTrue: ProvisionCluster
  - path: terraform/vpc/outputs.tf
    dependsOnTrue: ProvisionCluster
  # docker-compose setup for required tools
  - path: docker/docker-compose.yml.tmpl
  - path: docker/data/configure-xl-devops-platform.yaml
  - path: docker/jenkins/jenkins.yaml
    dependsOnTrue: enableCICD
