Skip to content

Commit

Permalink
r/api_management_product: making the approval_required field optional
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Feb 26, 2019
1 parent 29adcf2 commit 3bbd539
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
12 changes: 7 additions & 5 deletions azurerm/resource_arm_api_management_product.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand All @@ -29,23 +30,24 @@ func resourceArmApiManagementProduct() *schema.Resource {
"resource_group_name": resourceGroupNameSchema(),

"display_name": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.NoEmptyStrings,
},

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

"approval_required": {
"published": {
Type: schema.TypeBool,
Required: true,
},

"published": {
"approval_required": {
Type: schema.TypeBool,
Required: true,
Optional: true,
},

"description": {
Expand Down
31 changes: 16 additions & 15 deletions azurerm/resource_arm_api_management_product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ func TestAccAzureRMApiManagementProduct_basic(t *testing.T) {
Config: testAccAzureRMApiManagementProduct_basic(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMApiManagementProductExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "approval_required", "true"),
resource.TestCheckResourceAttr(resourceName, "approval_required", "false"),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "display_name", "Test Product"),
resource.TestCheckResourceAttr(resourceName, "product_id", "test-product"),
resource.TestCheckResourceAttr(resourceName, "published", "true"),
resource.TestCheckResourceAttr(resourceName, "subscription_required", "true"),
resource.TestCheckResourceAttr(resourceName, "published", "false"),
resource.TestCheckResourceAttr(resourceName, "subscription_required", "false"),
resource.TestCheckResourceAttr(resourceName, "terms", ""),
),
},
Expand Down Expand Up @@ -112,12 +112,12 @@ func TestAccAzureRMApiManagementProduct_update(t *testing.T) {
Config: testAccAzureRMApiManagementProduct_basic(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMApiManagementProductExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "approval_required", "true"),
resource.TestCheckResourceAttr(resourceName, "approval_required", "false"),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "display_name", "Test Product"),
resource.TestCheckResourceAttr(resourceName, "product_id", "test-product"),
resource.TestCheckResourceAttr(resourceName, "published", "true"),
resource.TestCheckResourceAttr(resourceName, "subscription_required", "true"),
resource.TestCheckResourceAttr(resourceName, "published", "false"),
resource.TestCheckResourceAttr(resourceName, "subscription_required", "false"),
resource.TestCheckResourceAttr(resourceName, "terms", ""),
),
},
Expand All @@ -130,12 +130,12 @@ func TestAccAzureRMApiManagementProduct_update(t *testing.T) {
Config: testAccAzureRMApiManagementProduct_updated(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMApiManagementProductExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "approval_required", "false"),
resource.TestCheckResourceAttr(resourceName, "approval_required", "true"),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "display_name", "Test Updated Product"),
resource.TestCheckResourceAttr(resourceName, "product_id", "test-product"),
resource.TestCheckResourceAttr(resourceName, "published", "false"),
resource.TestCheckResourceAttr(resourceName, "subscription_required", "false"),
resource.TestCheckResourceAttr(resourceName, "published", "true"),
resource.TestCheckResourceAttr(resourceName, "subscription_required", "true"),
resource.TestCheckResourceAttr(resourceName, "terms", ""),
),
},
Expand All @@ -148,12 +148,12 @@ func TestAccAzureRMApiManagementProduct_update(t *testing.T) {
Config: testAccAzureRMApiManagementProduct_basic(ri, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMApiManagementProductExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "approval_required", "true"),
resource.TestCheckResourceAttr(resourceName, "approval_required", "false"),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "display_name", "Test Product"),
resource.TestCheckResourceAttr(resourceName, "product_id", "test-product"),
resource.TestCheckResourceAttr(resourceName, "published", "true"),
resource.TestCheckResourceAttr(resourceName, "subscription_required", "true"),
resource.TestCheckResourceAttr(resourceName, "published", "false"),
resource.TestCheckResourceAttr(resourceName, "subscription_required", "false"),
resource.TestCheckResourceAttr(resourceName, "terms", ""),
),
},
Expand Down Expand Up @@ -208,6 +208,7 @@ func TestAccAzureRMApiManagementProduct_complete(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "display_name", "Test Product"),
resource.TestCheckResourceAttr(resourceName, "product_id", "test-product"),
resource.TestCheckResourceAttr(resourceName, "published", "true"),
resource.TestCheckResourceAttr(resourceName, "subscriptions_limit", "2"),
resource.TestCheckResourceAttr(resourceName, "subscription_required", "true"),
resource.TestCheckResourceAttr(resourceName, "terms", "These are some example terms and conditions"),
),
Expand Down Expand Up @@ -273,9 +274,8 @@ 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 = true
approval_required = true
published = true
subscription_required = false
published = false
}
`, rInt, location, rInt)
}
Expand Down Expand Up @@ -390,6 +390,7 @@ resource "azurerm_api_management_product" "test" {
subscription_required = true
approval_required = true
published = true
subscriptions_limit = 2
description = "This is an example description"
terms = "These are some example terms and conditions"
}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/api_management_product.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ The following arguments are supported:

* `api_management_name` - (Required) The name of the API Management Service. Changing this forces a new resource to be created.

* `approval_required` - (Required) Do subscribers need to be approved prior to being able to use the Product?
* `approval_required` - (Optional) 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`.

Expand Down

0 comments on commit 3bbd539

Please sign in to comment.