From fc2b3787b92660a9cd496f62a4ff3e3584ec7421 Mon Sep 17 00:00:00 2001 From: "Elena Xin (Centific Technologies Inc)" Date: Thu, 21 Sep 2023 17:46:24 +0800 Subject: [PATCH 1/3] fix import openai issue --- .../api_management_api_resource.go | 5 +-- .../api_management_api_resource_test.go | 44 +++++++++++++++++++ .../testdata/api_management_api_openai.yaml | 33 ++++++++++++++ 3 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 internal/services/apimanagement/testdata/api_management_api_openai.yaml diff --git a/internal/services/apimanagement/api_management_api_resource.go b/internal/services/apimanagement/api_management_api_resource.go index 695211d6d6aa..e46f3b943f2b 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) @@ -522,7 +521,7 @@ func resourceApiManagementApiRead(d *pluginsdk.ResourceData, meta interface{}) e } name := getApiName(id.ApiId) - newId := api.NewApiID(id.SubscriptionId, id.ResourceGroupName, id.ServiceName, name) + newId := api.NewApiID(id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) resp, err := client.Get(ctx, newId) if err != nil { if response.WasNotFound(resp.HttpResponse) { diff --git a/internal/services/apimanagement/api_management_api_resource_test.go b/internal/services/apimanagement/api_management_api_resource_test.go index 9074c07e7cae..ac851a09c61a 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_importOpenai(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management_api", "test") + r := ApiManagementApiResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.importOpenai(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) importOpenai(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_openai.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_openai.yaml b/internal/services/apimanagement/testdata/api_management_api_openai.yaml new file mode 100644 index 000000000000..b51291b7ebf5 --- /dev/null +++ b/internal/services/apimanagement/testdata/api_management_api_openai.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 From 424df1bb4aba74625cb4f2ff935135fa50d9e203 Mon Sep 17 00:00:00 2001 From: "Elena Xin (Centific Technologies Inc)" Date: Thu, 21 Sep 2023 18:22:59 +0800 Subject: [PATCH 2/3] update code --- .../apimanagement/api_management_api_resource_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/services/apimanagement/api_management_api_resource_test.go b/internal/services/apimanagement/api_management_api_resource_test.go index ac851a09c61a..d5be265ac795 100644 --- a/internal/services/apimanagement/api_management_api_resource_test.go +++ b/internal/services/apimanagement/api_management_api_resource_test.go @@ -247,13 +247,13 @@ func TestAccApiManagementApi_importSwagger(t *testing.T) { }) } -func TestAccApiManagementApi_importOpenai(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.importOpenai(data), + Config: r.importOpenapi(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), @@ -667,7 +667,7 @@ resource "azurerm_api_management_api" "test" { `, r.template(data, SkuNameConsumption), data.RandomInteger) } -func (r ApiManagementApiResource) importOpenai(data acceptance.TestData) string { +func (r ApiManagementApiResource) importOpenapi(data acceptance.TestData) string { return fmt.Sprintf(` %s From 7b8ca801b3564cc591fe1e343f183b7f5425e834 Mon Sep 17 00:00:00 2001 From: "Elena Xin (Centific Technologies Inc)" Date: Fri, 22 Sep 2023 09:36:36 +0800 Subject: [PATCH 3/3] update code --- internal/services/apimanagement/api_management_api_resource.go | 2 +- .../services/apimanagement/api_management_api_resource_test.go | 2 +- ...nagement_api_openai.yaml => api_management_api_openapi.yaml} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename internal/services/apimanagement/testdata/{api_management_api_openai.yaml => api_management_api_openapi.yaml} (100%) diff --git a/internal/services/apimanagement/api_management_api_resource.go b/internal/services/apimanagement/api_management_api_resource.go index e46f3b943f2b..0f6590f91293 100644 --- a/internal/services/apimanagement/api_management_api_resource.go +++ b/internal/services/apimanagement/api_management_api_resource.go @@ -521,7 +521,7 @@ func resourceApiManagementApiRead(d *pluginsdk.ResourceData, meta interface{}) e } name := getApiName(id.ApiId) - newId := api.NewApiID(id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.ApiId) + newId := api.NewApiID(id.SubscriptionId, id.ResourceGroupName, id.ServiceName, name) resp, err := client.Get(ctx, newId) if err != nil { if response.WasNotFound(resp.HttpResponse) { diff --git a/internal/services/apimanagement/api_management_api_resource_test.go b/internal/services/apimanagement/api_management_api_resource_test.go index d5be265ac795..b3ebf236be3f 100644 --- a/internal/services/apimanagement/api_management_api_resource_test.go +++ b/internal/services/apimanagement/api_management_api_resource_test.go @@ -681,7 +681,7 @@ resource "azurerm_api_management_api" "test" { revision = "current" import { - content_value = file("testdata/api_management_api_openai.yaml") + content_value = file("testdata/api_management_api_openapi.yaml") content_format = "openapi" } } diff --git a/internal/services/apimanagement/testdata/api_management_api_openai.yaml b/internal/services/apimanagement/testdata/api_management_api_openapi.yaml similarity index 100% rename from internal/services/apimanagement/testdata/api_management_api_openai.yaml rename to internal/services/apimanagement/testdata/api_management_api_openapi.yaml