Skip to content

Commit 54102ed

Browse files
azurerm_bot_channels_registration - add microsoft_app_type, microsoft_app_tenant_id, microsoft_app_user_assigned_identity_id (#30457)
Co-authored-by: sreallymatt <106555974+sreallymatt@users.noreply.github.com>
1 parent 09b6cfa commit 54102ed

4 files changed

Lines changed: 195 additions & 284 deletions

File tree

internal/services/bot/bot_channels_registration_resource.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/hashicorp/go-azure-helpers/lang/pointer"
1313
"github.com/hashicorp/go-azure-helpers/lang/response"
14+
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
1415
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
1516
"github.com/hashicorp/go-azure-helpers/resourcemanager/keyvault"
1617
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
@@ -96,6 +97,31 @@ func resourceBotChannelsRegistration() *pluginsdk.Resource {
9697
ValidateFunc: validation.IsUUID,
9798
},
9899

100+
"microsoft_app_type": {
101+
Type: pluginsdk.TypeString,
102+
Required: true,
103+
ForceNew: true,
104+
ValidateFunc: validation.StringInSlice([]string{
105+
string(botservice.MsaAppTypeMultiTenant),
106+
string(botservice.MsaAppTypeSingleTenant),
107+
string(botservice.MsaAppTypeUserAssignedMSI),
108+
}, false),
109+
},
110+
111+
"microsoft_app_tenant_id": {
112+
Type: pluginsdk.TypeString,
113+
Optional: true,
114+
ForceNew: true,
115+
ValidateFunc: validation.IsUUID,
116+
},
117+
118+
"microsoft_app_user_assigned_identity_id": {
119+
Type: pluginsdk.TypeString,
120+
Optional: true,
121+
ForceNew: true,
122+
ValidateFunc: commonids.ValidateUserAssignedIdentityID,
123+
},
124+
99125
"cmk_key_vault_url": {
100126
Type: pluginsdk.TypeString,
101127
Optional: true,
@@ -164,6 +190,19 @@ func resourceBotChannelsRegistration() *pluginsdk.Resource {
164190

165191
if !features.FivePointOh() {
166192
resource.Schema["cmk_key_vault_url"].ValidateFunc = keyvault.ValidateNestedItemID(keyvault.VersionTypeAny, keyvault.NestedItemTypeAny)
193+
194+
resource.Schema["microsoft_app_type"] = &pluginsdk.Schema{
195+
Type: pluginsdk.TypeString,
196+
Optional: true,
197+
// O+C because Azure sets a value for this if omitted
198+
Computed: true,
199+
ForceNew: true,
200+
ValidateFunc: validation.StringInSlice([]string{
201+
string(botservice.MsaAppTypeMultiTenant),
202+
string(botservice.MsaAppTypeSingleTenant),
203+
string(botservice.MsaAppTypeUserAssignedMSI),
204+
}, false),
205+
}
167206
}
168207

169208
return resource
@@ -197,6 +236,7 @@ func resourceBotChannelsRegistrationCreate(d *pluginsdk.ResourceData, meta inter
197236
Properties: &botservice.BotProperties{
198237
DisplayName: pointer.To(displayName),
199238
Endpoint: pointer.To(d.Get("endpoint").(string)),
239+
MsaAppType: botservice.MsaAppType(d.Get("microsoft_app_type").(string)),
200240
MsaAppID: pointer.To(d.Get("microsoft_app_id").(string)),
201241
CmekKeyVaultURL: pointer.To(d.Get("cmk_key_vault_url").(string)),
202242
Description: pointer.To(d.Get("description").(string)),
@@ -219,6 +259,14 @@ func resourceBotChannelsRegistrationCreate(d *pluginsdk.ResourceData, meta inter
219259
bot.Properties.IsCmekEnabled = pointer.To(true)
220260
}
221261

262+
if v, ok := d.GetOk("microsoft_app_tenant_id"); ok {
263+
bot.Properties.MsaAppTenantID = pointer.To(v.(string))
264+
}
265+
266+
if v, ok := d.GetOk("microsoft_app_user_assigned_identity_id"); ok {
267+
bot.Properties.MsaAppMSIResourceID = pointer.To(v.(string))
268+
}
269+
222270
if _, err := client.Create(ctx, resourceId.ResourceGroup, resourceId.Name, bot); err != nil {
223271
return fmt.Errorf("creating Bot Channels Registration %q (Resource Group %q): %+v", resourceId.Name, resourceId.ResourceGroup, err)
224272
}
@@ -266,6 +314,9 @@ func resourceBotChannelsRegistrationRead(d *pluginsdk.ResourceData, meta interfa
266314
if props := resp.Properties; props != nil {
267315
d.Set("cmk_key_vault_url", props.CmekKeyVaultURL)
268316
d.Set("microsoft_app_id", props.MsaAppID)
317+
d.Set("microsoft_app_type", string(props.MsaAppType))
318+
d.Set("microsoft_app_tenant_id", pointer.From(props.MsaAppTenantID))
319+
d.Set("microsoft_app_user_assigned_identity_id", pointer.From(props.MsaAppMSIResourceID))
269320
d.Set("endpoint", props.Endpoint)
270321
d.Set("description", props.Description)
271322
d.Set("display_name", props.DisplayName)
@@ -304,6 +355,7 @@ func resourceBotChannelsRegistrationUpdate(d *pluginsdk.ResourceData, meta inter
304355
DisplayName: pointer.To(displayName),
305356
Endpoint: pointer.To(d.Get("endpoint").(string)),
306357
MsaAppID: pointer.To(d.Get("microsoft_app_id").(string)),
358+
MsaAppType: botservice.MsaAppType(d.Get("microsoft_app_type").(string)),
307359
CmekKeyVaultURL: pointer.To(d.Get("cmk_key_vault_url").(string)),
308360
Description: pointer.To(d.Get("description").(string)),
309361
DeveloperAppInsightKey: pointer.To(d.Get("developer_app_insights_key").(string)),
@@ -325,6 +377,14 @@ func resourceBotChannelsRegistrationUpdate(d *pluginsdk.ResourceData, meta inter
325377
bot.Properties.IsCmekEnabled = pointer.To(true)
326378
}
327379

380+
if v, ok := d.GetOk("microsoft_app_tenant_id"); ok {
381+
bot.Properties.MsaAppTenantID = pointer.To(v.(string))
382+
}
383+
384+
if v, ok := d.GetOk("microsoft_app_user_assigned_identity_id"); ok {
385+
bot.Properties.MsaAppMSIResourceID = pointer.To(v.(string))
386+
}
387+
328388
// d.GetOk cannot identify whether user sets the property that is bool type and `public_network_access_enabled` is set as `false`. So it has to identify it using `d.GetRawConfig()`
329389
if v := d.GetRawConfig().AsValueMap()["public_network_access_enabled"]; !v.IsNull() {
330390
publicNetworkAccessEnabled := botservice.PublicNetworkAccessEnabled

0 commit comments

Comments
 (0)