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 1 commit
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
30 changes: 29 additions & 1 deletion azurerm/internal/services/bot/bot_connection_resource.go
Expand Up @@ -112,9 +112,37 @@ func resourceArmBotConnectionCreate(d *schema.ResourceData, meta interface{}) er
}
}

serviceProviderName := d.Get("service_provider_name").(string)
serviceProviderFound := false
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 available service provider %+v", serviceProviders)
njuCZ marked this conversation as resolved.
Show resolved Hide resolved
}
for _, provider := range *serviceProviders.Value {
if provider.Properties == nil || provider.Properties.ServiceProviderName == nil {
continue
}
name := provider.Properties.ServiceProviderName
if serviceProviderName == *name {
serviceProviderFound = true
break
}
availableProviders = append(availableProviders, *name)
}

if !serviceProviderFound {
return fmt.Errorf("invalid Service Provider Name. available service providers are: %+v", availableProviders)
njuCZ marked this conversation as resolved.
Show resolved Hide resolved
}

connection := botservice.ConnectionSetting{
Properties: &botservice.ConnectionSettingProperties{
ServiceProviderDisplayName: utils.String(d.Get("service_provider_name").(string)),
ServiceProviderDisplayName: utils.String(serviceProviderName),
ClientID: utils.String(d.Get("client_id").(string)),
ClientSecret: utils.String(d.Get("client_secret").(string)),
Scopes: utils.String(d.Get("scopes").(string)),
Expand Down