From 3bbd539d62f80b5a7a366860863c995adc0f2d5d Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Fri, 8 Feb 2019 17:50:01 +0000 Subject: [PATCH] r/api_management_product: making the `approval_required` field optional --- .../resource_arm_api_management_product.go | 12 ++++--- ...esource_arm_api_management_product_test.go | 31 ++++++++++--------- .../r/api_management_product.html.markdown | 2 +- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/azurerm/resource_arm_api_management_product.go b/azurerm/resource_arm_api_management_product.go index 50509ecf9957..3770b0600be6 100644 --- a/azurerm/resource_arm_api_management_product.go +++ b/azurerm/resource_arm_api_management_product.go @@ -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" ) @@ -29,8 +30,9 @@ 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": { @@ -38,14 +40,14 @@ func resourceArmApiManagementProduct() *schema.Resource { Required: true, }, - "approval_required": { + "published": { Type: schema.TypeBool, Required: true, }, - "published": { + "approval_required": { Type: schema.TypeBool, - Required: true, + Optional: true, }, "description": { diff --git a/azurerm/resource_arm_api_management_product_test.go b/azurerm/resource_arm_api_management_product_test.go index 53c8051f852a..11d19e22fb25 100644 --- a/azurerm/resource_arm_api_management_product_test.go +++ b/azurerm/resource_arm_api_management_product_test.go @@ -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", ""), ), }, @@ -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", ""), ), }, @@ -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", ""), ), }, @@ -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", ""), ), }, @@ -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"), ), @@ -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) } @@ -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" } diff --git a/website/docs/r/api_management_product.html.markdown b/website/docs/r/api_management_product.html.markdown index e476a1a4bb09..ca0b6aca4771 100644 --- a/website/docs/r/api_management_product.html.markdown +++ b/website/docs/r/api_management_product.html.markdown @@ -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`.