#
# Purpose: Manage regional resources for ARO HCP shared by SC and MC
# Managed Resources:
# * regional SVC and CX DNS zones and delegates them to the global ones
# * Eventgrid Namespaces MQTT for Maestro
# * regional replication for the OCP and SVC ACRs
# * regional Azure Monitor Workspace & linking into global Grafana
# * regional Azure Log Analytics Workspace
#
$schema: "pipeline.schema.v1"
serviceGroup: Microsoft.Azure.ARO.HCP.Region
rolloutName: Region Rollout
resourceGroups:
- name: '{{ .global.rg  }}'
  subscription: '{{ .global.subscription  }}'
  steps:
  # Query parameters from global deployment, e.g. DNS hzone and ACR resource IDs
  - name: global-output
    action: ARM
    template: templates/output-global.bicep
    parameters: configurations/output-global.tmpl.bicepparam
    deploymentLevel: ResourceGroup
    outputOnly: true
- name: '{{ .regionRG  }}'
  subscription: '{{ .svc.subscription  }}'
  steps:
  - name: rpRegistration
    action: ResourceProviderRegistration
    resourceProviderNamespaces:
      value:
      - Microsoft.Dashboard
  - name: region
    action: ARM
    template: templates/region.bicep
    parameters: configurations/region.tmpl.bicepparam
    deploymentLevel: ResourceGroup
    variables:
    - name: ocpAcrResourceId
      input:
        step: global-output
        name: ocpAcrResourceId
    - name: svcAcrResourceId
      input:
        step: global-output
        name: svcAcrResourceId
    - name: cxParentZoneResourceId
      input:
        step: global-output
        name: cxParentZoneResourceId
    - name: svcParentZoneResourceId
      input:
        step: global-output
        name: svcParentZoneResourceId
    dependsOn:
    - global-output
    - rpRegistration
  - name: metrics-infra
    action: ARM
    template: modules/metrics/metrics.bicep
    parameters: configurations/metrics.tmpl.bicepparam
    deploymentLevel: ResourceGroup
    variables:
    - name: grafanaResourceId
      input:
        step: global-output
        name: grafanaResourceId
    dependsOn:
    - region
  - name: region-output
    action: ARM
    template: templates/output-region.bicep
    parameters: configurations/output-region.tmpl.bicepparam
    deploymentLevel: ResourceGroup
    outputOnly: true
    dependsOn:
    - region
    - metrics-infra
- name: '{{ .global.rg  }}'
  subscription: '{{ .global.subscription  }}'
  steps:
  - name: add-grafana-datasource
    action: Shell
    command: scripts/add-grafana-datasource.sh
    variables:
    - name: GRAFANA_RESOURCE_ID
      input:
        step: global-output
        name: grafanaResourceId
    - name: PROM_QUERY_URL
      input:
        step: region-output
        name: monitorPrometheusQueryEndpoint
    - name: MONITOR_ID
      input:
        step: region-output
        name: azureMonitoringWorkspaceId
    dependsOn:
    - metrics-infra
    - region-output
