Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_api_management_api : fix importing openapi format content file issue #23348

Merged
merged 3 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading