Skip to content

Commit a66ca09

Browse files
authored
Merge pull request ovh#28 from goblain/25-dns-id
fixes ovh#25 by id removal, cleans up naming and struct repetition for domain zone record resource
2 parents c23c350 + f1ed4ef commit a66ca09

File tree

3 files changed

+57
-70
lines changed

3 files changed

+57
-70
lines changed

ovh/provider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func Provider() terraform.ResourceProvider {
5252
"ovh_publiccloud_private_network_subnet": resourcePublicCloudPrivateNetworkSubnet(),
5353
"ovh_publiccloud_user": resourcePublicCloudUser(),
5454
"ovh_vrack_publiccloud_attachment": resourceVRackPublicCloudAttachment(),
55-
"ovh_domain_zone_record": resourceOVHDomainZoneRecord(),
55+
"ovh_domain_zone_record": resourceOvhDomainZoneRecord(),
5656
},
5757

5858
ConfigureFunc: configureProvider,

ovh/resource_ovh_dns_record.go renamed to ovh/resource_ovh_domain_zone_record.go

+24-37
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,23 @@ import (
88
"github.com/hashicorp/terraform/helper/schema"
99
)
1010

11-
type NewRecord struct {
11+
type OvhDomainZoneRecord struct {
12+
Id int `json:"id,omitempty"`
13+
Zone string `json:"zone,omitempty"`
1214
Target string `json:"target"`
13-
Ttl int `json:"ttl"`
15+
Ttl int `json:"ttl,omitempty"`
1416
FieldType string `json:"fieldType"`
15-
SubDomain string `json:"subDomain"`
17+
SubDomain string `json:"subDomain,omitempty"`
1618
}
1719

18-
type Record struct {
19-
Id int `json:"id"`
20-
Zone string `json:"zone"`
21-
Target string `json:"target"`
22-
Ttl int `json:"ttl"`
23-
FieldType string `json:"fieldType"`
24-
SubDomain string `json:"subDomain"`
25-
}
26-
27-
func resourceOVHDomainZoneRecord() *schema.Resource {
20+
func resourceOvhDomainZoneRecord() *schema.Resource {
2821
return &schema.Resource{
29-
Create: resourceOVHRecordCreate,
30-
Read: resourceOVHRecordRead,
31-
Update: resourceOVHRecordUpdate,
32-
Delete: resourceOVHRecordDelete,
22+
Create: resourceOvhDomainZoneRecordCreate,
23+
Read: resourceOvhDomainZoneRecordRead,
24+
Update: resourceOvhDomainZoneRecordUpdate,
25+
Delete: resourceOvhDomainZoneRecordDelete,
3326

3427
Schema: map[string]*schema.Schema{
35-
"id": {
36-
Type: schema.TypeInt,
37-
Computed: true,
38-
},
3928
"zone": {
4029
Type: schema.TypeString,
4130
Required: true,
@@ -61,11 +50,11 @@ func resourceOVHDomainZoneRecord() *schema.Resource {
6150
}
6251
}
6352

64-
func resourceOVHRecordCreate(d *schema.ResourceData, meta interface{}) error {
53+
func resourceOvhDomainZoneRecordCreate(d *schema.ResourceData, meta interface{}) error {
6554
provider := meta.(*Config)
6655

6756
// Create the new record
68-
newRecord := &NewRecord{
57+
newRecord := &OvhDomainZoneRecord{
6958
FieldType: d.Get("fieldtype").(string),
7059
SubDomain: d.Get("subdomain").(string),
7160
Target: d.Get("target").(string),
@@ -74,7 +63,7 @@ func resourceOVHRecordCreate(d *schema.ResourceData, meta interface{}) error {
7463

7564
log.Printf("[DEBUG] OVH Record create configuration: %#v", newRecord)
7665

77-
resultRecord := Record{}
66+
resultRecord := OvhDomainZoneRecord{}
7867

7968
err := provider.OVHClient.Post(
8069
fmt.Sprintf("/domain/zone/%s/record", d.Get("zone").(string)),
@@ -86,20 +75,19 @@ func resourceOVHRecordCreate(d *schema.ResourceData, meta interface{}) error {
8675
return fmt.Errorf("Failed to create OVH Record: %s", err)
8776
}
8877

89-
d.Set("id", resultRecord.Id)
9078
d.SetId(strconv.Itoa(resultRecord.Id))
9179

9280
log.Printf("[INFO] OVH Record ID: %s", d.Id())
9381

94-
OVHZoneRefresh(d, meta)
82+
OvhDomainZoneRefresh(d, meta)
9583

96-
return resourceOVHRecordRead(d, meta)
84+
return resourceOvhDomainZoneRecordRead(d, meta)
9785
}
9886

99-
func resourceOVHRecordRead(d *schema.ResourceData, meta interface{}) error {
87+
func resourceOvhDomainZoneRecordRead(d *schema.ResourceData, meta interface{}) error {
10088
provider := meta.(*Config)
10189

102-
record := Record{}
90+
record := OvhDomainZoneRecord{}
10391
err := provider.OVHClient.Get(
10492
fmt.Sprintf("/domain/zone/%s/record/%s", d.Get("zone").(string), d.Id()),
10593
&record,
@@ -110,7 +98,6 @@ func resourceOVHRecordRead(d *schema.ResourceData, meta interface{}) error {
11098
return nil
11199
}
112100

113-
d.Set("id", record.Id)
114101
d.Set("zone", record.Zone)
115102
d.Set("fieldtype", record.FieldType)
116103
d.Set("subdomain", record.SubDomain)
@@ -120,10 +107,10 @@ func resourceOVHRecordRead(d *schema.ResourceData, meta interface{}) error {
120107
return nil
121108
}
122109

123-
func resourceOVHRecordUpdate(d *schema.ResourceData, meta interface{}) error {
110+
func resourceOvhDomainZoneRecordUpdate(d *schema.ResourceData, meta interface{}) error {
124111
provider := meta.(*Config)
125112

126-
record := NewRecord{}
113+
record := OvhDomainZoneRecord{}
127114

128115
if attr, ok := d.GetOk("subdomain"); ok {
129116
record.SubDomain = attr.(string)
@@ -149,12 +136,12 @@ func resourceOVHRecordUpdate(d *schema.ResourceData, meta interface{}) error {
149136
return fmt.Errorf("Failed to update OVH Record: %s", err)
150137
}
151138

152-
OVHZoneRefresh(d, meta)
139+
OvhDomainZoneRefresh(d, meta)
153140

154-
return resourceOVHRecordRead(d, meta)
141+
return resourceOvhDomainZoneRecordRead(d, meta)
155142
}
156143

157-
func resourceOVHRecordDelete(d *schema.ResourceData, meta interface{}) error {
144+
func resourceOvhDomainZoneRecordDelete(d *schema.ResourceData, meta interface{}) error {
158145
provider := meta.(*Config)
159146

160147
log.Printf("[INFO] Deleting OVH Record: %s.%s, %s", d.Get("zone").(string), d.Get("subdomain").(string), d.Id())
@@ -168,12 +155,12 @@ func resourceOVHRecordDelete(d *schema.ResourceData, meta interface{}) error {
168155
return fmt.Errorf("Error deleting OVH Record: %s", err)
169156
}
170157

171-
OVHZoneRefresh(d, meta)
158+
OvhDomainZoneRefresh(d, meta)
172159

173160
return nil
174161
}
175162

176-
func OVHZoneRefresh(d *schema.ResourceData, meta interface{}) error {
163+
func OvhDomainZoneRefresh(d *schema.ResourceData, meta interface{}) error {
177164
provider := meta.(*Config)
178165

179166
log.Printf("[INFO] Refresh OVH Zone: %s", d.Get("zone").(string))

ovh/resource_ovh_dns_record_test.go renamed to ovh/resource_ovh_domain_zone_record_test.go

+32-32
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ import (
1010
"github.com/hashicorp/terraform/terraform"
1111
)
1212

13-
func TestAccOVHRecord_Basic(t *testing.T) {
14-
var record Record
13+
func TestAccOvhDomainZoneRecord_Basic(t *testing.T) {
14+
var record OvhDomainZoneRecord
1515
zone := os.Getenv("OVH_ZONE")
1616

1717
resource.Test(t, resource.TestCase{
1818
PreCheck: func() { testAccPreCheck(t) },
1919
Providers: testAccProviders,
20-
CheckDestroy: testAccCheckOVHRecordDestroy,
20+
CheckDestroy: testAccCheckOvhDomainZoneRecordDestroy,
2121
Steps: []resource.TestStep{
2222
resource.TestStep{
23-
Config: fmt.Sprintf(testAccCheckOVHRecordConfig_basic, zone),
23+
Config: fmt.Sprintf(testAccCheckOvhDomainZoneRecordConfig_basic, zone),
2424
Check: resource.ComposeTestCheckFunc(
25-
testAccCheckOVHRecordExists("ovh_domain_zone_record.foobar", &record),
26-
testAccCheckOVHRecordAttributes(&record),
25+
testAccCheckOvhDomainZoneRecordExists("ovh_domain_zone_record.foobar", &record),
26+
testAccCheckOvhDomainZoneRecordAttributes(&record),
2727
resource.TestCheckResourceAttr(
2828
"ovh_domain_zone_record.foobar", "subdomain", "terraform"),
2929
resource.TestCheckResourceAttr(
@@ -38,20 +38,20 @@ func TestAccOVHRecord_Basic(t *testing.T) {
3838
})
3939
}
4040

41-
func TestAccOVHRecord_Updated(t *testing.T) {
42-
record := Record{}
41+
func TestAccOvhDomainZoneRecord_Updated(t *testing.T) {
42+
record := OvhDomainZoneRecord{}
4343
zone := os.Getenv("OVH_ZONE")
4444

4545
resource.Test(t, resource.TestCase{
4646
PreCheck: func() { testAccPreCheck(t) },
4747
Providers: testAccProviders,
48-
CheckDestroy: testAccCheckOVHRecordDestroy,
48+
CheckDestroy: testAccCheckOvhDomainZoneRecordDestroy,
4949
Steps: []resource.TestStep{
5050
resource.TestStep{
51-
Config: fmt.Sprintf(testAccCheckOVHRecordConfig_basic, zone),
51+
Config: fmt.Sprintf(testAccCheckOvhDomainZoneRecordConfig_basic, zone),
5252
Check: resource.ComposeTestCheckFunc(
53-
testAccCheckOVHRecordExists("ovh_domain_zone_record.foobar", &record),
54-
testAccCheckOVHRecordAttributes(&record),
53+
testAccCheckOvhDomainZoneRecordExists("ovh_domain_zone_record.foobar", &record),
54+
testAccCheckOvhDomainZoneRecordAttributes(&record),
5555
resource.TestCheckResourceAttr(
5656
"ovh_domain_zone_record.foobar", "subdomain", "terraform"),
5757
resource.TestCheckResourceAttr(
@@ -63,10 +63,10 @@ func TestAccOVHRecord_Updated(t *testing.T) {
6363
),
6464
},
6565
resource.TestStep{
66-
Config: fmt.Sprintf(testAccCheckOVHRecordConfig_new_value_1, zone),
66+
Config: fmt.Sprintf(testAccCheckOvhDomainZoneRecordConfig_new_value_1, zone),
6767
Check: resource.ComposeTestCheckFunc(
68-
testAccCheckOVHRecordExists("ovh_domain_zone_record.foobar", &record),
69-
testAccCheckOVHRecordAttributesUpdated_1(&record),
68+
testAccCheckOvhDomainZoneRecordExists("ovh_domain_zone_record.foobar", &record),
69+
testAccCheckOvhDomainZoneRecordAttributesUpdated_1(&record),
7070
resource.TestCheckResourceAttr(
7171
"ovh_domain_zone_record.foobar", "subdomain", "terraform"),
7272
resource.TestCheckResourceAttr(
@@ -78,10 +78,10 @@ func TestAccOVHRecord_Updated(t *testing.T) {
7878
),
7979
},
8080
resource.TestStep{
81-
Config: fmt.Sprintf(testAccCheckOVHRecordConfig_new_value_2, zone),
81+
Config: fmt.Sprintf(testAccCheckOvhDomainZoneRecordConfig_new_value_2, zone),
8282
Check: resource.ComposeTestCheckFunc(
83-
testAccCheckOVHRecordExists("ovh_domain_zone_record.foobar", &record),
84-
testAccCheckOVHRecordAttributesUpdated_2(&record),
83+
testAccCheckOvhDomainZoneRecordExists("ovh_domain_zone_record.foobar", &record),
84+
testAccCheckOvhDomainZoneRecordAttributesUpdated_2(&record),
8585
resource.TestCheckResourceAttr(
8686
"ovh_domain_zone_record.foobar", "subdomain", "terraform2"),
8787
resource.TestCheckResourceAttr(
@@ -93,10 +93,10 @@ func TestAccOVHRecord_Updated(t *testing.T) {
9393
),
9494
},
9595
resource.TestStep{
96-
Config: fmt.Sprintf(testAccCheckOVHRecordConfig_new_value_3, zone),
96+
Config: fmt.Sprintf(testAccCheckOvhDomainZoneRecordConfig_new_value_3, zone),
9797
Check: resource.ComposeTestCheckFunc(
98-
testAccCheckOVHRecordExists("ovh_domain_zone_record.foobar", &record),
99-
testAccCheckOVHRecordAttributesUpdated_3(&record),
98+
testAccCheckOvhDomainZoneRecordExists("ovh_domain_zone_record.foobar", &record),
99+
testAccCheckOvhDomainZoneRecordAttributesUpdated_3(&record),
100100
resource.TestCheckResourceAttr(
101101
"ovh_domain_zone_record.foobar", "subdomain", "terraform3"),
102102
resource.TestCheckResourceAttr(
@@ -111,7 +111,7 @@ func TestAccOVHRecord_Updated(t *testing.T) {
111111
})
112112
}
113113

114-
func testAccCheckOVHRecordDestroy(s *terraform.State) error {
114+
func testAccCheckOvhDomainZoneRecordDestroy(s *terraform.State) error {
115115
provider := testAccProvider.Meta().(*Config)
116116
zone := os.Getenv("OVH_ZONE")
117117

@@ -120,7 +120,7 @@ func testAccCheckOVHRecordDestroy(s *terraform.State) error {
120120
continue
121121
}
122122

123-
resultRecord := Record{}
123+
resultRecord := OvhDomainZoneRecord{}
124124
err := provider.OVHClient.Get(
125125
fmt.Sprintf("/domain/zone/%s/record/%s", zone, rs.Primary.ID),
126126
&resultRecord,
@@ -134,7 +134,7 @@ func testAccCheckOVHRecordDestroy(s *terraform.State) error {
134134
return nil
135135
}
136136

137-
func testAccCheckOVHRecordExists(n string, record *Record) resource.TestCheckFunc {
137+
func testAccCheckOvhDomainZoneRecordExists(n string, record *OvhDomainZoneRecord) resource.TestCheckFunc {
138138
zone := os.Getenv("OVH_ZONE")
139139
return func(s *terraform.State) error {
140140
rs, ok := s.RootModule().Resources[n]
@@ -166,7 +166,7 @@ func testAccCheckOVHRecordExists(n string, record *Record) resource.TestCheckFun
166166
}
167167
}
168168

169-
func testAccCheckOVHRecordAttributes(record *Record) resource.TestCheckFunc {
169+
func testAccCheckOvhDomainZoneRecordAttributes(record *OvhDomainZoneRecord) resource.TestCheckFunc {
170170
return func(s *terraform.State) error {
171171

172172
if record.Target != "192.168.0.10" {
@@ -177,7 +177,7 @@ func testAccCheckOVHRecordAttributes(record *Record) resource.TestCheckFunc {
177177
}
178178
}
179179

180-
func testAccCheckOVHRecordAttributesUpdated_1(record *Record) resource.TestCheckFunc {
180+
func testAccCheckOvhDomainZoneRecordAttributesUpdated_1(record *OvhDomainZoneRecord) resource.TestCheckFunc {
181181
return func(s *terraform.State) error {
182182

183183
if record.Target != "192.168.0.11" {
@@ -188,7 +188,7 @@ func testAccCheckOVHRecordAttributesUpdated_1(record *Record) resource.TestCheck
188188
}
189189
}
190190

191-
func testAccCheckOVHRecordAttributesUpdated_2(record *Record) resource.TestCheckFunc {
191+
func testAccCheckOvhDomainZoneRecordAttributesUpdated_2(record *OvhDomainZoneRecord) resource.TestCheckFunc {
192192
return func(s *terraform.State) error {
193193

194194
if record.Target != "192.168.0.11" {
@@ -203,7 +203,7 @@ func testAccCheckOVHRecordAttributesUpdated_2(record *Record) resource.TestCheck
203203
}
204204
}
205205

206-
func testAccCheckOVHRecordAttributesUpdated_3(record *Record) resource.TestCheckFunc {
206+
func testAccCheckOvhDomainZoneRecordAttributesUpdated_3(record *OvhDomainZoneRecord) resource.TestCheckFunc {
207207
return func(s *terraform.State) error {
208208

209209
if record.Target != "192.168.0.13" {
@@ -221,7 +221,7 @@ func testAccCheckOVHRecordAttributesUpdated_3(record *Record) resource.TestCheck
221221
}
222222
}
223223

224-
const testAccCheckOVHRecordConfig_basic = `
224+
const testAccCheckOvhDomainZoneRecordConfig_basic = `
225225
resource "ovh_domain_zone_record" "foobar" {
226226
zone = "%s"
227227
subdomain = "terraform"
@@ -230,7 +230,7 @@ resource "ovh_domain_zone_record" "foobar" {
230230
ttl = 3600
231231
}`
232232

233-
const testAccCheckOVHRecordConfig_new_value_1 = `
233+
const testAccCheckOvhDomainZoneRecordConfig_new_value_1 = `
234234
resource "ovh_domain_zone_record" "foobar" {
235235
zone = "%s"
236236
subdomain = "terraform"
@@ -239,7 +239,7 @@ resource "ovh_domain_zone_record" "foobar" {
239239
ttl = 3600
240240
}
241241
`
242-
const testAccCheckOVHRecordConfig_new_value_2 = `
242+
const testAccCheckOvhDomainZoneRecordConfig_new_value_2 = `
243243
resource "ovh_domain_zone_record" "foobar" {
244244
zone = "%s"
245245
subdomain = "terraform2"
@@ -248,7 +248,7 @@ resource "ovh_domain_zone_record" "foobar" {
248248
ttl = 3600
249249
}
250250
`
251-
const testAccCheckOVHRecordConfig_new_value_3 = `
251+
const testAccCheckOvhDomainZoneRecordConfig_new_value_3 = `
252252
resource "ovh_domain_zone_record" "foobar" {
253253
zone = "%s"
254254
subdomain = "terraform3"

0 commit comments

Comments
 (0)