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

Added data source for WAF policy (fixes #7468) #7469

Merged
merged 12 commits into from
Jul 7, 2020
1 change: 1 addition & 0 deletions azurerm/internal/services/network/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource {
"azurerm_virtual_network_gateway": dataSourceArmVirtualNetworkGateway(),
"azurerm_virtual_network_gateway_connection": dataSourceArmVirtualNetworkGatewayConnection(),
"azurerm_virtual_network": dataSourceArmVirtualNetwork(),
"azurerm_web_application_firewall_policy": dataArmWebApplicationFirewallPolicy(),
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package network

import (
"fmt"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataArmWebApplicationFirewallPolicy() *schema.Resource {
rikribbers marked this conversation as resolved.
Show resolved Hide resolved
return &schema.Resource{
Read: dataSourceArmWebApplicationFirewallPolicy,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

rikribbers marked this conversation as resolved.
Show resolved Hide resolved
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"tags": tags.Schema(),
},
}
}

func dataSourceArmWebApplicationFirewallPolicy(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Network.WebApplicationFirewallPoliciesClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Web Application Firewall Policy %q was not found", name)
}
return err
}

d.SetId(*resp.ID)

d.Set("name", resp.Name)
d.Set("resource_group_name", resourceGroup)
if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}

return tags.FlattenAndSet(d, resp.Tags)
}
3 changes: 3 additions & 0 deletions website/azurerm.erb
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,9 @@
<li>
<a href="/docs/providers/azurerm/d/virtual_network_gateway_connection.html">azurerm_virtual_network_gateway_connection</a>
</li>
<li>
<a href="/docs/providers/azurerm/d/web_application_firewall_policy.html">azurerm_web_application_firewall_policy</a>
</li>
</ul>
</li>

Expand Down
44 changes: 44 additions & 0 deletions website/docs/d/web_application_firewall_policy.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
subcategory: "Network"
layout: "azurerm"
page_title: "Azure Resource Manager: Data Source: azurerm_web_application_firewall_policy"
description: |-
Gets information about an existing Web Application Firewall Policy.
---

# Data Source: azurerm_web_application_firewall_policy

Use this data source to access information about an existing Web Application Firewall Policy.

## Example Usage

```hcl
data "azurerm_web_application_firewall_policy" "example" {
resource_group_name = "existing"
policy_name = "existing"
}

output "id" {
value = data.azurerm_web_application_firewall_policy.example.id
}
```

## Arguments Reference

The following arguments are supported:

* `name` - (Required) The name of the Web Application Firewall Policy

* `resource_group_name` - (Required) The name of the Resource Group where the Web Application Firewall Policy exists.

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

* `id` - The ID of the Web Application Firewall Policy.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:

* `read` - (Defaults to 5 minutes) Used when retrieving the Web Application Firewall Policy.