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

Add data source for azurerm_api_management_api_version_set #5470

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -0,0 +1,93 @@
package apimanagement

import (
"fmt"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceApiManagementApiVersionSet() *schema.Resource {
return &schema.Resource{
Read: dataSourceApiManagementApiVersionSetRead,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": azure.SchemaApiManagementChildDataSourceName(),

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"api_management_name": azure.SchemaApiManagementDataSourceName(),

"description": {
Type: schema.TypeString,
Computed: true,
},

"display_name": {
Type: schema.TypeString,
Computed: true,
},

"versioning_scheme": {
Type: schema.TypeString,
Computed: true,
},

"version_header_name": {
Type: schema.TypeString,
Computed: true,
},

"version_query_name": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceApiManagementApiVersionSetRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).ApiManagement.ApiVersionSetClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
serviceName := d.Get("api_management_name").(string)

resp, err := client.Get(ctx, resourceGroup, serviceName, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: API Version Set %q (API Management Service %q / Resource Group %q) does not exist!", name, serviceName, resourceGroup)
}

return fmt.Errorf("Error reading API Version Set %q (API Management Service %q / Resource Group %q): %+v", name, serviceName, resourceGroup, err)
}

if resp.ID == nil || *resp.ID == "" {
return fmt.Errorf("Error retrieving API Version Set %q (API Management Service %q /Resource Group %q): ID was nil or empty", name, serviceName, resourceGroup)
}

d.SetId(*resp.ID)

d.Set("name", resp.Name)
d.Set("resource_group_name", resourceGroup)
d.Set("api_management_name", serviceName)
if props := resp.APIVersionSetContractProperties; props != nil {
d.Set("description", props.Description)
d.Set("display_name", props.DisplayName)
d.Set("versioning_scheme", string(props.VersioningScheme))
d.Set("version_header_name", props.VersionHeaderName)
d.Set("version_query_name", props.VersionQueryName)
}

return nil
}
11 changes: 6 additions & 5 deletions azurerm/internal/services/apimanagement/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ func (r Registration) Name() string {
// SupportedDataSources returns the supported Data Sources supported by this Service
func (r Registration) SupportedDataSources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_api_management": dataSourceApiManagementService(),
"azurerm_api_management_api": dataSourceApiManagementApi(),
"azurerm_api_management_group": dataSourceApiManagementGroup(),
"azurerm_api_management_product": dataSourceApiManagementProduct(),
"azurerm_api_management_user": dataSourceArmApiManagementUser(),
"azurerm_api_management": dataSourceApiManagementService(),
"azurerm_api_management_api": dataSourceApiManagementApi(),
"azurerm_api_management_api_version_set": dataSourceApiManagementApiVersionSet(),
"azurerm_api_management_group": dataSourceApiManagementGroup(),
"azurerm_api_management_product": dataSourceApiManagementProduct(),
"azurerm_api_management_user": dataSourceArmApiManagementUser(),
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package tests

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
)

func TestAccDataSourceAzureRMApiManagementApiVersionSet_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_api_management_api_version_set", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceApiManagementApiVersionSet_basic(data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(data.ResourceName, "name"),
resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"),
resource.TestCheckResourceAttrSet(data.ResourceName, "api_management_name"),
),
},
},
})
}

func testAccDataSourceApiManagementApiVersionSet_basic(data acceptance.TestData) string {
config := testAccAzureRMApiManagementApiVersionSet_basic(data)
return fmt.Sprintf(`
%s

data "azurerm_api_management_api_version_set" "test" {
name = "${azurerm_api_management_api_version_set.test.name}"
resource_group_name = "${azurerm_api_management_api_version_set.test.resource_group_name}"
api_management_name = "${azurerm_api_management_api_version_set.test.api_management_name}"
}
`, config)
}
4 changes: 4 additions & 0 deletions website/azurerm.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<a href="/docs/providers/azurerm/d/api_management_api.html">azurerm_api_management_api</a>
</li>

<li>
<a href="/docs/providers/azurerm/d/api_management_api_version_set.html">azurerm_api_management_api_version_set</a>
</li>

<li>
<a href="/docs/providers/azurerm/d/api_management_group.html">azurerm_api_management_group</a>
</li>
Expand Down
47 changes: 47 additions & 0 deletions website/docs/d/api_management_api_version_set.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
subcategory: "API Management"
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_api_management_api_version_set"
description: |-
Gets information about an API Version Set within an existing API Management Service.
---

# Data Source: azurerm_api_management_api_version_set

Uses this data source to access information about an API Version Set within an API Management Service.

## Example Usage

```hcl
data "azurerm_api_management_api_version_set" "example" {
resource_group_name = "acctestRG"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use example names here

Suggested change
resource_group_name = "acctestRG"
resource_group_name = "example-resources"

api_management_name = "acctestApiManagement"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
api_management_name = "acctestApiManagement"
api_management_name = "example-api-management"

name = "example-api-version-set"
}

output "api_management_api_version_set_id" {
value = "${data.azurerm_api_management_api_version_set.example.id}"
}
```

## Argument Reference

* `name` - (Required) The name of the API Version Set.

* `resource_group_name` - (Required) The name of the Resource Group in which the parent API Management Service exists.

* `api_management_name` - (Required) The name of the [API Management Service](api_management.html) in which the API Version Set should exist.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* `api_management_name` - (Required) The name of the [API Management Service](api_management.html) in which the API Version Set should exist.
* `api_management_name` - (Required) The name of the [API Management Service](api_management.html) in which the API Version exists.


## Attributes Reference

* `id` - The ID of the API Version Set.

* `description` - The description of API Version Set.

* `display_name` - The display name of this API Version Set.

* `versioning_schema` - The value that determines where the API Version identifer will be located in a HTTP request. Possible values are `Header`, `Query` and `Segment`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to state the possible values for data sources

Suggested change
* `versioning_schema` - The value that determines where the API Version identifer will be located in a HTTP request. Possible values are `Header`, `Query` and `Segment`.
* `versioning_schema` - The value that determines where the API Version identifier will be located in a HTTP request.


* `version_header_name` - The name of the Header which should be read from Inbound Requests which defines the API Version.

* `version_query_name` - The name of the Query String which should be read from Inbound Requests which defines the API Version.