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

Commit

Permalink
Fix dns zone (#44)
Browse files Browse the repository at this point in the history
* support last version of terraform cli for run tests equinix/terraform-provider-metal#155

* add check of dns resource dependency
  • Loading branch information
shubinmi authored Aug 31, 2021
1 parent 9e0314a commit 326ca35
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 60 deletions.
19 changes: 16 additions & 3 deletions gcore/resource_gcore_dns_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,29 @@ func resourceDNSZone() *schema.Resource {
Description: "A name of DNS Zone resource.",
},
},
CreateContext: resourceDNSZoneCreate,
ReadContext: resourceDNSZoneRead,
DeleteContext: resourceDNSZoneDelete,
CreateContext: checkDNSDependency(resourceDNSZoneCreate),
ReadContext: checkDNSDependency(resourceDNSZoneRead),
DeleteContext: checkDNSDependency(resourceDNSZoneDelete),
Description: "Represent DNS zone resource. https://dns.gcorelabs.com/zones",
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
}
}

func checkDNSDependency(next func(context.Context, *schema.ResourceData,
interface{}) diag.Diagnostics) func(context.Context, *schema.ResourceData, interface{}) diag.Diagnostics {

return func(ctx context.Context, data *schema.ResourceData, i interface{}) diag.Diagnostics {
config := i.(*Config)
client := config.DNSClient
if client == nil {
return diag.Errorf("dns api client is null. make sure that you defined gcore_dns_api var in gcore provider section.")
}
return next(ctx, data, i)
}
}

func resourceDNSZoneCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
name := strings.TrimSpace(d.Get(DNSZoneSchemaName).(string))
log.Println("[DEBUG] Start DNS Zone Resource creating")
Expand Down
8 changes: 4 additions & 4 deletions gcore/resource_gcore_dns_zone_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ func resourceDNSZoneRecord() *schema.Resource {
Description: "An array of contents with meta of DNS Zone Record resource.",
},
},
CreateContext: resourceDNSZoneRecordCreate,
UpdateContext: resourceDNSZoneRecordUpdate,
ReadContext: resourceDNSZoneRecordRead,
DeleteContext: resourceDNSZoneRecordDelete,
CreateContext: checkDNSDependency(resourceDNSZoneRecordCreate),
UpdateContext: checkDNSDependency(resourceDNSZoneRecordUpdate),
ReadContext: checkDNSDependency(resourceDNSZoneRecordRead),
DeleteContext: checkDNSDependency(resourceDNSZoneRecordDelete),
Description: "Represent DNS Zone Record resource. https://dns.gcorelabs.com/zones",
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
Expand Down
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ require (
github.com/G-Core/gcorelabs-storage-sdk-go v0.0.9
github.com/G-Core/gcorelabscdn-go v0.0.0-20210503173228-b4ac8b2402ff
github.com/G-Core/gcorelabscloud-go v0.4.15
github.com/google/uuid v1.1.2 // indirect
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.3
github.com/imdario/mergo v0.3.11 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.7.0
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mitchellh/mapstructure v1.4.1
github.com/zclconf/go-cty v1.7.1 // indirect
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a // indirect
)
Loading

0 comments on commit 326ca35

Please sign in to comment.