Skip to content

Commit e37951e

Browse files
committed
added TestAccApiManagementLogger_switchBetweenApplicationInsightsAndEventHub
1 parent a33f6be commit e37951e

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

internal/services/apimanagement/api_management_logger_resource_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010

1111
"github.com/hashicorp/go-azure-helpers/lang/pointer"
1212
"github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2022-08-01/logger"
13+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
14+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
1315
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
1416
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
1517
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
@@ -215,6 +217,72 @@ func TestAccApiManagementLogger_update(t *testing.T) {
215217
})
216218
}
217219

220+
func TestAccApiManagementLogger_switchBetweenApplicationInsightsAndEventHub(t *testing.T) {
221+
data := acceptance.BuildTestData(t, "azurerm_api_management_logger", "test")
222+
r := ApiManagementLoggerResource{}
223+
// switching between Application Insights and Event Hub requires recreation of the resource
224+
data.ResourceTestIgnoreRecreate(t, r, []acceptance.TestStep{
225+
{
226+
Config: r.basicEventHub(data),
227+
Check: acceptance.ComposeTestCheckFunc(
228+
check.That(data.ResourceName).ExistsInAzure(r),
229+
check.That(data.ResourceName).Key("buffered").HasValue("true"),
230+
check.That(data.ResourceName).Key("description").HasValue(""),
231+
check.That(data.ResourceName).Key("application_insights.#").HasValue("0"),
232+
check.That(data.ResourceName).Key("eventhub.#").HasValue("1"),
233+
check.That(data.ResourceName).Key("eventhub.0.name").Exists(),
234+
check.That(data.ResourceName).Key("eventhub.0.connection_string").Exists(),
235+
),
236+
},
237+
{
238+
Config: r.basicApplicationInsights(data),
239+
ConfigPlanChecks: expectResourceActionCheck(data.ResourceName, plancheck.ResourceActionReplace),
240+
Check: acceptance.ComposeTestCheckFunc(
241+
check.That(data.ResourceName).ExistsInAzure(r),
242+
check.That(data.ResourceName).Key("buffered").HasValue("true"),
243+
check.That(data.ResourceName).Key("description").HasValue(""),
244+
check.That(data.ResourceName).Key("eventhub.#").HasValue("0"),
245+
check.That(data.ResourceName).Key("application_insights.#").HasValue("1"),
246+
check.That(data.ResourceName).Key("application_insights.0.instrumentation_key").Exists(),
247+
),
248+
},
249+
{
250+
Config: r.complete(data, "Logger from Terraform test", "false"),
251+
ConfigPlanChecks: expectResourceActionCheck(data.ResourceName, plancheck.ResourceActionReplace),
252+
Check: acceptance.ComposeTestCheckFunc(
253+
check.That(data.ResourceName).ExistsInAzure(r),
254+
check.That(data.ResourceName).Key("buffered").HasValue("false"),
255+
check.That(data.ResourceName).Key("description").HasValue("Logger from Terraform test"),
256+
check.That(data.ResourceName).Key("eventhub.#").HasValue("0"),
257+
check.That(data.ResourceName).Key("application_insights.#").HasValue("1"),
258+
check.That(data.ResourceName).Key("application_insights.0.instrumentation_key").Exists(),
259+
check.That(data.ResourceName).Key("resource_id").Exists(),
260+
),
261+
},
262+
{
263+
Config: r.basicEventHub(data),
264+
ConfigPlanChecks: expectResourceActionCheck(data.ResourceName, plancheck.ResourceActionReplace),
265+
Check: acceptance.ComposeTestCheckFunc(
266+
check.That(data.ResourceName).ExistsInAzure(r),
267+
check.That(data.ResourceName).Key("buffered").HasValue("true"),
268+
check.That(data.ResourceName).Key("description").HasValue(""),
269+
check.That(data.ResourceName).Key("application_insights.#").HasValue("0"),
270+
check.That(data.ResourceName).Key("eventhub.#").HasValue("1"),
271+
check.That(data.ResourceName).Key("eventhub.0.name").Exists(),
272+
check.That(data.ResourceName).Key("eventhub.0.connection_string").Exists(),
273+
),
274+
},
275+
})
276+
}
277+
278+
func expectResourceActionCheck(resourceName string, action plancheck.ResourceActionType) resource.ConfigPlanChecks {
279+
return resource.ConfigPlanChecks{
280+
PreApply: []plancheck.PlanCheck{
281+
plancheck.ExpectResourceAction(resourceName, action),
282+
},
283+
}
284+
}
285+
218286
func (ApiManagementLoggerResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
219287
id, err := logger.ParseLoggerID(state.ID)
220288
if err != nil {

0 commit comments

Comments
 (0)