Skip to content

Commit

Permalink
only setting approval_required / subscriptions_limit if `subscrip…
Browse files Browse the repository at this point in the history
…tion_required` is true
  • Loading branch information
tombuildsstuff committed Feb 26, 2019
1 parent d9b2221 commit 29adcf2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
7 changes: 4 additions & 3 deletions azurerm/resource_arm_api_management_product.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func resourceArmApiManagementProductCreateUpdate(d *schema.ResourceData, meta in

properties := apimanagement.ProductContract{
ProductContractProperties: &apimanagement.ProductContractProperties{
ApprovalRequired: utils.Bool(approvalRequired),
Description: utils.String(description),
DisplayName: utils.String(displayName),
State: publishedVal,
Expand All @@ -112,8 +111,10 @@ func resourceArmApiManagementProductCreateUpdate(d *schema.ResourceData, meta in
},
}

// Can be present only if subscriptionRequired property is present and has a value of false.
if !subscriptionRequired && subscriptionsLimit > 0 {
// Swagger says: Can be present only if subscriptionRequired property is present and has a value of false.
// API/Portal says: Cannot provide values for approvalRequired and subscriptionsLimit when subscriptionRequired is set to false in the request payload
if subscriptionRequired && subscriptionsLimit > 0 {
properties.ProductContractProperties.ApprovalRequired = utils.Bool(approvalRequired)
properties.ProductContractProperties.SubscriptionsLimit = utils.Int32(int32(subscriptionsLimit))
}

Expand Down
13 changes: 7 additions & 6 deletions azurerm/resource_arm_api_management_product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestAccAzureRMApiManagementProduct_update(t *testing.T) {
})
}

func TestAccAzureRMApiManagementProduct_subscriptionlimits(t *testing.T) {
func TestAccAzureRMApiManagementProduct_subscriptionsLimit(t *testing.T) {
resourceName := "azurerm_api_management_product.test"
ri := tf.AccRandTimeInt()
location := testLocation()
Expand All @@ -175,8 +175,9 @@ func TestAccAzureRMApiManagementProduct_subscriptionlimits(t *testing.T) {
Config: testAccAzureRMApiManagementProduct_subscriptionLimits(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMApiManagementProductExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "subscription_required", "false"),
resource.TestCheckResourceAttr(resourceName, "subscription_limits", "2"),
resource.TestCheckResourceAttr(resourceName, "approval_required", "true"),
resource.TestCheckResourceAttr(resourceName, "subscription_required", "true"),
resource.TestCheckResourceAttr(resourceName, "subscriptions_limit", "2"),
),
},
{
Expand Down Expand Up @@ -353,9 +354,9 @@ resource "azurerm_api_management_product" "test" {
api_management_name = "${azurerm_api_management.test.name}"
resource_group_name = "${azurerm_resource_group.test.name}"
display_name = "Test Product"
subscription_required = false
approval_required = false
subscription_limits = 2
subscription_required = true
approval_required = true
subscriptions_limit = 2
published = false
}
`, rInt, location, rInt)
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/api_management_product.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ The following arguments are supported:

* `approval_required` - (Required) Do subscribers need to be approved prior to being able to use the Product?

-> **NOTE:** `approval_required` can only be set when `subscription_required` is set to `true`.

* `display_name` - (Required) The Display Name for this API Management Product.

* `product_id` - (Required) The Identifier for this Product, which must be unique within the API Management Service. Changing this forces a new resource to be created.
Expand All @@ -66,7 +68,7 @@ The following arguments are supported:

* `subscriptions_limit` - (Optional) The number of subscriptions a user can have to this Product at the same time.

-> **NOTE:** `subscriptions_limit` can only be set when `subscription_required` is set to `false`.
-> **NOTE:** `subscriptions_limit` can only be set when `subscription_required` is set to `true`.

* `terms` - (Optional) The Terms and Conditions for this Product, which must be accepted by Developers before they can begin the Subscription process.

Expand Down

0 comments on commit 29adcf2

Please sign in to comment.