diff --git a/internal/services/apimanagement/api_management_api_resource.go b/internal/services/apimanagement/api_management_api_resource.go index 695211d6d6aa..0f6590f91293 100644 --- a/internal/services/apimanagement/api_management_api_resource.go +++ b/internal/services/apimanagement/api_management_api_resource.go @@ -441,10 +441,9 @@ func resourceApiManagementApiCreateUpdate(d *pluginsdk.ResourceData, meta interf if versionSetId != "" { apiParams.Properties.ApiVersionSetId = pointer.To(versionSetId) } - if err := client.CreateOrUpdateThenPoll(ctx, id, apiParams, api.CreateOrUpdateOperationOptions{}); err != nil { + if err := client.CreateOrUpdateThenPoll(ctx, newId, apiParams, api.CreateOrUpdateOperationOptions{}); err != nil { return fmt.Errorf("creating/updating %s: %+v", id, err) } - } description := d.Get("description").(string) diff --git a/internal/services/apimanagement/api_management_api_resource_test.go b/internal/services/apimanagement/api_management_api_resource_test.go index 9074c07e7cae..b3ebf236be3f 100644 --- a/internal/services/apimanagement/api_management_api_resource_test.go +++ b/internal/services/apimanagement/api_management_api_resource_test.go @@ -247,6 +247,29 @@ func TestAccApiManagementApi_importSwagger(t *testing.T) { }) } +func TestAccApiManagementApi_importOpenapi(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") + r := ApiManagementApiResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.importOpenapi(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_importSwaggerWithServiceUrl(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") r := ApiManagementApiResource{} @@ -644,6 +667,27 @@ resource "azurerm_api_management_api" "test" { `, r.template(data, SkuNameConsumption), data.RandomInteger) } +func (r ApiManagementApiResource) importOpenapi(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 = "current" + + import { + content_value = file("testdata/api_management_api_openapi.yaml") + content_format = "openapi" + } +} +`, r.template(data, SkuNameConsumption), data.RandomInteger) +} + func (r ApiManagementApiResource) importSwaggerWithServiceUrl(data acceptance.TestData) string { return fmt.Sprintf(` %s diff --git a/internal/services/apimanagement/testdata/api_management_api_openapi.yaml b/internal/services/apimanagement/testdata/api_management_api_openapi.yaml new file mode 100644 index 000000000000..b51291b7ebf5 --- /dev/null +++ b/internal/services/apimanagement/testdata/api_management_api_openapi.yaml @@ -0,0 +1,33 @@ +openapi: 3.0.0 +info: + title: api1 + description: api + version: 1.0.0 +servers: + - url: "https://terraform.com/test/v1/api1" + description: test +paths: + /default: + post: + operationId: default + summary: Default + description: Default operation + responses: + "200": + description: Accepted + content: + application/json: + schema: + $ref: "#/components/schemas/response" +components: + schemas: + response: + type: object + properties: + status: + type: string + example: success + securitySchemes: + basicAuth: + type: http + scheme: basic \ No newline at end of file