diff --git a/internal/services/apimanagement/api_management_api_resource.go b/internal/services/apimanagement/api_management_api_resource.go index d89657647d8c..695211d6d6aa 100644 --- a/internal/services/apimanagement/api_management_api_resource.go +++ b/internal/services/apimanagement/api_management_api_resource.go @@ -420,6 +420,11 @@ func resourceApiManagementApiCreateUpdate(d *pluginsdk.ResourceData, meta interf ApiVersion: pointer.To(version), }, } + + if v, ok := d.GetOk("service_url"); ok { + apiParams.Properties.ServiceUrl = pointer.To(v.(string)) + } + wsdlSelectorVs := importV["wsdl_selector"].([]interface{}) if len(wsdlSelectorVs) > 0 { diff --git a/internal/services/apimanagement/api_management_api_resource_test.go b/internal/services/apimanagement/api_management_api_resource_test.go index 5896fd89ee30..9074c07e7cae 100644 --- a/internal/services/apimanagement/api_management_api_resource_test.go +++ b/internal/services/apimanagement/api_management_api_resource_test.go @@ -247,6 +247,44 @@ func TestAccApiManagementApi_importSwagger(t *testing.T) { }) } +func TestAccApiManagementApi_importSwaggerWithServiceUrl(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") + r := ApiManagementApiResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.importSwaggerWithServiceUrl(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + { + ResourceName: data.ResourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + // not returned from the API + "import", + }, + }, + { + Config: r.importSwaggerWithServiceUrlUpdate(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + { + ResourceName: data.ResourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + // not returned from the API + "import", + }, + }, + }) +} + func TestAccApiManagementApi_importWsdl(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") r := ApiManagementApiResource{} @@ -606,6 +644,52 @@ resource "azurerm_api_management_api" "test" { `, r.template(data, SkuNameConsumption), data.RandomInteger) } +func (r ApiManagementApiResource) importSwaggerWithServiceUrl(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_api_management_api" "test" { + name = "acctestapi-%d" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name + display_name = "api1" + path = "api1" + protocols = ["https"] + revision = "1" + description = "import swagger" + service_url = "https://example.com/foo/bar" + + import { + content_value = file("testdata/api_management_api_swagger.json") + content_format = "swagger-json" + } +} +`, r.template(data, SkuNameConsumption), data.RandomInteger) +} + +func (r ApiManagementApiResource) importSwaggerWithServiceUrlUpdate(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_api_management_api" "test" { + name = "acctestapi-%d" + resource_group_name = azurerm_resource_group.test.name + api_management_name = azurerm_api_management.test.name + display_name = "api1" + path = "api1" + protocols = ["https"] + revision = "1" + description = "import swagger update" + service_url = "https://example.com/foo/bar" + + import { + content_value = file("testdata/api_management_api_swagger.json") + content_format = "swagger-json" + } +} +`, r.template(data, SkuNameConsumption), data.RandomInteger) +} + func (r ApiManagementApiResource) importWsdl(data acceptance.TestData) string { return fmt.Sprintf(` %s