This repository has been archived by the owner on Nov 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
dns_recordset_v2.go
91 lines (71 loc) · 2.35 KB
/
dns_recordset_v2.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
package openstack
import (
"fmt"
"log"
"regexp"
"strings"
"github.com/hashicorp/terraform/helper/resource"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/dns/v2/recordsets"
)
// RecordSetCreateOpts represents the attributes used when creating a new DNS record set.
type RecordSetCreateOpts struct {
recordsets.CreateOpts
ValueSpecs map[string]string `json:"value_specs,omitempty"`
}
// ToRecordSetCreateMap casts a CreateOpts struct to a map.
// It overrides recordsets.ToRecordSetCreateMap to add the ValueSpecs field.
func (opts RecordSetCreateOpts) ToRecordSetCreateMap() (map[string]interface{}, error) {
b, err := BuildRequest(opts, "")
if err != nil {
return nil, err
}
if m, ok := b[""].(map[string]interface{}); ok {
return m, nil
}
return nil, fmt.Errorf("Expected map but got %T", b[""])
}
func dnsRecordSetV2RefreshFunc(
dnsClient *gophercloud.ServiceClient, zoneID, recordsetId string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
recordset, err := recordsets.Get(dnsClient, zoneID, recordsetId).Extract()
if err != nil {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return recordset, "DELETED", nil
}
return nil, "", err
}
log.Printf("[DEBUG] openstack_dns_recordset_v2 %s current status: %s", recordset.ID, recordset.Status)
return recordset, recordset.Status, nil
}
}
func dnsRecordSetV2ParseID(id string) (string, string, error) {
idParts := strings.Split(id, "/")
if len(idParts) != 2 {
return "", "", fmt.Errorf("Unable to determine openstack_dns_recordset_v2 ID from raw ID: %s", id)
}
zoneID := idParts[0]
recordsetID := idParts[1]
return zoneID, recordsetID, nil
}
func expandDNSRecordSetV2Records(v []interface{}) []string {
records := make([]string, len(v))
// Strip out any [ ] characters in the address.
// This is to format IPv6 records in a way that DNSaaS / Designate wants.
re := regexp.MustCompile("[][]")
for i, rawRecord := range v {
record := rawRecord.(string)
record = re.ReplaceAllString(record, "")
records[i] = record
}
return records
}
// dnsRecordSetV2RecordsStateFunc will strip brackets from IPv6 addresses.
func dnsRecordSetV2RecordsStateFunc(v interface{}) string {
if addr, ok := v.(string); ok {
re := regexp.MustCompile("[][]")
addr = re.ReplaceAllString(addr, "")
return addr
}
return ""
}