apiVersion: xl/v2
kind: Blueprint

metadata:
  name: 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: 2.0
  instructions: Please read the generated file "xebialabs/USAGE.md" for further usage instructions.

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

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

  # ############################################################################
  # Own cluster
  # ############################################################################
  - name: ClusterEndpoint
    type: Input
    prompt: What is the endpoint for the existing cluster, example https://104.155.109.230
    promptIf: !expr "!ProvisionCluster"

  - name: PasswordToken
    type: SecretInput
    prompt: What is the token for accessing the existing cluster
    promptIf: !expr "!ProvisionCluster"
  # ############################################################################

  # ############################################################################
  # New cluster
  # ############################################################################
  - name: AKSRegion
    type: Select
    prompt: "Select the AKS region for the cluster:"
    promptIf: ProvisionCluster
    options:
      - label: East Asia
        value: eastasia
      - label: Southeast Asia
        value: southeastasia
      - label: Central US
        value: centralus
      - label: East US
        value: eastus
      - label: East US 2
        value: eastus2
      - label: West US
        value: westus
      - label: North Central US
        value: northcentralus
      - label: South Central US
        value: southcentralus
      - label: North Europe
        value: northeurope
      - label: West Europe
        value: westeurope
      - label: Japan West
        value: japanwest
      - label: Japan East
        value: japaneast
      - label: Brazil South
        value: brazilsouth
      - label: Australia East
        value: australiaeast
      - label: Australia Southeast
        value: australiasoutheast
      - label: South India
        value: southindia
      - label: Central India
        value: centralindia
      - label: West India
        value: westindia
      - label: Canada Central
        value: canadacentral
      - label: Canada East
        value: canadaeast
      - label: UK South
        value: uksouth
      - label: UK West
        value: ukwest
      - label: West Central US
        value: westcentralus
      - label: West US 2
        value: westus2
      - label: Korea Central
        value: koreacentral
      - label: Korea South
        value: koreasouth
      - label: France Central
        value: francecentral
      - label: France South
        value: francesouth
      - label: Australia Central
        value: australiacentral
      - label: Australia Central 2
        value: australiacentral2
      - label: South Africa North
        value: southafricanorth
      - label: South Africa West
        value: southafricawest

    # ############################################################################
  # Authentication
  # ############################################################################
  - name: SubscriptionID
    type: Input
    prompt: "Enter you Azure subscription id:"
    promptIf: ProvisionCluster

  - name: ClientID
    type: Input
    prompt: "Enter your Azure client id:"
    promptIf: ProvisionCluster

  - name: ClientSecret
    type: SecretInput
    prompt: "Enter your Azure client secret:"
    promptIf: ProvisionCluster

  - name: TenantID
    type: Input
    prompt: "Enter your Azure tenant id:"
    promptIf: 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
    prompt: "The blueprint will create a new Resource Group for the cluster. Please supply a name:"
    promptIf: ProvisionCluster
    validate: !expr "regex('^[\\\\w._()-]{2,50}[\\\\w_()-]$', ResourceGroup)"

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

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

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

  - name: ClusterName
    type: Input
    prompt: What name do you want to give the cluster?
    validate: !expr "regex('^[a-zA-Z][\\\\w-]{1,29}[\\\\w]$', ClusterName)"

  - name: Namespace
    value: xl-demo

  - name: XLDUrlForXLR
    type: Input
    prompt: 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
    prompt: Do you want to enable CI/CD integration with Jenkins?

  - name: StoreAdminUsername
    value: admin

  - name: StoreAdminPassword
    type: SecretInput
    value: admin
  # ############################################################################

  - name: GenerateDockerComposeSetup
    type: Confirm
    prompt: "Do you want to generate a docker-compose setup with the required tools to run this blueprint?"
    default: false

  includeAfter:
  - blueprint: xl-devops-platform
    includeIf: GenerateDockerComposeSetup
    parameterOverrides:
    - name: UseXLDeploy
      value: true
    - name: XLDeployPort
      value: 4516
    - name: UseXLRelease
      value: true
    - name: XLReleasePort
      value: 5516
    - name: JetPackOrEnterprise
      value: "JetPack"
    - name: XLVersion
      value: "9.0.0"
    - name: UseDockerProxy
      value: false
    - name: UseJenkins
      value: !expr "EnableCICD"
    - name: JenkinsPort
      value: 8080
    - name: JenkinsBranch
      value: gke-blueprint

  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
    writeIf: ProvisionCluster
  - path: terraform/variables.tf
    writeIf: ProvisionCluster
  - path: terraform/backend.tf.tmpl
    writeIf: ProvisionCluster
  - path: terraform/outputs.tf
    writeIf: ProvisionCluster
  - path: terraform/.gitignore
    writeIf: ProvisionCluster
  - path: terraform/aks/main.tf
    writeIf: ProvisionCluster
  - path: terraform/aks/variables.tf
    writeIf: ProvisionCluster
  - path: terraform/aks/outputs.tf
    writeIf: ProvisionCluster
  - path: terraform/vpc/main.tf
    writeIf: ProvisionCluster
  - path: terraform/vpc/variables.tf
    writeIf: ProvisionCluster
  - path: terraform/vpc/outputs.tf
    writeIf: ProvisionCluster
