diff --git a/azurerm/internal/services/network/registration.go b/azurerm/internal/services/network/registration.go index f08e1f86e97c..00eb8ab1f791 100644 --- a/azurerm/internal/services/network/registration.go +++ b/azurerm/internal/services/network/registration.go @@ -50,6 +50,7 @@ func (r Registration) SupportedDataSources() map[string]*schema.Resource { "azurerm_virtual_network_gateway_connection": dataSourceArmVirtualNetworkGatewayConnection(), "azurerm_virtual_network": dataSourceArmVirtualNetwork(), "azurerm_web_application_firewall_policy": dataArmWebApplicationFirewallPolicy(), + "azurerm_virtual_wan": dataSourceArmVirtualWan(), } } diff --git a/azurerm/internal/services/network/tests/virtual_wan_data_source_test.go b/azurerm/internal/services/network/tests/virtual_wan_data_source_test.go new file mode 100644 index 000000000000..855888746a97 --- /dev/null +++ b/azurerm/internal/services/network/tests/virtual_wan_data_source_test.go @@ -0,0 +1,57 @@ +package tests + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" +) + +func TestAccDataSourceVirtualWan_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "data.azurerm_virtual_wan", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + Steps: []resource.TestStep{ + { + Config: testAccDataSourceVirtualWan_basic(data), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(data.ResourceName, "name"), + resource.TestCheckResourceAttrSet(data.ResourceName, "resource_group_name"), + ), + }, + }, + }) +} + +func testAccDataSourceVirtualWan_basic(data acceptance.TestData) string { + template := testAccDataSourceVirtualWan_template(data) + return fmt.Sprintf(` +%s +resource "azurerm_virtual_wan" "test" { + name = "test" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location +} + +data "azurerm_virtual_wan" "test" { + name = azurerm_virtual_wan.test.name + resource_group_name = azurerm_virtual_wan.test.resource_group_name +} + `, template) +} + +func testAccDataSourceVirtualWan_template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} +`, data.RandomInteger, data.Locations.Primary) +} diff --git a/azurerm/internal/services/network/virtual_wan_data_source.go b/azurerm/internal/services/network/virtual_wan_data_source.go new file mode 100644 index 000000000000..f835679ff660 --- /dev/null +++ b/azurerm/internal/services/network/virtual_wan_data_source.go @@ -0,0 +1,130 @@ +package network + +import ( + "fmt" + "time" + + "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2020-05-01/network" + + "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 dataSourceArmVirtualWan() *schema.Resource { + return &schema.Resource{ + Read: dataSourceArmVirtualWanRead, + Timeouts: &schema.ResourceTimeout{ + Read: schema.DefaultTimeout(5 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), + + "allow_branch_to_branch_traffic": { + Type: schema.TypeBool, + Computed: true, + }, + "disable_vpn_encryption": { + Type: schema.TypeBool, + Computed: true, + }, + "office365_local_breakout_category": { + Type: schema.TypeString, + Computed: true, + }, + "sku": { + Type: schema.TypeString, + Computed: true, + }, + "virtual_hub_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "vpn_site_ids": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "location": azure.SchemaLocationForDataSource(), + + "tags": tags.SchemaDataSource(), + }, + } +} + +func dataSourceArmVirtualWanRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Network.VirtualWanClient + 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: Virtual Wan %q (Resource Group %q) was not found", name, resourceGroup) + } + return fmt.Errorf("Error reading Virtual Wan %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + if resp.ID == nil || *resp.ID == "" { + return fmt.Errorf("API returns a nil/empty id on Virtual Wan %q (resource group %q): %+v", name, resourceGroup, 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)) + } + + if props := resp.VirtualWanProperties; props != nil { + d.Set("allow_branch_to_branch_traffic", props.AllowBranchToBranchTraffic) + d.Set("disable_vpn_encryption", props.DisableVpnEncryption) + if err := d.Set("office365_local_breakout_category", props.Office365LocalBreakoutCategory); err != nil { + return fmt.Errorf("error setting `office365_local_breakout_category`: %v", err) + } + d.Set("office365_local_breakout_category", props.Office365LocalBreakoutCategory) + if err := d.Set("sku", props.Type); err != nil { + return fmt.Errorf("error setting `sku`: %v", err) + } + d.Set("sku", props.Type) + if err := d.Set("virtual_hub_ids", flattenVirtualWanProperties(props.VirtualHubs)); err != nil { + return fmt.Errorf("error setting `virtual_hubs`: %v", err) + } + if err := d.Set("vpn_site_ids", flattenVirtualWanProperties(props.VpnSites)); err != nil { + return fmt.Errorf("error setting `vpn_sites`: %v", err) + } + } + + return tags.FlattenAndSet(d, resp.Tags) +} + +func flattenVirtualWanProperties(input *[]network.SubResource) []interface{} { + if input == nil { + return []interface{}{} + } + output := make([]interface{}, 0) + for _, v := range *input { + if v.ID != nil { + output = append(output, *v.ID) + } + } + return output +} diff --git a/website/docs/d/images.html.markdown b/website/docs/d/images.html.markdown index d3db934c3800..46d20983e50b 100644 --- a/website/docs/d/images.html.markdown +++ b/website/docs/d/images.html.markdown @@ -1,86 +1,86 @@ ---- -subcategory: "Compute" -layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_images" -description: |- - Gets information about existing Images within a Resource Group. - ---- - -# Data Source: azurerm_images - -Use this data source to access information about existing Images within a Resource Group. - -## Example Usage - -```hcl -data "azurerm_images" "example" { - resource_group_name = "example-resources" -} -``` - -## Argument Reference - -The following arguments are supported: - -* `resource_group_name` - The name of the Resource Group in which the Image exists. - -* `tags_filter` - A mapping of tags to filter the list of images against. - -## Attributes Reference - -The following attributes are exported: - -* `images` - One or more `images` blocks as defined below: - ---- - -A `images` block exports the following: - -* `name` - The name of the Image. - -* `location` - The supported Azure location where the Image exists. - -* `zone_resilient` - Is zone resiliency enabled? - -* `os_disk` - An `os_disk` block as defined below. - -* `data_disk` - One or more `data_disk` blocks as defined below. - -* `tags` - A mapping of tags assigned to the Image. - ---- - -The `os_disk` block exports the following: - -* `blob_uri` - the URI in Azure storage of the blob used to create the image. - -* `caching` - the caching mode for the OS Disk. - -* `managed_disk_id` - the ID of the Managed Disk used as the OS Disk Image. - -* `os_state` - the State of the OS used in the Image. - -* `os_type` - the type of Operating System used on the OS Disk. - -* `size_gb` - the size of the OS Disk in GB. - ---- - -The `data_disk` block exports the following: - -* `blob_uri` - the URI in Azure storage of the blob used to create the image. - -* `caching` - the caching mode for the Data Disk. - -* `lun` - the logical unit number of the data disk. - -* `managed_disk_id` - the ID of the Managed Disk used as the Data Disk Image. - -* `size_gb` - the size of this Data Disk in GB. - -## 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 Images within a Resource Group. +--- +subcategory: "Compute" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_images" +description: |- + Gets information about existing Images within a Resource Group. + +--- + +# Data Source: azurerm_images + +Use this data source to access information about existing Images within a Resource Group. + +## Example Usage + +```hcl +data "azurerm_images" "example" { + resource_group_name = "example-resources" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `resource_group_name` - The name of the Resource Group in which the Image exists. + +* `tags_filter` - A mapping of tags to filter the list of images against. + +## Attributes Reference + +The following attributes are exported: + +* `images` - One or more `images` blocks as defined below: + +--- + +A `images` block exports the following: + +* `name` - The name of the Image. + +* `location` - The supported Azure location where the Image exists. + +* `zone_resilient` - Is zone resiliency enabled? + +* `os_disk` - An `os_disk` block as defined below. + +* `data_disk` - One or more `data_disk` blocks as defined below. + +* `tags` - A mapping of tags assigned to the Image. + +--- + +The `os_disk` block exports the following: + +* `blob_uri` - the URI in Azure storage of the blob used to create the image. + +* `caching` - the caching mode for the OS Disk. + +* `managed_disk_id` - the ID of the Managed Disk used as the OS Disk Image. + +* `os_state` - the State of the OS used in the Image. + +* `os_type` - the type of Operating System used on the OS Disk. + +* `size_gb` - the size of the OS Disk in GB. + +--- + +The `data_disk` block exports the following: + +* `blob_uri` - the URI in Azure storage of the blob used to create the image. + +* `caching` - the caching mode for the Data Disk. + +* `lun` - the logical unit number of the data disk. + +* `managed_disk_id` - the ID of the Managed Disk used as the Data Disk Image. + +* `size_gb` - the size of this Data Disk in GB. + +## 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 Images within a Resource Group. diff --git a/website/docs/d/virtual_wan.html.markdown b/website/docs/d/virtual_wan.html.markdown new file mode 100644 index 000000000000..b8bfeafce984 --- /dev/null +++ b/website/docs/d/virtual_wan.html.markdown @@ -0,0 +1,93 @@ +--- +subcategory: "Network" +layout: "azurerm" +page_title: "Azure Resource Manager: Data Source: azurerm_virtual_wan" +description: |- + Gets information about an existing Virtual Wan. +--- + +# Data Source: azurerm_virtual_wan + +Use this data source to access information about an existing Virtual Wan. + +## Example Usage + +```hcl +data "azurerm_virtual_wan" "example" { + name = "existing" + resource_group_name = "existing" +} + +output "id" { + value = data.azurerm_virtual_wan.example.id +} + +output "allow_branch_to_branch_traffic" { + value = data.azurerm_virtual_wan.example.allow_branch_to_branch_traffic +} + +output "disable_vpn_encryption" { + value = data.azurerm_virtual_wan.exemple.disable_vpn_encryption +} + +output "location" { + value = data.azurerm_virtual_wan.exemple.location +} + +output "office365_local_breakout_category" { + value = data.azurerm_virtual_wan.exemple.office365_local_breakout_category +} + +output "sku" { + value = data.azurerm_virtual_wan.exemple.sku +} + +output "tags" { + value = data.azurerm_virtual_wan.exemple.tags +} + +output "virtual_hubs" { + value = data.azurerm_virtual_wan.exemple.virtual_hubs +} + +output "vpn_sites" { + value = data.azurerm_virtual_wan.exemple.vpn_sites +} + +``` + +## Arguments Reference + +The following arguments are supported: + +- `name` - (Required) The name of this Virtual Wan. + +- `resource_group_name` - (Required) The name of the Resource Group where the Virtual Wan exists. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +- `id` - The ID of the Virtual Wan. + +- `allow_branch_to_branch_traffic` - Is branch to branch traffic is allowed? + +- `disable_vpn_encryption` - Is VPN Encryption disabled? + +- `location` - The Azure Region where the Virtual Wan exists. + +- `office365_local_breakout_category` - The Office365 Local Breakout Category. + +- `sku` - Type of Virtual Wan (Basic or Standard). + +- `tags` - A mapping of tags assigned to the Virtual Wan. + +- `virtual_hub_ids` - A list of Virtual Hubs ID's attached to this Virtual WAN. + +- `vpn_site_ids` - A list of VPN Site ID's attached to this Virtual WAN. + +## 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 Virtual Wan. diff --git a/website/docs/r/security_center_auto_provisioning.html.markdown b/website/docs/r/security_center_auto_provisioning.html.markdown index d35ac3cafb48..e2d584ea518d 100644 --- a/website/docs/r/security_center_auto_provisioning.html.markdown +++ b/website/docs/r/security_center_auto_provisioning.html.markdown @@ -47,4 +47,4 @@ Security Center Auto Provisioning can be imported using the `resource id`, e.g. ```shell terraform import azurerm_security_center_auto_provisioning.example /subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Security/autoProvisioningSettings/default -``` \ No newline at end of file +```