Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 0480230

Browse files
committed
add docs for dns zone & record import
1 parent b10d03f commit 0480230

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

docs/resources/gcore_dns_zone.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ resource "gcore_dns_zone" "example_zone" {
3838

3939
- **id** (String) The ID of this resource.
4040

41+
## Import
4142

43+
Import is supported using the following syntax:
44+
45+
```shell
46+
# import using zone name format
47+
terraform import gcore_dns_zone.example_zone example_zone.com
48+
```

docs/resources/gcore_dns_zone_record.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,11 @@ Optional:
136136
- **limit** (Number) A DNS Zone Record filter option that describe how many records will be percolated.
137137
- **strict** (Boolean) A DNS Zone Record filter option that describe possibility to return answers if no records were percolated through filter.
138138

139+
## Import
139140

141+
Import is supported using the following syntax:
142+
143+
```shell
144+
# import using zone:domain:type format
145+
terraform import gcore_dns_zone_record.example_rrset0 example.com:domain.example.com:A
146+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# import using zone name format
2+
terraform import gcore_dns_zone.example_zone example_zone.com
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# import using zone:domain:type format
2+
terraform import gcore_dns_zone_record.example_rrset0 example.com:domain.example.com:A

gcore/resource_gcore_dns_zone_record.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,18 @@ func resourceDNSZoneRecord() *schema.Resource {
238238
DeleteContext: checkDNSDependency(resourceDNSZoneRecordDelete),
239239
Description: "Represent DNS Zone Record resource. https://dns.gcorelabs.com/zones",
240240
Importer: &schema.ResourceImporter{
241-
StateContext: schema.ImportStatePassthroughContext,
241+
StateContext: func(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
242+
parts := strings.Split(d.Id(), ":")
243+
if len(parts) != 3 {
244+
return nil, fmt.Errorf("format must be as zone:domain:type")
245+
}
246+
_ = d.Set(DNSZoneRecordSchemaZone, parts[0])
247+
d.SetId(parts[0])
248+
_ = d.Set(DNSZoneRecordSchemaDomain, parts[1])
249+
_ = d.Set(DNSZoneRecordSchemaType, parts[2])
250+
251+
return []*schema.ResourceData{d}, nil
252+
},
242253
},
243254
}
244255
}

0 commit comments

Comments
 (0)