Skip to content

Commit

Permalink
azurerm_api_management_api : fix service is unavailable while updat…
Browse files Browse the repository at this point in the history
…ing `azurerm_api_management_api` (hashicorp#23011)

* fix issue 22973

* update code
  • Loading branch information
sinbai authored Sep 18, 2023
1 parent 536c89a commit ff4c056
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ff4c056

Please sign in to comment.