This repo demonstrates how to use Azure Functions to provision a Microsoft Teams team and channel using the Microsoft Graph API. The function is triggered by a message on an Azure Service Bus queue. The function is written in PowerShell.
The Infrastructure as Code (IaC) is written in Terraform.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
Modify the
infra/env/dev.tfvars
file to match your environment -
Initialize Terraform locally
terraform init
-
Format the Terraform code
terraform fmt
-
Create a Terraform plan
terraform plan --var-file ./env/dev.tfvars
-
Apply the Terraform plan
terraform apply --var-file ./env/dev.tfvars
-
Deploy the Azure Function App
func azure functionapp publish func-funcSbTeams-ussc-dev
-
Put a message on the queue
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ..." -d '{ "clientCallback": { "type": "webhook", "method": "POST", "uri": "http://localhost", "token": "asdf" }, "request": { "userPrincipalName": "testTerraform@MngEnv472967.onmicrosoft.com", "teamName": "PowerShellCreatedTeam", "channelName": "PowerShellCreatedChannel" }}' https://sb-funcsbteams-ussc-dev.servicebus.windows.net/provision-teams/messages
-
Update the
local.settings.json
file to match your environment -
Run locally
func start
-
Add the following line to the PowerShell script
Wait-Debugger
-
Start the script
func start
-
Find the process ID
Get-PSHostProcessInfo
-
Look for the
dotnet
process name.ProcessName ProcessId AppDomainName ----------- --------- ------------- dotnet 49988 None pwsh 43796 None pwsh 49970 None pwsh 3533 None pwsh 79544 None pwsh 34881 None pwsh 32071 None pwsh 88785 None
-
Run the following commands to attach the debugger
$pid = 49988 Enter-PSHostProcess -Id $pid Debug-Runspace 1