import { Environment } from '../types.bicep'

targetScope = 'subscription'

param environment Environment

var location = deployment().location
var productionSubscriptionId = '799cbffe-5209-41fd-adf9-4ffa3d1feead'

resource rgBff 'Microsoft.Resources/resourceGroups@2021-04-01' = {
  name: 'rg-redis-api-${environment}'
  location: location
}

module mi '../managedIdentity.bicep' = {
  name: 'mi-redis-api-${environment}'
  scope: rgBff
  params: {
    principalName: 'mi-redis-api-${environment}'
    location: location
  }
}

module allowAcrPull 'allow-acr-pull.bicep' = {
  name: 'allowAcrPull'
  scope: resourceGroup('1e6ef69e-8719-4924-a311-e66fe00399c7', 'rg-shared')
  params: {
    principalId: mi.outputs.principalId
  }
}

module containerEnv 'containerEnvironment.bicep' = {
  name: 'containerEnv'
  scope: rgBff
  params: {
    location: location
    environment: environment
    userAssignedIdentityId: mi.outputs.id
  }
}
