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 - support for subscription_required #4885

Merged
merged 6 commits into from Jun 24, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -99,6 +99,11 @@ func dataSourceApiManagementApi() *schema.Resource {
},
},

"subscription_required": {
Type: schema.TypeBool,
Computed: true,
},

"version": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -147,6 +152,7 @@ func dataSourceApiManagementApiRead(d *schema.ResourceData, meta interface{}) er
d.Set("revision", props.APIRevision)
d.Set("service_url", props.ServiceURL)
d.Set("soap_pass_through", string(props.APIType) == string(apimanagement.SoapPassThrough))
d.Set("subscription_required", props.SubscriptionRequired)
d.Set("version", props.APIVersion)
d.Set("version_set_id", props.APIVersionSetID)

Expand Down
Expand Up @@ -163,6 +163,12 @@ func resourceArmApiManagementApi() *schema.Resource {
},
},

"subscription_required": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},

"soap_pass_through": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -292,6 +298,7 @@ func resourceArmApiManagementApiCreateUpdate(d *schema.ResourceData, meta interf
description := d.Get("description").(string)
displayName := d.Get("display_name").(string)
serviceUrl := d.Get("service_url").(string)
subscriptionRequired := d.Get("subscription_required").(bool)

protocolsRaw := d.Get("protocols").(*schema.Set).List()
protocols := expandApiManagementApiProtocols(protocolsRaw)
Expand All @@ -310,6 +317,7 @@ func resourceArmApiManagementApiCreateUpdate(d *schema.ResourceData, meta interf
ServiceURL: utils.String(serviceUrl),
SubscriptionKeyParameterNames: subscriptionKeyParameterNames,
APIVersion: utils.String(version),
SubscriptionRequired: &subscriptionRequired,
},
}

Expand Down Expand Up @@ -384,6 +392,7 @@ func resourceArmApiManagementApiRead(d *schema.ResourceData, meta interface{}) e
d.Set("service_url", props.ServiceURL)
d.Set("revision", props.APIRevision)
d.Set("soap_pass_through", string(props.APIType) == string(apimanagement.SoapPassThrough))
d.Set("subscription_required", props.SubscriptionRequired)
d.Set("version", props.APIVersion)
d.Set("version_set_id", props.APIVersionSetID)

Expand Down
Expand Up @@ -23,6 +23,7 @@ func TestAccDataSourceAzureRMApiManagementApi_basic(t *testing.T) {
resource.TestCheckResourceAttr(data.ResourceName, "protocols.#", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "protocols.0", "https"),
resource.TestCheckResourceAttr(data.ResourceName, "soap_pass_through", "false"),
resource.TestCheckResourceAttr(data.ResourceName, "subscription_required", "false"),
resource.TestCheckResourceAttr(data.ResourceName, "is_current", "true"),
resource.TestCheckResourceAttr(data.ResourceName, "is_online", "false"),
),
Expand Down
Expand Up @@ -26,6 +26,7 @@ func TestAccAzureRMApiManagementApi_basic(t *testing.T) {
resource.TestCheckResourceAttr(data.ResourceName, "soap_pass_through", "false"),
resource.TestCheckResourceAttr(data.ResourceName, "is_current", "true"),
resource.TestCheckResourceAttr(data.ResourceName, "is_online", "false"),
resource.TestCheckResourceAttr(data.ResourceName, "subscription_required", "false"),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -157,6 +158,26 @@ func TestAccAzureRMApiManagementApi_soapPassthrough(t *testing.T) {
})
}

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

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMApiManagementApiDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMApiManagementApi_subscriptionRequired(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMApiManagementApiExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "subscription_required", "false"),
),
},
data.ImportStep(),
},
})
}

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

Expand Down Expand Up @@ -419,6 +440,24 @@ resource "azurerm_api_management_api" "test" {
`, template, data.RandomInteger)
}

func testAccAzureRMApiManagementApi_subscriptionRequired(data acceptance.TestData) string {
template := testAccAzureRMApiManagementApi_template(data)
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 = "1"
subscription_required = false
}
`, template, data.RandomInteger)
}

func testAccAzureRMApiManagementApi_requiresImport(data acceptance.TestData) string {
template := testAccAzureRMApiManagementApi_basic(data)
return fmt.Sprintf(`
Expand Down
2 changes: 2 additions & 0 deletions website/docs/d/api_management_api.html.markdown
Expand Up @@ -57,6 +57,8 @@ output "api_management_api_id" {

* `subscription_key_parameter_names` - A `subscription_key_parameter_names` block as documented below.

* `subscription_required` - Should this API require a subscription key?

* `version` - The Version number of this API, if this API is versioned.

* `version_set_id` - The ID of the Version Set which this API is associated with.
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/api_management_api.html.markdown
Expand Up @@ -74,6 +74,8 @@ The following arguments are supported:

* `subscription_key_parameter_names` - (Optional) A `subscription_key_parameter_names` block as documented below.

* `subscription_required` - (Optional) Should this API require a subscription key?

* `version` - (Optional) The Version number of this API, if this API is versioned.

* `version_set_id` - (Optional) The ID of the Version Set which this API is associated with.
Expand Down