Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
et1975 committed May 3, 2022
1 parent 00d99da commit 9599bc0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/Farmer/Arm/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type ContainerApp =
interface IArmResource with
member this.ResourceId = containerApps.resourceId this.Name
member this.JsonModel =
let usernameSecretName (resourceId:ResourceId) = $"{resourceId.Name.Value}-username"
{| containerApps.Create(this.Name, this.Location, this.dependencies) with
kind = "containerapp"
identity =
Expand All @@ -72,7 +73,7 @@ type ContainerApp =
{| name = cred.Username
value = cred.Password.ArmExpression.Eval() |}
| ImageRegistryAuthentication.ListCredentials resourceId ->
{| name = ArmExpression.create($"listCredentials({resourceId.ArmExpression.Value}, '2019-05-01').username").Eval()
{| name = usernameSecretName resourceId
value = ArmExpression.create($"listCredentials({resourceId.ArmExpression.Value}, '2019-05-01').passwords[0].value").Eval() |}
for setting in this.Secrets do
{| name = setting.Key.Value
Expand All @@ -90,9 +91,9 @@ type ContainerApp =
username = cred.Username
passwordSecretRef = cred.Username |}
| ImageRegistryAuthentication.ListCredentials resourceId ->
{| server = ArmExpression.create($"reference({resourceId.ArmExpression.Value}, '2019-05-01').loginServer").Eval()
{| server = $"{resourceId.Name.Value}.azurecr.io"
username = ArmExpression.create($"listCredentials({resourceId.ArmExpression.Value}, '2019-05-01').username").Eval()
passwordSecretRef = ArmExpression.create($"listCredentials({resourceId.ArmExpression.Value}, '2019-05-01').username").Eval() |}
passwordSecretRef = usernameSecretName resourceId |}
|]
ingress =
match this.IngressMode with
Expand Down
14 changes: 11 additions & 3 deletions src/Tests/ContainerApps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ open Farmer.ContainerApp
open Farmer.Identity

let msi = createUserAssignedIdentity "appUser"
let containerRegistryName = "myregistry"

let fullContainerAppDeployment =
let containerLogs = logAnalytics { name "containerlogs" }
let containerRegistryDomain = "myregistry.azurecr.io"
let containerRegistryUsername = "myregistry"
let containerRegistryDomain = $"{containerRegistryName}.azurecr.io"
let acr = containerRegistry {
name containerRegistryName
}
let version = "1.0.0"
let containerEnv =
containerEnvironment {
Expand All @@ -24,7 +27,7 @@ let fullContainerAppDeployment =
add_identity msi
active_revision_mode Single
add_registry_credentials [
registry containerRegistryDomain containerRegistryUsername
registry containerRegistryDomain containerRegistryName
]
add_containers [
container {
Expand Down Expand Up @@ -57,6 +60,7 @@ let fullContainerAppDeployment =
containerApp {
name "servicebus"
active_revision_mode Single
reference_registry_credentials [(acr :> IBuilder).ResourceId]
add_containers [
container {
name "servicebus"
Expand Down Expand Up @@ -150,4 +154,8 @@ let tests = testList "Container Apps" [
Expect.isNonEmpty containerApp.Identity.UserAssigned "Container app did not have identity"
Expect.equal containerApp.Identity.UserAssigned.[0] (UserAssignedIdentity(ResourceId.create(Arm.ManagedIdentity.userAssignedIdentities, ResourceName "appUser"))) "Expected user identity named 'appUser'."
}
test "Linked ACR references correct secret" {
let containerApp = fullContainerAppDeployment.Template.Resources |> List.find(fun r -> r.ResourceId.Name.Value = "servicebus") :?> Farmer.Arm.App.ContainerApp
Expect.isFalse (containerApp.Secrets |> Map.containsKey (ContainerAppValidation.ContainerAppSettingKey.Create $"{containerRegistryName}-username").OkValue) "Container app did not have linked ACR's secret"
}
]

0 comments on commit 9599bc0

Please sign in to comment.