version: 1
kind: stack
meta:
  name: Cloud SQL with performance testing
  brief: Cloud SQL with performance testing

components:
- name: cloud-sql
  source:
    dir: components/cloud-sql
    git:
      remote: https://github.com/agilestacks/google-components.git
      subDir: cloud-sql
- name: k6-sql-load-test
  source:
    dir: components/k6-sql-load-test
    git:
      remote: https://github.com/agilestacks/google-components.git
      subDir: k6-sql-load-test

extensions:
  init:
    - gcp
    - .hub/get-info
  configure:
    - gcp
    - env

requires:
- gcp

lifecycle:
  verbs:
  - deploy
  - undeploy
  order:
  - cloud-sql
  - k6-sql-load-test

parameters:
- name: hub.sandboxDir
  fromEnv: SANDBOX_DIR
- name: hub.sandboxCommit
  fromEnv: SANDBOX_COMMIT
- name: hub.userAccount
  fromEnv: USER_ACCOUNT

- name: projectId
  fromEnv: GOOGLE_PROJECT
- name: dns.domain
  fromEnv: HUB_DOMAIN_NAME
- name: stateBucketName
  fromEnv: HUB_STATE_BUCKET
- name: hubStackName
  fromEnv: HUB_STACK_NAME
- name: cloud.region
  fromEnv: GOOGLE_REGION
  value: us-central1
- name: cloud.zone
  fromEnv: GOOGLE_ZONE
  value: us-central1-a

- name: component.cloudSql
  parameters:
  - name: name
    value: ${hubStackName}
  - name: version
    value: MYSQL_5_7
  - name: dbName
    value: ${hubStackName}
  - name: dbUser
    value: ${hubStackName}-user
  - name: password
    fromEnv: DB_PASSWORD

- name: component.k6SQLloadTest
  parameters:
  - name: kind
    value: mysql
  - name: dbHost
    kind: link
    value: ${component.cloudSql.publicIp}
  - name: dbName
    value: ${component.cloudSql.dbName}
  - name: dbUser
    value: ${component.cloudSql.dbUser}
  - name: password
    value: ${component.cloudSql.password}
  - name: testDuration
    value: 100s
  - name: numberOfUsers
    value: 100

outputs:
- name: component.cloudSql.dbName
- name: component.cloudSql.dbUser
- name: component.cloudSql.publicIp
