-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_source_dns_zone.go
82 lines (65 loc) · 1.86 KB
/
data_source_dns_zone.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
70
71
72
73
74
75
76
77
78
79
80
81
82
package azurerm
import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)
func dataSourceArmDnsZone() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmDnsZoneRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"resource_group_name": resourceGroupNameForDataSourceSchema(),
"number_of_record_sets": {
Type: schema.TypeString,
Computed: true,
},
"max_number_of_record_sets": {
Type: schema.TypeString,
Computed: true,
},
"name_servers": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"tags": tagsForDataSourceSchema(),
},
}
}
func dataSourceArmDnsZoneRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).zonesClient
ctx := meta.(*ArmClient).StopContext
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) {
d.SetId("")
return nil
}
return fmt.Errorf("Error reading DNS Zone %q (Resource Group %q): %+v", name, resourceGroup, err)
}
d.SetId(*resp.ID)
d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
if props := resp.ZoneProperties; props != nil {
d.Set("number_of_record_sets", props.NumberOfRecordSets)
d.Set("max_number_of_record_sets", props.MaxNumberOfRecordSets)
if ns := props.NameServers; ns != nil {
nameServers := make([]string, 0, len(*ns))
for _, ns := range *ns {
nameServers = append(nameServers, ns)
}
if err := d.Set("name_servers", nameServers); err != nil {
return err
}
}
}
flattenAndSetTags(d, resp.Tags)
return nil
}