apiVersion: xl/v2
kind: Blueprint

metadata:
  name: GCP-Microservice-GKE-with-JHipster
  description: |
    This blueprint deploys an e-commerce microservice application to GCP GKE.
    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: AppName
    type: Input
    prompt: What do you want to name the application?
    description: Application name will be used to generate cloud resource names
    validate: !expr "regex('^[a-zA-Z][\\\\w-]{1,29}[\\\\w]$', AppName)"

  - name: ProvisionCluster
    type: Confirm
    prompt: Do you want to provision a new GCP GKE 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-z0-9_-]*[a-z0-9](\\.[a-z0-9_-]*[a-z0-9]+)*(:[0-9]{2,5})?$', ClusterEndpoint)"

  - name: GCPProjectID
    type: Input
    prompt: What is the GCP project ID?

  - name: K8SMasterUser
    type: Input
    prompt: What is the username for Kubernetes cluster?
    default: admin

  - name: K8SMasterPassword
    type: SecretInput
    prompt: What is the password for Kubernetes cluster? (minimum 16 characters)
    validate: !expr "regex('^(\\\\S){16,}$', K8SMasterPassword)"

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

  - name: StoreAdminUsername
    value: admin

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

  includeAfter:
  - blueprint: fragments/gcp-region

  - 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"
    - name: JenkinsBranch
      value: gke-blueprint

  files:
  # XebiaLabs
  - path: xebialabs.yaml
  - path: README.md
  - path: xebialabs/USAGE-microservice-ecommerce.md.tmpl
  - path: xebialabs/xld-microservice-ecommerce-terraform-applications.yaml.tmpl
  - path: xebialabs/xld-microservice-ecommerce-invoice-applications.yaml.tmpl
  - path: xebialabs/xld-microservice-ecommerce-store-applications.yaml.tmpl
  - path: xebialabs/xld-microservice-ecommerce-notification-applications.yaml.tmpl
  - path: xebialabs/xld-microservice-ecommerce-infra-env.yaml.tmpl
  - path: xebialabs/xlr-microservice-ecommerce-pipeline-ci-cd.yaml.tmpl
  - path: xebialabs/xlr-microservice-ecommerce-pipeline-destroy.yaml.tmpl
  # Terraform
  - path: terraform-microservice-ecommerce/gke/main.tf
    writeIf: ProvisionCluster
  - path: terraform-microservice-ecommerce/gke/outputs.tf
    writeIf: ProvisionCluster
  - path: terraform-microservice-ecommerce/gke/variables.tf
    writeIf: ProvisionCluster
  - path: terraform-microservice-ecommerce/vpc/main.tf
    writeIf: ProvisionCluster
  - path: terraform-microservice-ecommerce/vpc/outputs.tf
    writeIf: ProvisionCluster
  - path: terraform-microservice-ecommerce/vpc/variables.tf
    writeIf: ProvisionCluster
  - path: terraform-microservice-ecommerce/.gitignore
    writeIf: ProvisionCluster
  - path: terraform-microservice-ecommerce/backend.tf.tmpl
    writeIf: ProvisionCluster
  - path: terraform-microservice-ecommerce/main.tf
    writeIf: ProvisionCluster
  - path: terraform-microservice-ecommerce/outputs.tf
    writeIf: ProvisionCluster
  - path: terraform-microservice-ecommerce/variables.tf
    writeIf: ProvisionCluster
  - path: manifest.yaml
    writeIf: ProvisionCluster
