apiVersion: xl/v2
kind: Blueprint

metadata:
  name: AWS-Microservice-EKS-with-JHipster
  description: |
    This blueprint deploys an e-commerce microservice application to AWS EKS.
    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-microservice-ecommerce.md" for further usage instructions.

spec:
  parameters:
  - name: ProvisionCluster
    type: Confirm
    prompt: Do you want to provision a new AWS EKS cluster?

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

  # ############################################################################
  # Own cluster
  # ############################################################################
  - name: ClusterEndpoint
    type: Input
    prompt: !expr "'What is the endpoint for your \\'' + ClusterName + '\\' cluster (example https://104.155.109.230)?'"
    promptIf: !expr "!ProvisionCluster"
    validate: !expr "regex('^https?://[a-zA-Z0-9_-]*[a-zA-Z0-9](\\.[a-zA-Z0-9_-]*[a-zA-Z0-9]+)*(:[0-9]{2,5})?$', ClusterEndpoint)"

  - name: Namespace
    type: Input
    prompt: What is the name of the namespace? This should be same as the one used in Kubernetes files.
    default: xl-demo
    value: !expr "ProvisionCluster ? 'xl-demo' : ''"

  - name: UseAWSCredentialsFromSystem
    type: Confirm
    prompt: Do you want to use AWS credentials from ~/.aws/credentials file?
    promptIf: !expr "!ProvisionCluster && awsCredentials('IsAvailable')"

  - name: AWSAccessKey
    type: SecretInput
    prompt: What is the AWS Access Key ID?
    promptIf: !expr "!ProvisionCluster && !UseAWSCredentialsFromSystem"
    default: !expr "awsCredentials('AccessKeyID')"

  - name: AWSAccessSecret
    type: SecretInput
    prompt: What is the AWS Secret Access Key?
    promptIf: !expr "!ProvisionCluster && !UseAWSCredentialsFromSystem"
    default: !expr "awsCredentials('SecretAccessKey')"

  - name: XLDUrlForXLR
    type: Input
    prompt: What is the XL Deploy URL used by XL Release? (This is only used in the XL Release template)
    default: http://xl-deploy:4516

  # ############################################################################
  # Jenkins
  # ############################################################################
  - name: EnableCICD
    value: true

  - name: StoreAdminUsername
    value: admin

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

  includeAfter:
  - blueprint: aws/basic-eks-cluster
    includeIf: !expr "ProvisionCluster"
    parameterOverrides:
    - name: ClusterName
      value: !expr "ClusterName"
    - name: IncludeDockerCompose
      value: false
    - name: XLEnvironmentPath
      value: !expr "ProvisionCluster ? 'aws-eks-' + ClusterName : ''"
    fileOverrides:
    - path: xebialabs.yaml
      writeIf: !expr "false"
    - path: README.md
      writeIf: !expr "false"

  - blueprint: xl-devops-platform
    parameterOverrides:
    - name: UseXLDeploy
      value: true
    - name: UseXLRelease
      value: true
    - name: XLVersion
      value: "9.0"
    - name: UseDockerProxy
      value: false
    - name: UseJenkins
      value: !expr "EnableCICD"

  files:
  # XebiaLabs
  - path: xebialabs.yaml.tmpl
  - path: README.md
  - path: xebialabs/USAGE-microservice-ecommerce.md.tmpl
  - path: xebialabs/xld-kubernetes-invoice-app.yaml.tmpl
  - path: xebialabs/xld-kubernetes-notification-app.yaml.tmpl
  - path: xebialabs/xld-kubernetes-store-app.yaml.tmpl
  - path: xebialabs/xld-microservice-ecommerce-cloudformation-applications.yaml.tmpl
  - path: xebialabs/xld-microservice-ecommerce-infra-env.yaml.tmpl
    writeIf: !expr "!ProvisionCluster"
  - path: xebialabs/xlr-microservice-ecommerce-pipeline-ci-cd.yaml.tmpl
  - path: xebialabs/xlr-microservice-ecommerce-pipeline-destroy.yaml.tmpl
