-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
data_source_network_ddos_protection_plan.go
69 lines (54 loc) · 2.01 KB
/
data_source_network_ddos_protection_plan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package azurerm
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
func dataSourceNetworkDDoSProtectionPlan() *schema.Resource {
return &schema.Resource{
Read: dataSourceNetworkDDoSProtectionPlanRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"location": azure.SchemaLocationForDataSource(),
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),
"virtual_network_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"tags": tags.Schema(),
},
}
}
func dataSourceNetworkDDoSProtectionPlanRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).network.DDOSProtectionPlansClient
ctx := meta.(*ArmClient).StopContext
name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
plan, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(plan.Response) {
return fmt.Errorf("Error DDoS Protection Plan %q (Resource Group %q) was not found", name, resourceGroup)
}
return fmt.Errorf("Error making Read request on DDoS Protection Plan %q (Resource Group %q): %+v", name, resourceGroup, err)
}
d.Set("name", plan.Name)
d.Set("resource_group_name", resourceGroup)
if location := plan.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}
if props := plan.DdosProtectionPlanPropertiesFormat; props != nil {
vNetIDs := flattenArmNetworkDDoSProtectionPlanVirtualNetworkIDs(props.VirtualNetworks)
if err := d.Set("virtual_network_ids", vNetIDs); err != nil {
return fmt.Errorf("Error setting `virtual_network_ids`: %+v", err)
}
}
return tags.FlattenAndSet(d, plan.Tags)
}