-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource:
azurerm_bot_channels_registration
(#4245)
- Loading branch information
Showing
20 changed files
with
6,238 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package bot | ||
|
||
import ( | ||
"github.com/Azure/azure-sdk-for-go/services/preview/botservice/mgmt/2018-07-12/botservice" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common" | ||
) | ||
|
||
type Client struct { | ||
BotClient *botservice.BotsClient | ||
} | ||
|
||
func BuildClient(o *common.ClientOptions) *Client { | ||
|
||
BotClient := botservice.NewBotsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) | ||
o.ConfigureClient(&BotClient.Client, o.ResourceManagerAuthorizer) | ||
|
||
return &Client{ | ||
BotClient: &BotClient, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,268 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/preview/botservice/mgmt/2018-07-12/botservice" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/features" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func resourceArmBotChannelsRegistration() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceArmBotChannelsRegistrationCreate, | ||
Read: resourceArmBotChannelsRegistrationRead, | ||
Delete: resourceArmBotChannelsRegistrationDelete, | ||
Update: resourceArmBotChannelsRegistrationUpdate, | ||
|
||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validate.CosmosEntityName, | ||
}, | ||
|
||
"resource_group_name": azure.SchemaResourceGroupName(), | ||
|
||
"location": azure.SchemaLocation(), | ||
|
||
"sku": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validation.StringInSlice([]string{ | ||
string(botservice.F0), | ||
string(botservice.S1), | ||
}, false), | ||
}, | ||
|
||
"microsoft_app_id": { | ||
Type: schema.TypeString, | ||
ForceNew: true, | ||
Required: true, | ||
ValidateFunc: azure.ValidateResourceID, | ||
}, | ||
|
||
"display_name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ValidateFunc: validate.NoEmptyStrings, | ||
}, | ||
|
||
"endpoint": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ValidateFunc: validate.NoEmptyStrings, | ||
}, | ||
|
||
"developer_app_insights_key": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ValidateFunc: validate.UUID, | ||
}, | ||
|
||
"developer_app_insights_api_key": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
Sensitive: true, | ||
ValidateFunc: validate.NoEmptyStrings, | ||
}, | ||
|
||
"developer_app_insights_application_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ValidateFunc: validate.UUID, | ||
}, | ||
|
||
"tags": tags.Schema(), | ||
}, | ||
} | ||
} | ||
|
||
func resourceArmBotChannelsRegistrationCreate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).bot.BotClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
|
||
if features.ShouldResourcesBeImported() && d.IsNewResource() { | ||
existing, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
if !utils.ResponseWasNotFound(existing.Response) { | ||
return fmt.Errorf("Error checking for presence of creating Bot Channels Registration %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
} else { | ||
id, err := azure.CosmosGetIDFromResponse(existing.Response) | ||
if err != nil { | ||
return fmt.Errorf("Error generating import ID for Bot Channels Registration %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
return tf.ImportAsExistsError("azurerm_bot", id) | ||
} | ||
} | ||
|
||
t := d.Get("tags").(map[string]interface{}) | ||
displayName := d.Get("display_name").(string) | ||
if displayName == "" { | ||
displayName = name | ||
} | ||
|
||
bot := botservice.Bot{ | ||
Properties: &botservice.BotProperties{ | ||
DisplayName: utils.String(displayName), | ||
Endpoint: utils.String(d.Get("endpoint").(string)), | ||
MsaAppID: utils.String(d.Get("microsoft_app_id").(string)), | ||
DeveloperAppInsightKey: utils.String(d.Get("developer_app_insights_key").(string)), | ||
DeveloperAppInsightsAPIKey: utils.String(d.Get("developer_app_insights_api_key").(string)), | ||
DeveloperAppInsightsApplicationID: utils.String(d.Get("developer_app_insights_application_id").(string)), | ||
}, | ||
Location: utils.String(d.Get("location").(string)), | ||
Sku: &botservice.Sku{ | ||
Name: botservice.SkuName(d.Get("sku").(string)), | ||
}, | ||
Kind: botservice.KindBot, | ||
Tags: tags.Expand(t), | ||
} | ||
|
||
if _, err := client.Create(ctx, resourceGroup, name, bot); err != nil { | ||
return fmt.Errorf("Error issuing create request for Bot Channels Registration %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
resp, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
return fmt.Errorf("Error making get request for Bot Channels Registration %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
if resp.ID == nil { | ||
return fmt.Errorf("Cannot read Bot Channels Registration %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
return resourceArmBotChannelsRegistrationRead(d, meta) | ||
} | ||
|
||
func resourceArmBotChannelsRegistrationRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).bot.BotClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
id, err := azure.ParseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
name := id.Path["botServices"] | ||
|
||
resp, err := client.Get(ctx, id.ResourceGroup, name) | ||
if err != nil { | ||
if utils.ResponseWasNotFound(resp.Response) { | ||
log.Printf("[INFO] Error reading Bot Channels Registration %q (Resource Group %q) - removing from state", name, id.ResourceGroup) | ||
d.SetId("") | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("Error reading Bot Channels Registration %q (Resource Group %q): %+v", name, id.ResourceGroup, err) | ||
} | ||
|
||
d.Set("resource_group_name", id.ResourceGroup) | ||
d.Set("name", resp.Name) | ||
d.Set("location", resp.Location) | ||
|
||
if sku := resp.Sku; sku != nil { | ||
d.Set("sku", string(sku.Name)) | ||
} | ||
|
||
if props := resp.Properties; props != nil { | ||
d.Set("microsoft_app_id", props.MsaAppID) | ||
d.Set("endpoint", props.Endpoint) | ||
d.Set("display_name", props.DisplayName) | ||
d.Set("developer_app_insights_key", props.DeveloperAppInsightKey) | ||
d.Set("developer_app_insights_application_id", props.DeveloperAppInsightsApplicationID) | ||
} | ||
|
||
return tags.FlattenAndSet(d, resp.Tags) | ||
} | ||
|
||
func resourceArmBotChannelsRegistrationUpdate(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).bot.BotClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
name := d.Get("name").(string) | ||
resourceGroup := d.Get("resource_group_name").(string) | ||
t := d.Get("tags").(map[string]interface{}) | ||
displayName := d.Get("display_name").(string) | ||
if displayName == "" { | ||
displayName = name | ||
} | ||
|
||
bot := botservice.Bot{ | ||
Properties: &botservice.BotProperties{ | ||
DisplayName: utils.String(displayName), | ||
Endpoint: utils.String(d.Get("endpoint").(string)), | ||
MsaAppID: utils.String(d.Get("microsoft_app_id").(string)), | ||
DeveloperAppInsightKey: utils.String(d.Get("developer_app_insights_key").(string)), | ||
DeveloperAppInsightsAPIKey: utils.String(d.Get("developer_app_insights_api_key").(string)), | ||
DeveloperAppInsightsApplicationID: utils.String(d.Get("developer_app_insights_application_id").(string)), | ||
}, | ||
Location: utils.String(d.Get("location").(string)), | ||
Sku: &botservice.Sku{ | ||
Name: botservice.SkuName(d.Get("sku").(string)), | ||
}, | ||
Kind: botservice.KindBot, | ||
Tags: tags.Expand(t), | ||
} | ||
|
||
if _, err := client.Update(ctx, resourceGroup, name, bot); err != nil { | ||
return fmt.Errorf("Error issuing update request for Bot Channels Registration %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
resp, err := client.Get(ctx, resourceGroup, name) | ||
if err != nil { | ||
return fmt.Errorf("Error making get request for Bot Channels Registration %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
if resp.ID == nil { | ||
return fmt.Errorf("Cannot read Bot Channels Registration %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
return resourceArmBotChannelsRegistrationRead(d, meta) | ||
} | ||
|
||
func resourceArmBotChannelsRegistrationDelete(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).bot.BotClient | ||
ctx := meta.(*ArmClient).StopContext | ||
|
||
id, err := azure.ParseAzureResourceID(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
name := id.Path["botServices"] | ||
|
||
resp, err := client.Delete(ctx, id.ResourceGroup, name) | ||
if err != nil { | ||
if !response.WasNotFound(resp.Response) { | ||
return fmt.Errorf("Error deleting Bot Channels Registration %q (Resource Group %q): %+v", name, id.ResourceGroup, err) | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.