Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check for available service provider - azurerm_bot_connection #7279

Merged
merged 5 commits into from Jun 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 34 additions & 5 deletions azurerm/internal/services/bot/bot_connection_resource.go
Expand Up @@ -3,6 +3,7 @@ package bot
import (
"fmt"
"log"
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/preview/botservice/mgmt/2018-07-12/botservice"
Expand Down Expand Up @@ -112,13 +113,41 @@ func resourceArmBotConnectionCreate(d *schema.ResourceData, meta interface{}) er
}
}

serviceProviderName := d.Get("service_provider_name").(string)
var serviceProviderId *string
var availableProviders []string

serviceProviders, err := client.ListServiceProviders(ctx)
if err != nil {
return fmt.Errorf("listing Bot Connection service provider: %+v", err)
}

if serviceProviders.Value == nil {
return fmt.Errorf("no service providers were returned from the Azure API")
}
for _, provider := range *serviceProviders.Value {
if provider.Properties == nil || provider.Properties.ServiceProviderName == nil {
continue
}
name := provider.Properties.ServiceProviderName
if strings.EqualFold(serviceProviderName, *name) {
serviceProviderId = provider.Properties.ID
break
}
availableProviders = append(availableProviders, *name)
}

if serviceProviderId == nil {
return fmt.Errorf("the Service Provider %q was not found. The available service providers are %s", serviceProviderName, strings.Join(availableProviders, ","))
}

connection := botservice.ConnectionSetting{
Properties: &botservice.ConnectionSettingProperties{
ServiceProviderDisplayName: utils.String(d.Get("service_provider_name").(string)),
ClientID: utils.String(d.Get("client_id").(string)),
ClientSecret: utils.String(d.Get("client_secret").(string)),
Scopes: utils.String(d.Get("scopes").(string)),
Parameters: expandAzureRMBotConnectionParameters(d.Get("parameters").(map[string]interface{})),
ServiceProviderID: serviceProviderId,
ClientID: utils.String(d.Get("client_id").(string)),
ClientSecret: utils.String(d.Get("client_secret").(string)),
Scopes: utils.String(d.Get("scopes").(string)),
Parameters: expandAzureRMBotConnectionParameters(d.Get("parameters").(map[string]interface{})),
},
Kind: botservice.KindBot,
Location: utils.String(d.Get("location").(string)),
Expand Down