Skip to content

Instantly share code, notes, and snippets.

@isaacabraham
Last active December 4, 2017 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacabraham/34e8304ef48681072cac9b1634954cda to your computer and use it in GitHub Desktop.
Save isaacabraham/34e8304ef48681072cac9b1634954cda to your computer and use it in GitHub Desktop.
#I @"..\packages\arm-deploy"
#I @"..\packages\arm-deploy\Newtonsoft.Json\lib\net45"
#r @"..\packages\arm-deploy\fake\tools\FakeLib.dll"
#load @"..\.paket\load\net452\arm-deploy\arm-deploy.group.fsx"
#load @"..\paket-files\arm-deploy\CompositionalIT\fshelpers\src\FsHelpers\ArmHelper\ArmHelper.fsx"
open Cit.Helpers.Arm
open Fake
open Fake.EnvironmentHelper
open Fake.TraceHelper
open System
open System.IO
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
let mutable azure = None
Target "AzureAuthentication" <| fun _ ->
tracefn "Authenticating with Azure..."
let azureCredentials =
{ ClientId = getBuildParam "ClientId" |> Guid
ClientSecret = getBuildParam "ClientSecret"
TenantId = getBuildParam "TenantId" |> Guid }
let subscriptionId = getBuildParam "SubscriptionId" |> Guid
azure <- Some(authenticate azureCredentials subscriptionId)
Target "CreateResourceGroup" <| fun _ ->
let resourceGroup = getBuildParam "ResourceGroup"
let armTemplate = getBuildParam "ArmTemplate"
let outputs =
let deployment =
tracefn "Deploying template '%s' to resource group '%s'..." armTemplate resourceGroup
{ DeploymentName =
getBuildParamOrDefault "BUILD_BUILDNUMBER" (sprintf "LOCAL-%s" (getMachineEnvironment()).MachineName)
|> fun buildNumber -> buildNumber.Replace(" ", "_")
ResourceGroup = Existing resourceGroup
ArmTemplate = File.ReadAllText armTemplate
Parameters = [ "storageAccountName", getBuildParam "StorageAccountName" ]
DeploymentMode = Incremental }
deployment
|> deployWithProgress azure.Value
|> Seq.choose(function
| DeploymentInProgress (state, operations) -> tracefn "State is %s, completed %d operations." state operations; None
| DeploymentError (statusCode, message) -> traceError <| sprintf "DEPLOYMENT ERROR: %s - '%s'" statusCode message; None
| DeploymentCompleted outputs -> Some outputs)
|> Seq.head
let storageAccountKey = outputs.TryFind "storageAccountKey"
tracefn "Done! Storage account key is %A" storageAccountKey
// Build order
"AzureAuthentication"
==> "CreateResourceGroup"
// Start build
RunTargetOrDefault "CreateResourceGroup"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment