Skip to content

Commit

Permalink
fix missing PostDeployTasks for nested resources
Browse files Browse the repository at this point in the history
  • Loading branch information
amine-mejaouel authored and ninjarobot committed May 11, 2022
1 parent bd5481d commit d59f6ac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Farmer/Builders/Builders.ResourceGroup.fs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,17 @@ type ResourceGroupConfig =

interface IDeploymentSource with
member this.Deployment=
let rec getPostDeployTasks (resources: IArmResource list) = [
for resource in resources do
match resource with
| :? IPostDeploy as pd -> pd
| :? ResourceGroupDeployment as rgp -> yield! getPostDeployTasks rgp.Resources
| _ -> ()
]

{ Location=this.Location
Template = this.Template
PostDeployTasks =
this.Resources
|> List.choose (function | :? IPostDeploy as pd -> Some pd |_ -> None)
PostDeployTasks = getPostDeployTasks this.Resources
RequiredResourceGroups =
this.Resources
|> List.collect (function | :? ResourceGroupDeployment as rg -> rg.RequiredResourceGroups | _ -> [])
Expand Down
14 changes: 14 additions & 0 deletions src/Tests/ResourceGroup.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,18 @@ let tests = testList "Resource Group" [
|> List.map (fun x -> x.ResourceId.Name.Value)
Expect.equal nestedResources ["stg1";"stg2";"stg3"] "all three storage accounts should be nested"
}
test "zip_deploy should be performed when declared in a nested resource" {
let webApp = webApp {
name "webapp"
zip_deploy "deploy"
}

let oneNestedLevel = resourceGroup { add_resource webApp }
let twoNestedLevels = resourceGroup { add_resource oneNestedLevel }
let threeNestedLevels = arm { add_resource twoNestedLevels }

Expect.isNonEmpty
(threeNestedLevels :> IDeploymentSource).Deployment.PostDeployTasks
"The zip_deploy should create a post deployment task"
}
]

0 comments on commit d59f6ac

Please sign in to comment.