apiVersion: xl/v2
kind: Blueprint

metadata:
  name: Azure-App-Service
  description: |
    The blueprint provisions an Azure App service instance with given Docker image or with a sample application
  author: XebiaLabs
  version: 2.0
  instructions: Please read the generated file "xebialabs/USAGE.md" for further usage instructions.

spec:
  parameters:

  # ############################################################################
  # Access and authorization
  # ############################################################################
  - name: SubscriptionID
    type: Input
    prompt: What is your existing Azure subscription id?

  - name: ClientID
    type: Input
    prompt: What is the client id (appId) of an existing Service Principal in Azure?

  - name: ClientSecret
    type: SecretInput
    prompt: What is the secret (password) for that client id?

  - name: TenantID
    type: Input
    prompt: What is your existing Azure tenant id?

  # ############################################################################
  # Location and app details
  # ############################################################################
  - name: ResourceGroupLocation
    type: Select
    prompt: "Select where this resource group will go:"
    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

  - name: AppName
    type: Input
    prompt: What do you want to name the application?
    validate: !expr "regex('^[a-zA-Z0-9-]*$', AppName)"

  - name: UseSampleApplication
    type: Confirm
    prompt: Do you want to deploy a sample application with its database?
    default: true
    description: Deploy the sample application from https://github.com/xebialabs/e-commerce-monolith with a MySQL server database

  - name: MySqlMasterPassword
    type: SecretInput
    prompt: What is the master password to use for MySQL server that will be provisioned? 
    description: A complex password for MySQL server user. Needs minimum 8 character with at least 1 lowercase, 1 uppercase, 1 number and 1 special character 
    validate: !expr "regex('^(?=.*?[0-9])(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[-._!#^~@$%*]).{8,128}$', MySqlMasterPassword)"
    promptIf: !expr "UseSampleApplication"

  - name: MySqlMasterUsername
    value: mysqladminun

  - name: DockerImage
    type: Input
    prompt: What is the docker image path that you would like to use?
    default: xebialabsunsupported/ecommerce-monolith
    value: !expr "UseSampleApplication ? 'xebialabsunsupported/ecommerce-monolith' : ''"

  - name: DockerImageTag
    type: Input
    prompt: What is the docker image tag to be used?
    default: latest
    value: !expr "UseSampleApplication ? 'latest' : ''"

  - 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: false
    - name: XLVersion
      value: "9.0"
    - name: UseDockerProxy
      value: false
    - name: UseJenkins
      value: false

  files:
  # XebiaLabs
  - path: xebialabs/USAGE.md.tmpl
  - path: xebialabs/azure-app-service.yaml.tmpl
  # Terraform
  - path: terraform/.gitignore
  - path: terraform/main.tf.tmpl
  - path: terraform/outputs.tf
  - path: terraform/variables.tf.tmpl