trigger:
  - none

pool:
  vmImage: ubuntu-latest

variables:
  - group: openhack
  - name: ServiceConnectionName
    value: AzureServiceConnection
  - name: RESOURCES_SUFFIX
    value: sqlsecrot
  - name: RESOURCE_GROUP_NAME
    value: $(RESOURCES_PREFIX)$(RESOURCES_SUFFIX)rg
  - name: workDir
    value: "$(System.DefaultWorkingDirectory)/support/sqlsecretrotation/iac/bicep"

steps:
  - task: AzureCLI@2
    displayName: "Deploy"
    inputs:
      azureSubscription: "$(ServiceConnectionName)"
      scriptType: "bash"
      scriptLocation: "inlineScript"
      inlineScript: |
        if [ $(az group exists --name $(RESOURCE_GROUP_NAME)) = false ]; then
          az group create --name $(RESOURCE_GROUP_NAME) --location $(LOCATION)
        fi
        az deployment group create \
        --name $(Build.BuildId) \
        --resource-group $(RESOURCE_GROUP_NAME) \
        --template-file main.bicep \
        --parameters keyVaultRgName='$(RESOURCES_PREFIX)rg' keyVaultName='$(RESOURCES_PREFIX)kv' resourcesPrefix='$(RESOURCES_PREFIX)' resourcesSuffix='$(RESOURCES_SUFFIX)'
      workingDirectory: $(workDir)
