Skip to content

Commit

Permalink
azurerm_api_management_api : fix importing openapi format content…
Browse files Browse the repository at this point in the history
… file issue (#23348)
  • Loading branch information
sinbai authored Sep 25, 2023
1 parent 9b327e4 commit 4b018f8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4b018f8

Please sign in to comment.