Skip to content

Commit 8f9aad8

Browse files
author
Florian Wagner
authored
Refactored Version Beta complete - limited docs (#12)
Signed-off-by: Florian Wagner <[email protected]>
1 parent bd6cb74 commit 8f9aad8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1560
-530
lines changed

Deploy/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
body.json
33
# Ignore zip file for publish
44
botnotselfcontained.zip
5+
# Ignore Terraform tfvars
6+
*.tfvars.*

Deploy/ActivateSSL.ps1

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
###
2+
#
3+
# Activate Custom Domain Name SSL Certificate and activate TrafficManager Endpoints
4+
#
5+
# This script will do following steps:
6+
#
7+
# 1. Import information from previous Terraform runs
8+
# 2. Terraform execution to activate certificate and map TrafficManager endpoints
9+
# 3. Update Bot Endpoint
10+
#
11+
# After the script is successfully executed the bot should be in a usable from WebChat
12+
#
13+
###
14+
# Parameters
15+
param(
16+
# Only needed in Issuing Mode
17+
[Parameter(HelpMessage="The domain (CN) name for the SSL certificate")]
18+
[string] $YOUR_DOMAIN,
19+
20+
[Parameter(HelpMessage="Terraform and SSL creation Automation Flag. `$False -> Interactive, Approval `$True -> Automatic Approval")]
21+
[bool] $AUTOAPPROVE = $False,
22+
23+
[Parameter(HelpMessage="KeyVault certificate name")]
24+
[string] $KEYVAULT_CERT_NAME = "SSLcert"
25+
)
26+
# Helper var
27+
$success = $True
28+
$webAppsVariableFile = "webAppVariable.tfvars.json"
29+
# Tell who you are
30+
Write-Host "`n`n# Executing $($MyInvocation.MyCommand.Name)"
31+
32+
# 1. Read values from Terraform IaC run (Bot deployment scripts)
33+
Write-Host "## 1. Read values from Terraform IaC run (Bot deployment scripts)"
34+
$content = '{ "azure_webApps" : ' + $(terraform output -state=".\IaC\terraform.tfstate" -json webAppAccounts) + '}'
35+
Set-Content -Path ".\SSLActivation\$webAppsVariableFile" -Value $content
36+
$KeyVault = terraform output -state=".\IaC\terraform.tfstate" -json keyVault | ConvertFrom-Json
37+
$TrafficManager = terraform output -state=".\IaC\terraform.tfstate" -json trafficManager | ConvertFrom-Json
38+
$Bot = terraform output -state=".\IaC\terraform.tfstate" -json bot | ConvertFrom-Json
39+
40+
# 2. Terraform execution to activate certificate and map TrafficManager endpoints
41+
Write-Host "## 2. Terraform execution to activate certificate and map TrafficManager endpoints"
42+
if ($AUTOAPPROVE -eq $True)
43+
{
44+
$AUTOFLAG = "-auto-approve"
45+
} else {
46+
$AUTOFLAG = ""
47+
}
48+
49+
if ($YOUR_DOMAIN -eq "")
50+
{
51+
$YOUR_DOMAIN = $TrafficManager.fqdn
52+
}
53+
54+
Set-Location SSLActivation
55+
terraform init
56+
terraform apply -var "keyVault_name=$($KeyVault.name)" -var "keyVault_rg=$($KeyVault.resource_group)" `
57+
-var "your_domain=$YOUR_DOMAIN" `
58+
-var "trafficmanager_name=$($TrafficManager.name)" -var "trafficmanager_rg=$($TrafficManager.resource_group)" `
59+
-var-file="$webAppsVariableFile" `
60+
-var "keyVault_cert_name=$KEYVAULT_CERT_NAME" $AUTOFLAG
61+
$success = $success -and $?
62+
Set-Location ..
63+
64+
# CleanUp
65+
Remove-Item -Path ".\SSLActivation\$webAppsVariableFile"
66+
67+
# 3. Update Bot Endpoint
68+
Write-Host "## 3. Update Bot Endpoint"
69+
az bot update --resource-group $Bot.resource_group --name $Bot.name --endpoint "https://$YOUR_DOMAIN/api/messages"
70+
$success = $success -and $?
71+
72+
# Return execution status
73+
exit $success

Deploy/CheckExistingSSL.ps1

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
###
2+
#
3+
# Check if already a SSL certificate was imported to KeyVault
4+
#
5+
# This script will do following steps:
6+
#
7+
# 1. Read values from Terraform IaC run (Bot deployment scripts)
8+
# 2. Check if certificate exists in Key Vault
9+
#
10+
# Returns $True if certificate already exists
11+
#
12+
###
13+
# Parameters
14+
param(
15+
[Parameter(HelpMessage="KeyVault certificate name")]
16+
[string] $KEYVAULT_CERT_NAME = "SSLcert"
17+
)
18+
# Tell who you are
19+
Write-Host "`n`n# Executing $($MyInvocation.MyCommand.Name)"
20+
21+
# 1. Read values from Terraform IaC run (Bot deployment scripts)
22+
Write-Host "## 1. Read values from Terraform IaC run (Bot deployment scripts)"
23+
$KeyVault = terraform output -state=".\IaC\terraform.tfstate" -json keyVault | ConvertFrom-Json
24+
25+
# 2. Check if certificate exists in Key Vault
26+
Write-Host "## 2. Check if certificate exists in Key Vault"
27+
az keyvault certificate show --vault-name $KeyVault.name --name $KEYVAULT_CERT_NAME > $null 2> $1
28+
if ($? -eq $True)
29+
{
30+
Write-Host "### Existing Certificate found"
31+
return $True
32+
} else {
33+
Write-Host "### No existing Certificate found"
34+
return $False
35+
}

Deploy/CheckServiceAvailability.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
###
2+
#
3+
# Check for availability of DNS
4+
# returns $False if service is already
5+
#
6+
###
7+
# Parameters
8+
param(
9+
[Parameter(HelpMessage="Service Name")]
10+
[string] $Service,
11+
12+
# Only needed in Issuing Mode
13+
[Parameter(HelpMessage="Full Qualified Domain Name to check")]
14+
[string] $FQDN
15+
)
16+
17+
Resolve-DnsName -Name $FQDN -DnsOnly > $null 2> $1
18+
if ($?)
19+
{
20+
Write-Host "### ERROR, $Service with name '$FQDN' already exists. Please try another Bot Name."
21+
return $False
22+
} else {
23+
return $True
24+
}

Deploy/CreateOrImportSSL.ps1

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
###
2+
#
3+
# Import existing or create/issue new SSL certificate
4+
#
5+
# This script will do following steps:
6+
#
7+
# In Import Mode
8+
# 1. Execute Import script
9+
#
10+
# In Issuing Mode
11+
# 1. Execute Issuing script
12+
#
13+
# 2. Terraform execution to activate certificate
14+
#
15+
# After the script is successfully executed the Bot should be in a usable from within Bot Framework Service (WebChat) and Emulator
16+
#
17+
###
18+
# Parameters
19+
param(
20+
# Only needed in Issuing Mode
21+
[Parameter(HelpMessage="Mail to be associated with Let's Encrypt certificate")]
22+
[string] $YOUR_CERTIFICATE_EMAIL,
23+
24+
# Only needed in Issuing Mode
25+
[Parameter(HelpMessage="The domain (CN) name for the SSL certificate")]
26+
[string] $YOUR_DOMAIN,
27+
28+
[Parameter(HelpMessage="SSL CERT (PFX Format) file location")]
29+
[string] $PFX_FILE_LOCATION,
30+
31+
[Parameter(HelpMessage="SSL CERT (PFX Format) file password")]
32+
[string] $PFX_FILE_PASSWORD,
33+
34+
[Parameter(HelpMessage="KeyVault certificate name")]
35+
[string] $KEYVAULT_CERT_NAME = "SSLcert",
36+
37+
[Parameter(HelpMessage="Terraform and SSL creation Automation Flag. `$False -> Interactive, Approval `$True -> Automatic Approval")]
38+
[bool] $AUTOAPPROVE = $False,
39+
40+
[Parameter(HelpMessage="Flag to determine if run from within OneClickDeploy.ps1")]
41+
[bool] $ALREADYCONFIRMED = $False,
42+
43+
[Parameter(HelpMessage="Force Reimport or Reissuing if certificate already exists")]
44+
[bool] $FORCE = $False,
45+
46+
[Parameter(HelpMessage="To change existing infrastructure, e.g. skips DNS check. `$False -> first run/no infrastructure, `$True -> subsequent run, existing infrastructure")]
47+
[bool] $RERUN = $False
48+
)
49+
# Tell who you are
50+
Write-Host "`n`n# Executing $($MyInvocation.MyCommand.Name)"
51+
52+
# Helper Variable
53+
$success = $True
54+
$sslexists = $False
55+
56+
# Validate Input parameter combination
57+
$validationresult = .\ValidateParameter.ps1 -YOUR_CERTIFICATE_EMAIL $YOUR_CERTIFICATE_EMAIL -YOUR_DOMAIN $YOUR_DOMAIN -PFX_FILE_LOCATION $PFX_FILE_LOCATION -PFX_FILE_PASSWORD $PFX_FILE_PASSWORD -AUTOAPPROVE $AUTOAPPROVE -ALREADYCONFIRMED $ALREADYCONFIRMED
58+
59+
# Check if SSL Certificate exists
60+
if ($FORCE -eq $False)
61+
{
62+
$sslexists = .\CheckExistingSSL.ps1 -KEYVAULT_CERT_NAME $KEYVAULT_CERT_NAME
63+
}
64+
65+
if ($validationresult -and (-not $sslexists))
66+
{
67+
# 0. Deactivate SSL Endpoints (needed if you want to change the SSL for a <yourbot>.trafficmanager.net domain - not needed for custom domain)
68+
if ($FORCE -eq $True)
69+
{
70+
Write-Host "## 0. Deactivate SSL Endpoints"
71+
.\DeactivateSSL.ps1
72+
$success = $success -and $LASTEXITCODE
73+
}
74+
75+
# 1. Import SSL Certificate to KeyVault
76+
Write-Host "## 1. Import SSL Certificate to KeyVault"
77+
if (Test-Path -Path $PFX_FILE_LOCATION)
78+
{
79+
# Import Mode
80+
Write-Host "### Import Mode, load local PFX file"
81+
# Execute Import Script
82+
.\ImportSSL.ps1 -PFX_FILE_LOCATION $PFX_FILE_LOCATION -PFX_FILE_PASSWORD $PFX_FILE_PASSWORD -KEYVAULT_CERT_NAME $KEYVAULT_CERT_NAME
83+
$success = $success -and $LASTEXITCODE
84+
}
85+
else {
86+
# Issuing Mode
87+
Write-Host "### Issuing Mode, issue new certificate and directly upload it to KeyVault from within a container"
88+
.\CreateSSL.ps1 -YOUR_CERTIFICATE_EMAIL $YOUR_CERTIFICATE_EMAIL -YOUR_DOMAIN $YOUR_DOMAIN -KEYVAULT_CERT_NAME $KEYVAULT_CERT_NAME -AUTOAPPROVE $AUTOAPPROVE
89+
$success = $success -and $LASTEXITCODE
90+
}
91+
92+
}
93+
elseif ($sslexists -eq $True) {
94+
Write-Host "### WARNING, SSL Certificate with KeyVault name-key '$KEYVAULT_CERT_NAME' already exists.`n### If you want to recreate/upload a new one please use -FORCE `$True parameter."
95+
}
96+
97+
if ((($success -eq $True) -and ($validationresult -eq $True)) -or ($RERUN -eq $True))
98+
{
99+
# 2. Activate SSL Endpoint
100+
Write-Host "## 2. Activate SSL Endpoints"
101+
.\ActivateSSL.ps1 -YOUR_DOMAIN $YOUR_DOMAIN -AUTOAPPROVE $AUTOAPPROVE
102+
$success = $success -and $LASTEXITCODE
103+
}
104+
105+
# Return execution status
106+
exit $success

Deploy/CreateRegionVariableFile.ps1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
###
2+
#
3+
# Create Region Variable File for Terraform
4+
#
5+
# This script will do following steps:
6+
#
7+
# 1. Create content for variable file
8+
#
9+
###
10+
# Parameters
11+
param(
12+
[Parameter(Mandatory=$True, HelpMessage="Filename to use")]
13+
[string] $FILENAME,
14+
15+
[Parameter(HelpMessage="Regions to deploy the Bot to")]
16+
[string[]] $BOT_REGIONS = @("koreacentral", "southeastasia")
17+
)
18+
# Helper var
19+
$success = $True
20+
$priority = 0
21+
22+
# Tell who you are
23+
Write-Host "`n`n# Executing $($MyInvocation.MyCommand.Name)"
24+
25+
# 1. Create content for variable file
26+
Write-Host "## 1. Create content for variable file"
27+
28+
# See IaC/variables.tf format for azure_bot_regions (here in json format)
29+
$content = '{ "azure_bot_regions" : [' + $BOT_REGIONS.ForEach({
30+
"{ `"name`" : `"$_`", `"priority`" : $priority },"
31+
$priority++
32+
})
33+
$content = $content.TrimEnd(",") + ']}'
34+
35+
Set-Content -Path $azureBotRegions -Value $content
36+
$success = $success -and $?
37+
38+
# Check successful execution
39+
exit $success

0 commit comments

Comments
 (0)