Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
neil-yechenwei committed May 13, 2022
1 parent a8bc433 commit edd4b51
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 23 deletions.
23 changes: 16 additions & 7 deletions internal/services/bot/bot_connection_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/bot/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

func resourceArmBotConnection() *pluginsdk.Resource {
return &pluginsdk.Resource{
resource := &pluginsdk.Resource{
Create: resourceArmBotConnectionCreate,
Read: resourceArmBotConnectionRead,
Update: resourceArmBotConnectionUpdate,
Expand Down Expand Up @@ -90,10 +90,21 @@ func resourceArmBotConnection() *pluginsdk.Resource {
Type: pluginsdk.TypeString,
},
},

"tags": tags.Schema(),
},
}

if !features.FourPointOhBeta() {
resource.Schema["tags"] = &pluginsdk.Schema{
Type: pluginsdk.TypeMap,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
Deprecated: "This property has been deprecated as the API no longer supports tags and will be removed in version 4.0 of the provider.",
}
}

return resource
}

func resourceArmBotConnectionCreate(d *pluginsdk.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -152,7 +163,6 @@ func resourceArmBotConnectionCreate(d *pluginsdk.ResourceData, meta interface{})
},
Kind: botservice.KindBot,
Location: utils.String(d.Get("location").(string)),
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

if v, ok := d.GetOk("parameters"); ok {
Expand Down Expand Up @@ -201,7 +211,7 @@ func resourceArmBotConnectionRead(d *pluginsdk.ResourceData, meta interface{}) e
}
}

return tags.FlattenAndSet(d, resp.Tags)
return nil
}

func resourceArmBotConnectionUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
Expand All @@ -223,7 +233,6 @@ func resourceArmBotConnectionUpdate(d *pluginsdk.ResourceData, meta interface{})
},
Kind: botservice.KindBot,
Location: utils.String(d.Get("location").(string)),
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

if v, ok := d.GetOk("parameters"); ok {
Expand Down
62 changes: 46 additions & 16 deletions internal/services/bot/bot_connection_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (t BotConnectionResource) Exists(ctx context.Context, clients *clients.Clie
return utils.Bool(resp.Properties != nil), nil
}

func (BotConnectionResource) basicConfig(data acceptance.TestData) string {
func (r BotConnectionResource) basicConfig(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand All @@ -76,13 +76,13 @@ resource "azurerm_bot_connection" "test" {
location = azurerm_bot_channels_registration.test.location
resource_group_name = azurerm_resource_group.test.name
service_provider_name = "box"
client_id = "test"
client_secret = "secret"
client_id = data.azurerm_client_config.current.client_id
client_secret = "86546868-e7ed-429f-b0e5-3a1caea7db64"
}
`, BotChannelsRegistrationResource{}.basicConfig(data), data.RandomInteger)
`, r.template(data), data.RandomInteger)
}

func (BotConnectionResource) completeConfig(data acceptance.TestData) string {
func (r BotConnectionResource) completeConfig(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand All @@ -92,34 +92,64 @@ resource "azurerm_bot_connection" "test" {
location = azurerm_bot_channels_registration.test.location
resource_group_name = azurerm_resource_group.test.name
service_provider_name = "Salesforce"
client_id = "test"
client_secret = "secret"
scopes = "testscope"
client_id = data.azurerm_client_config.current.client_id
client_secret = "60a97b1d-0894-4c5a-9968-7d1d29d77aed"
scopes = "/subscriptions/${data.azurerm_client_config.current.subscription_id}"
parameters = {
loginUri = "www.example.com"
loginUri = "https://www.google.com"
}
}
`, BotChannelsRegistrationResource{}.basicConfig(data), data.RandomInteger)
`, r.template(data), data.RandomInteger)
}

func (BotConnectionResource) completeUpdateConfig(data acceptance.TestData) string {
func (r BotConnectionResource) completeUpdateConfig(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_user_assigned_identity" "test" {
name = "acctestUAI-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}
resource "azurerm_bot_connection" "test" {
name = "acctestBc%d"
bot_name = azurerm_bot_channels_registration.test.name
location = azurerm_bot_channels_registration.test.location
resource_group_name = azurerm_resource_group.test.name
service_provider_name = "Salesforce"
client_id = "test2"
client_secret = "secret2"
scopes = "testscope2"
client_id = azurerm_user_assigned_identity.test.client_id
client_secret = "32ea21cb-cb20-4df9-ad39-b55e985e9117"
scopes = "/subscriptions/${data.azurerm_client_config.current.subscription_id}/resourceGroups/${azurerm_resource_group.test.name}"
parameters = {
loginUri = "www.example2.com"
loginUri = "https://www.terraform.io"
}
}
`, BotChannelsRegistrationResource{}.basicConfig(data), data.RandomInteger)
`, r.template(data), data.RandomInteger, data.RandomInteger)
}

func (r BotConnectionResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
data "azurerm_client_config" "current" {
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_bot_channels_registration" "test" {
name = "acctestdf%d"
location = "global"
resource_group_name = azurerm_resource_group.test.name
sku = "F0"
microsoft_app_id = data.azurerm_client_config.current.client_id
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}
1 change: 1 addition & 0 deletions website/docs/r/bot_connection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ The following arguments are supported:

* `tags` - (Optional) A mapping of tags to assign to the resource.

-> **Note:** `tags` has been deprecated as the API no longer supports it and will be removed in version 4.0 of the provider.

## Attributes Reference

Expand Down

0 comments on commit edd4b51

Please sign in to comment.