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

Commit

Permalink
fmt: fix golint warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Richter <[email protected]>
  • Loading branch information
danielr1996 committed Apr 26, 2021
1 parent 5ef58cd commit a5043ca
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# terraform-provider-hdns
[![Go Reference](https://pkg.go.dev/badge/github.com/danielr1996/terraform-provider-hdns.svg)](https://pkg.go.dev/github.com/danielr1996/terraform-provider-hdns)
[![Go Report Card](https://goreportcard.com/badge/github.com/danielr1996/hdns-go)](https://goreportcard.com/report/github.com/danielr1996/hdns-go)
![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/danielr1996/hdns-go?style=flat)
## Usage

Add the provider configuration to your `terraform.tf`
```hcl
Expand Down
5 changes: 3 additions & 2 deletions terraform/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// Provider defines the terraform provider
func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
Expand All @@ -20,7 +21,7 @@ func Provider() *schema.Provider {
},
},
ConfigureContextFunc: providerConfigure,
ResourcesMap: map[string]*schema.Resource{
ResourcesMap: map[string]*schema.Resource{
"hdns_record": record.Resource(),
},
DataSourcesMap: map[string]*schema.Resource{
Expand All @@ -33,7 +34,7 @@ func Provider() *schema.Provider {
func providerConfigure(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
token := d.Get("token").(string)
var diags diag.Diagnostics
if token == ""{
if token == "" {
return nil, diag.FromErr(errors.New("token must not be empty"))
}
return client.New().WithToken(token), diags
Expand Down
3 changes: 2 additions & 1 deletion terraform/record/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// DataSource defines the terraform datasource for a record
func DataSource() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceRecordRead,
Expand Down Expand Up @@ -55,7 +56,7 @@ func dataSourceRecordRead(_ context.Context, d *schema.ResourceData, m interface
c := m.(*client.Client)

id, ok := d.GetOk("id")
if !ok{
if !ok {
return diag.Errorf("Please provide a id argument")
}
record, err := c.Record.GetById(id.(string))
Expand Down
28 changes: 14 additions & 14 deletions terraform/record/resource.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package record


import (
"context"
"github.com/danielr1996/hdns-go/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// Resource defines the terraform resource for a record
func Resource() *schema.Resource {
return &schema.Resource{
CreateContext: Create,
ReadContext: Read,
UpdateContext: Update,
DeleteContext: Delete,
CreateContext: create,
ReadContext: read,
UpdateContext: update,
DeleteContext: delete,
Schema: map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Expand All @@ -38,27 +38,27 @@ func Resource() *schema.Resource {
}
}

func Create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func create(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
var diags diag.Diagnostics
c := m.(*client.Client)
recordType := d.Get("type").(string)
value := d.Get("value").(string)
name := d.Get("name").(string)
zoneId := d.Get("zone_id").(string)
record, err := c.Record.Create(name, recordType,value,zoneId)
record, err := c.Record.Create(name, recordType, value, zoneId)
if err != nil {
return diag.FromErr(err)
}
d.SetId(record.Id)
Read(ctx, d, m)
read(ctx, d, m)
return diags
}

func Read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
var diags diag.Diagnostics
c := m.(*client.Client)
record, err := c.Record.GetById(d.Id())
if err != nil{
if err != nil {
return diag.FromErr(err)
}
if err := d.Set("type", record.Type); err != nil {
Expand All @@ -76,9 +76,9 @@ func Read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagn
return diags
}

func Update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
c := m.(*client.Client)
if d.HasChanges("type","name","value","zone_id"){
if d.HasChanges("type", "name", "value", "zone_id") {
recordType := d.Get("type").(string)
value := d.Get("value").(string)
name := d.Get("name").(string)
Expand All @@ -89,10 +89,10 @@ func Update(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Dia
}

}
return Read(ctx, d, m)
return read(ctx, d, m)
}

func Delete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func delete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
var diags diag.Diagnostics
c := m.(*client.Client)
err := c.Record.Delete(d.Id())
Expand Down
5 changes: 3 additions & 2 deletions terraform/zone/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// DataSource defines the terraform datasource for a zone
func DataSource() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceZoneRead,
ReadContext: read,
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Expand All @@ -30,7 +31,7 @@ func DataSource() *schema.Resource {
}
}

func dataSourceZoneRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
func read(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
var diags diag.Diagnostics
c := m.(*client.Client)
name, ok := d.GetOk("name")
Expand Down

0 comments on commit a5043ca

Please sign in to comment.