robvet / func-sb-teams

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

func-sb-teams

architecture

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.

Disclaimer

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.

Prerequisites

Deployment

  1. Modify the infra/env/dev.tfvars file to match your environment

  2. Initialize Terraform locally

    terraform init
  3. Format the Terraform code

    terraform fmt
  4. Create a Terraform plan

    terraform plan --var-file ./env/dev.tfvars
  5. Apply the Terraform plan

    terraform apply --var-file ./env/dev.tfvars
  6. Deploy the Azure Function App

    func azure functionapp publish func-funcSbTeams-ussc-dev

Testing

  1. 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

Run locally

  1. Update the local.settings.json file to match your environment

  2. Run locally

    func start

Debug locally

  1. Add the following line to the PowerShell script

    Wait-Debugger
  2. Start the script

    func start
  3. Find the process ID

    Get-PSHostProcessInfo
  4. 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
  5. Run the following commands to attach the debugger

    $pid = 49988
    Enter-PSHostProcess -Id $pid
    
    Debug-Runspace 1

Links

About

License:MIT License


Languages

Language:HCL 72.2%Language:PowerShell 27.8%