-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdata_source_transip_domain.go
117 lines (108 loc) · 3.32 KB
/
data_source_transip_domain.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/transip/gotransip/v6/domain"
"github.com/transip/gotransip/v6/repository"
)
func dataSourceDomain() *schema.Resource {
return &schema.Resource{
Read: dataSourceDomainRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Description: "The name, including the tld of this domain.",
Required: true,
},
"nameservers": {
Type: schema.TypeList,
Description: "List of nameservers associated with domain.",
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeMap,
},
},
"tags": {
Type: schema.TypeList,
Description: "The custom tags added to this domain.",
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"authcode": {
Type: schema.TypeString,
Description: "The authcode for this domain as generated by the registry.",
Computed: true,
},
"cancellation_date": {
Type: schema.TypeString,
Description: "Cancellation data, in YYYY-mm-dd h:i:s format, null if the domain is active.",
Computed: true,
},
"cancellation_status": {
Type: schema.TypeString,
Description: "Cancellation status, null if the domain is active, 'cancelled' when the domain is cancelled.",
Computed: true,
},
"is_dns_only": {
Type: schema.TypeBool,
Description: "Whether this domain is DNS only.",
Computed: true,
},
"is_transfer_locked": {
Type: schema.TypeBool,
Description: "If this domain supports transfer locking, this flag is true when the domains ability to transfer is locked at the registry.",
Computed: true,
},
"is_whitelabel": {
Type: schema.TypeBool,
Description: "If this domain is added to your whitelabel.",
Computed: true,
},
"registration_date": {
Type: schema.TypeString,
Description: "Registration date of the domain, in YYYY-mm-dd format.",
Computed: true,
},
"renewal_date": {
Type: schema.TypeString,
Description: "Next renewal date of the domain, in YYYY-mm-dd format.",
Computed: true,
},
},
}
}
func dataSourceDomainRead(d *schema.ResourceData, m interface{}) error {
name := d.Get("name").(string)
client := m.(repository.Client)
repository := domain.Repository{Client: client}
i, err := repository.GetByDomainName(name)
if err != nil {
return fmt.Errorf("failed to lookup domain %q: %s", name, err)
}
var nameservers []map[string]string
ns, err := repository.GetNameservers(name)
if err != nil {
return fmt.Errorf("failed to lookup nameservers for domain %q: %s", name, err)
}
for _, n := range ns {
nameservers = append(nameservers, map[string]string{
"hostname": n.Hostname,
"ipv4_address": n.IPv4.String(),
"ipv6_address": n.IPv6.String(),
})
}
d.SetId(i.Name)
d.Set("nameservers", nameservers)
d.Set("tags", i.Tags)
d.Set("authcode", i.AuthCode)
d.Set("cancellation_date", i.CancellationDate)
d.Set("cancellation_status", i.CancellationStatus)
d.Set("is_dns_only", i.IsDNSOnly)
d.Set("is_transfer_locked", i.IsTransferLocked)
d.Set("is_whitelabel", i.IsWhitelabel)
d.Set("registation_date", i.RegistrationDate)
d.Set("renewal_date", i.RenewalDate)
return nil
}