-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} |
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) | ||
} |
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" | ||||||
api_management_name = "acctestApiManagement" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
## 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`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
|
||||||
|
||||||
* `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. |
There was a problem hiding this comment.
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