apiVersion: xl/v2
kind: Blueprint

metadata:
  name: AWS-Microservice-EKS-with-JHipster
  description: |
    The 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.md" for further usage instructions.

spec:
  parameters:
  # General variables
  - name: AppName
    type: Input
    prompt: What is the name of the application?

  # AWS specific variables
  - name: UseAWSCredentialsFromSystem
    type: Confirm
    prompt: Do you want to use AWS credentials from ~/.aws/credentials file?
    promptIf: !expr "awsCredentials('IsAvailable')"
  - name: AWSAccessKey
    type: SecretInput
    prompt: What is the AWS Access Key ID?
    promptIf: !expr "!UseAWSCredentialsFromSystem"
    default: !expr "awsCredentials('AccessKeyID')"
  - name: AWSAccessSecret
    type: SecretInput
    prompt: What is the AWS Secret Access Key?
    promptIf: !expr "!UseAWSCredentialsFromSystem"
    default: !expr "awsCredentials('SecretAccessKey')"
  - name: AWSRegion #options are set manually because EKS service is not registered within AWS GO SDK
    type: Select
    prompt: "Select the AWS region:"
    options:
    # This needs to be updated in the RegionMap of cloudformation/eks-workers.yaml as well
      - label: US West (Oregon)
        value: us-west-2
      # commented out because of https://github.com/boto/boto3/issues/811
      # - us-east-1
      - label: US East (Ohio)
        value: us-east-2
      - label: EU (Frankfurt)
        value: eu-central-1
      # - eu-north-1 # doesn't seem to work
      - label: EU (Ireland)
        value: eu-west-1
      - label: EU (London)
        value: eu-west-2
      - label: EU (Paris)
        value: eu-west-3
      - label: Asia Pacific (Tokyo)
        value: ap-northeast-1
      - label: Asia Pacific (Seoul)
        value: ap-northeast-2
      - label: Asia Pacific (Mumbai)
        value: ap-south-1
      - label: Asia Pacific (Singapore)
        value: ap-southeast-1
      - label: Asia Pacific (Sydney)
        value: ap-southeast-2
  - name: ProvisionCluster
    type: Confirm
    prompt: Do you want to provision a new AWS EKS cluster?
  - name: ClusterName
    type: Input
    prompt: What is the name of the cluster?
  - name: ClusterEndpoint
    type: Input
    prompt: What is the endpoint for the cluster, example https://3219568049031C127A97DD725F241767.yl4.eu-west-1.eks.amazonaws.com
    promptIf: !expr "!ProvisionCluster"
  - 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: StoreAdminUsername
    value: admin
  - name: StoreAdminPassword
    value: admin
  - 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

  - 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: "XL Enterprise"
    - name: XLVersion
      value: "9.0.0"
    - name: UseDockerProxy
      value: false
    - name: UseJenkins
      value: true
    - name: JenkinsPort
      value: 8080

  files:
  - path: xebialabs/xld-infra-env.yaml.tmpl
  - path: xebialabs/xld-cloudformation-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
  - path: kubernetes/aws-auth-cm.yaml
    writeIf: ProvisionCluster
  - path: cloudformation/cfn-secret-provider.zip
    writeIf: ProvisionCluster
  - path: cloudformation/eks-master.yaml
    writeIf: ProvisionCluster
  - path: cloudformation/eks-user.yaml
    writeIf: ProvisionCluster
  - path: cloudformation/eks-vpc.yaml
    writeIf: ProvisionCluster
  - path: cloudformation/eks-workers.yaml
    writeIf: ProvisionCluster
  - path: xebialabs.yaml