Bicep 上で、App Configuration の接続文字列が欲しい時があったので、備忘録として残します。
やってみる
次のような Bicep を書けば取得できます。
なんでこうなるの
App Configuration を listKeys() すると、実体は次のような構造の json になっているので、filter 関数で、キーをフィルターして最初のモノを取得すると接続文字列が取得できます。
{ "value": [ { "id": "abcdefg123456789", "name": "Primary", "value": "000000000000000000000000000000000000000000000000000000", "connectionString": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "lastModified": "2023-06-06T00:00:00+00:00", "readOnly": false }, { "id": "abcdefg1234567891", "name": "Secondary", "value": "000000000000000000000000000000000000000000000000000000", "connectionString": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "lastModified": "2023-06-06T00:00:00+00:00", "readOnly": false }, { "id": "abcdefg1234567892", "name": "Primary Read Only", "value": "000000000000000000000000000000000000000000000000000000", "connectionString": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "lastModified": "2023-06-06T00:00:00+00:00", "readOnly": true }, { "id": "abcdefg1234567893", "name": "Secondary Read Only", "value": "000000000000000000000000000000000000000000000000000000", "connectionString": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "lastModified": "2023-06-06T00:00:00+00:00", "readOnly": true } ] }
注意点
取得した接続文字列を output で返そうとすると、ログに接続文字列が露出するので、絶対にやめましょう。
現在、output で secure string を扱えるように対応が進んでるはずなので、その対応が終わるまでは、絶対に output しないようにしましょう。
まとめ
接続文字列が必要な場合は、これで対応できました。
が、お遊びやミニマムなテスト環境以外で利用する場合は、普通に Managed Identity を利用しましょう。