Skip to content

Commit

Permalink
azurerm_api_management_subscription - Support `allow_tracing proper…
Browse files Browse the repository at this point in the history
…ty` (#7969)
  • Loading branch information
BlakeDickie authored Aug 28, 2020
1 parent 4262285 commit d813adc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func resourceArmApiManagementSubscription() *schema.Resource {
Computed: true,
Sensitive: true,
},

"allow_tracing": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
},
}
}
Expand Down Expand Up @@ -123,13 +129,15 @@ func resourceArmApiManagementSubscriptionCreateUpdate(d *schema.ResourceData, me
productId := d.Get("product_id").(string)
state := d.Get("state").(string)
userId := d.Get("user_id").(string)
allowTracing := d.Get("allow_tracing").(bool)

params := apimanagement.SubscriptionCreateParameters{
SubscriptionCreateParameterProperties: &apimanagement.SubscriptionCreateParameterProperties{
DisplayName: utils.String(displayName),
Scope: utils.String(productId),
State: apimanagement.SubscriptionState(state),
OwnerID: utils.String(userId),
DisplayName: utils.String(displayName),
Scope: utils.String(productId),
State: apimanagement.SubscriptionState(state),
OwnerID: utils.String(userId),
AllowTracing: utils.Bool(allowTracing),
},
}

Expand Down Expand Up @@ -190,6 +198,7 @@ func resourceArmApiManagementSubscriptionRead(d *schema.ResourceData, meta inter
d.Set("state", string(props.State))
d.Set("product_id", props.Scope)
d.Set("user_id", props.OwnerID)
d.Set("allow_tracing", props.AllowTracing)
}

// Primary and secondary keys must be got from this additional api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestAccAzureRMAPIManagementSubscription_basic(t *testing.T) {
Config: testAccAzureRMAPIManagementSubscription_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "allow_tracing", "true"),
resource.TestCheckResourceAttrSet(data.ResourceName, "subscription_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"),
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"),
Expand Down Expand Up @@ -64,36 +65,44 @@ func TestAccAzureRMAPIManagementSubscription_update(t *testing.T) {
CheckDestroy: testCheckAzureRMAPIManagementSubscriptionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMAPIManagementSubscription_update(data, "submitted"),
Config: testAccAzureRMAPIManagementSubscription_update(data, "submitted", "true"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "state", "submitted"),
resource.TestCheckResourceAttr(data.ResourceName, "allow_tracing", "true"),
resource.TestCheckResourceAttrSet(data.ResourceName, "subscription_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"),
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"),
),
},
{
Config: testAccAzureRMAPIManagementSubscription_update(data, "active"),
Config: testAccAzureRMAPIManagementSubscription_update(data, "active", "true"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "state", "active"),
),
},
{
Config: testAccAzureRMAPIManagementSubscription_update(data, "suspended"),
Config: testAccAzureRMAPIManagementSubscription_update(data, "suspended", "true"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "state", "suspended"),
),
},
{
Config: testAccAzureRMAPIManagementSubscription_update(data, "cancelled"),
Config: testAccAzureRMAPIManagementSubscription_update(data, "cancelled", "true"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "state", "cancelled"),
),
},
{
Config: testAccAzureRMAPIManagementSubscription_update(data, "active", "false"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "allow_tracing", "false"),
),
},
},
})
}
Expand All @@ -111,6 +120,7 @@ func TestAccAzureRMAPIManagementSubscription_complete(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAPIManagementSubscriptionExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "state", "active"),
resource.TestCheckResourceAttr(data.ResourceName, "allow_tracing", "false"),
resource.TestCheckResourceAttrSet(data.ResourceName, "subscription_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "primary_key"),
resource.TestCheckResourceAttrSet(data.ResourceName, "secondary_key"),
Expand Down Expand Up @@ -202,7 +212,7 @@ resource "azurerm_api_management_subscription" "import" {
`, template)
}

func testAccAzureRMAPIManagementSubscription_update(data acceptance.TestData, state string) string {
func testAccAzureRMAPIManagementSubscription_update(data acceptance.TestData, state string, allow_tracing string) string {
template := testAccAzureRMAPIManagementSubscription_template(data)
return fmt.Sprintf(`
%s
Expand All @@ -214,8 +224,9 @@ resource "azurerm_api_management_subscription" "test" {
product_id = azurerm_api_management_product.test.id
display_name = "Butter Parser API Enterprise Edition"
state = "%s"
allow_tracing = "%s"
}
`, template, state)
`, template, state, allow_tracing)
}

func testAccAzureRMAPIManagementSubscription_complete(data acceptance.TestData) string {
Expand All @@ -230,6 +241,7 @@ resource "azurerm_api_management_subscription" "test" {
product_id = azurerm_api_management_product.test.id
display_name = "Butter Parser API Enterprise Edition"
state = "active"
allow_tracing = "false"
}
`, template)
}
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/api_management_subscription.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ The following arguments are supported:

* `subscription_id` - (Optional) An Identifier which should used as the ID of this Subscription. If not specified a new Subscription ID will be generated. Changing this forces a new resource to be created.

* `allow_tracing` - (Optional) Determines whether tracing can be enabled. Defaults to `true`.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:
Expand Down

0 comments on commit d813adc

Please sign in to comment.